Index._engine creates cyclic reference · Issue #27585 · pandas-dev/pandas (original) (raw)

Code Sample, a copy-pastable example if possible

import gc import pandas as pd

gc.disable()

idx = pd.Int64Index(data=[0])

trigger a call to idx._engine using public API, but a unit test might also be

able to use the private API here

idx.is_monotonic_increasing del idx

remaining_indices = [o for o in gc.get_objects() if isinstance(o, pd.Int64Index)] assert remaining_indices == []

Problem description

The (indirect) call to idx._engine creates a cyclic reference, therefore indices are not removed without calling the GC:

import objgraph objgraph.show_backrefs( remaining_indices, filename='obj.png', shortnames=False, max_depth=10, )

obj

On certain payloads (e.g. on dask.distributed clusters), this might increase memory consumptions significantly.

Expected Output

Index is cleared on del idx call.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.6.6.final.0
python-bits : 64
OS : Linux
OS-release : 4.9.125-linuxkit
machine : x86_64
processor :
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 0.25.0
numpy : 1.16.4
pytz : 2019.1
dateutil : 2.8.0
pip : 10.0.1
setuptools : 39.1.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None