mirror of
https://github.com/wassname/catalyst.git
synced 2026-06-29 22:49:25 +08:00
MAINT: Hit more dataframe indexers.
This commit is contained in:
@@ -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