BUG: IntervalIndex cannot be round-tripped pickled (original) (raw)


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

import pandas as pd
import numpy as np import pickle as pkl

interval = pd.IntervalIndex.from_breaks(np.linspace(0, 100, 5+1), closed="left")

print("original:", interval) print("pickle", pkl.loads(pkl.dumps(interval)))

original: IntervalIndex([[0.0, 20.0), [20.0, 40.0), [40.0, 60.0), [60.0, 80.0), [80.0, 100.0)],
              closed='left',
              dtype='interval[float64]')
pickle IntervalIndex([(0.0, 20.0], (20.0, 40.0], (40.0, 60.0], (60.0, 80.0], (80.0, 100.0]],
              closed='right',
              dtype='interval[float64]')

Problem description

Having recently updated to v1.1.0 from v1.0.5, it seems IntervalIndex is no longer preserving the closure of the intervals as being left or right. When unpickling the IntervalIndex, the closure is reset to the default value of "right". This seems similar to the serialisation issues of #32037 and #35420, but those seem to be for older versions of the master branch.

Expected Output

original: [IntervalIndex([[0.0, 20.0), [20.0, 40.0), [40.0, 60.0), [60.0, 80.0), [80.0, 100.0)],
              closed='left',
              dtype='interval[float64]')]
pickle [IntervalIndex([[0.0, 20.0), [20.0, 40.0), [40.0, 60.0), [60.0, 80.0), [80.0, 100.0)],
              closed='left',
              dtype='interval[float64]')]

Output of pd.show_versions()

Details

python -c "import pandas as pd; pd.show_versions()"

INSTALLED VERSIONS

commit : d9fff27
python : 3.7.3.final.0
python-bits : 64
OS : Linux
OS-release : 3.10.0-1062.7.1.el7.x86_64
Version : #1 SMP Mon Dec 2 17:33:29 UTC 2019
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8

pandas : 1.1.0
numpy : 1.19.1
pytz : 2020.1
dateutil : 2.8.1
pip : 19.3.1
setuptools : 45.2.0
Cython : None
pytest : 4.3.0
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.1
IPython : 7.17.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.3.0
numexpr : 2.7.1
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : None
tables : 3.6.1
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : 0.48.0