From aa3f2220d95c3c44ebee11a38727c2ca7b7bdf4f Mon Sep 17 00:00:00 2001 From: Scott Sanderson Date: Tue, 22 Nov 2016 17:11:04 -0500 Subject: [PATCH] MAINT: Hit more dataframe indexers. --- zipline/utils/pandas_utils.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/zipline/utils/pandas_utils.py b/zipline/utils/pandas_utils.py index 1b81897a..633960e1 100644 --- a/zipline/utils/pandas_utils.py +++ b/zipline/utils/pandas_utils.py @@ -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: