Skip to content

Commit

Permalink
make things work with pandas 2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
greglandrum committed Mar 9, 2024
1 parent 84f8186 commit 3eb1ca2
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions rdkit/Chem/PandasPatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
orig_get_adjustment = getattr(get_adjustment_module, get_adjustment_name)
break
if orig_get_adjustment is not None:
break
break
if orig_get_adjustment is None:
log.warning("Failed to find the pandas get_adjustment() function to patch")
raise AttributeError
Expand Down Expand Up @@ -195,17 +195,16 @@ def patched_to_html(self, *args, **kwargs):


def patched_get_formatter(self, i, *args, **kwargs):
if (isinstance(self.formatters, dict) and isinstance(i, int)
and i not in self.columns and hasattr(self, "tr_col_num")
and i >= self.tr_col_num):
max_cols = 0
if hasattr(self, "max_cols_fitted"):
max_cols = self.max_cols_fitted
elif hasattr(self, "max_cols_adj"):
max_cols = self.max_cols_adj
n_trunc_cols = len(self.columns) - max_cols
if n_trunc_cols > 0:
i += n_trunc_cols
if (isinstance(self.formatters, dict) and isinstance(i, int) and i not in self.columns
and hasattr(self, "tr_col_num") and i >= self.tr_col_num):
max_cols = 0
if hasattr(self, "max_cols_fitted"):
max_cols = self.max_cols_fitted
elif hasattr(self, "max_cols_adj"):
max_cols = self.max_cols_adj
n_trunc_cols = len(self.columns) - max_cols
if n_trunc_cols > 0:
i += n_trunc_cols
return orig_get_formatter(self, i, *args, **kwargs)


Expand Down Expand Up @@ -260,9 +259,10 @@ def patchPandas():
setattr(to_html_class, "to_html", patched_to_html)
if getattr(html_formatter_class, "_write_cell") != patched_write_cell:
setattr(html_formatter_class, "_write_cell", patched_write_cell)
if getattr(pandas_formats.format, get_adjustment_name) != patched_get_adjustment:
setattr(pandas_formats.format, get_adjustment_name, patched_get_adjustment)
if (orig_get_formatter and getattr(dataframeformatter_class, "_get_formatter") != patched_get_formatter):
if getattr(get_adjustment_module, get_adjustment_name) != patched_get_adjustment:
setattr(get_adjustment_module, get_adjustment_name, patched_get_adjustment)
if (orig_get_formatter
and getattr(dataframeformatter_class, "_get_formatter") != patched_get_formatter):
setattr(dataframeformatter_class, "_get_formatter", patched_get_formatter)


Expand Down

0 comments on commit 3eb1ca2

Please sign in to comment.