MAINT: Hit more dataframe indexers.

This commit is contained in:
Scott Sanderson
2016-11-22 17:11:04 -05:00
parent f244a20e65
commit aa3f2220d9
+10 -4
View File
@@ -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: