mirror of
https://github.com/wassname/catalyst.git
synced 2026-10-30 13:10:53 +08:00
MAINT: Hit more dataframe indexers.
This commit is contained in:
1 parent
16e78bbccd
commit
9f28b7cede
1 file changed
+10
-4
@@ -168,19 +168,25 @@ def ignore_pandas_nan_categorical_warning():
|
||||
yield
|
||||
|
||||
|
||||
_INDEXER_NAMES = [
|
||||
'_' + name for (name, _) in pd.core.indexing.get_indexers_list()
|
||||
]
|
||||
|
||||
|
||||
def clear_dataframe_indexer_caches(df):
|
||||
"""
|
||||
Clear cached attributes from a pandas DataFrame.
|
||||
|
||||
By default pandas memoizes `iloc`, `loc` objects on DataFrames, resulting
|
||||
in refcycles that can lead to unexpectedly long-lived DataFrames. This
|
||||
function attempts to clear those cycles.
|
||||
By default pandas memoizes indexers (`iloc`, `loc`, `ix`, etc.) objects on
|
||||
DataFrames, resulting in refcycles that can lead to unexpectedly long-lived
|
||||
DataFrames. This function attempts to clear those cycles by deleting the
|
||||
cached indexers from the frame.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
df : pd.DataFrame
|
||||
"""
|
||||
for attr in ('_loc', '_iloc'):
|
||||
for attr in _INDEXER_NAMES:
|
||||
try:
|
||||
delattr(df, attr)
|
||||
except AttributeError:
|
||||
|
||||
Reference in new issue
Block a user