Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: IntervalIndex cannot be round-tripped pickled #35658

Closed
2 of 3 tasks
benkrikler opened this issue Aug 10, 2020 · 2 comments · Fixed by #36118
Closed
2 of 3 tasks

BUG: IntervalIndex cannot be round-tripped pickled #35658

benkrikler opened this issue Aug 10, 2020 · 2 comments · Fixed by #36118
Labels
Interval Interval data type IO Pickle read_pickle, to_pickle Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@benkrikler
Copy link

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


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()

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

@benkrikler benkrikler added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 10, 2020
@jorisvandenbossche jorisvandenbossche added Interval Interval data type IO Pickle read_pickle, to_pickle Regression Functionality that used to work in a prior pandas version and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 11, 2020
@jorisvandenbossche jorisvandenbossche added this to the 1.1.1 milestone Aug 11, 2020
@jorisvandenbossche
Copy link
Member

@benkrikler Thanks for the report! I can confirm this is a regression from 1.0

@simonjayhawkins
Copy link
Member

I can confirm this is a regression from 1.0

regression in #32260 cc @jbrockmendel

1b8b428 is the first bad commit
commit 1b8b428
Author: jbrockmendel jbrockmendel@gmail.com
Date: Wed Feb 26 04:27:24 2020 -0800

CLN: remove dtype kwarg from _simple_new (#32260)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Interval Interval data type IO Pickle read_pickle, to_pickle Regression Functionality that used to work in a prior pandas version
Projects
None yet
3 participants