Skip to content

BUG: pickle incompatibility with pandas-2.0 from pandas-1.5 with numeric index #53300

Closed
@mwtoews

Description

@mwtoews

Pandas version checks

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

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

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

Create a simple series with a numeric index with pandas-1.5.3:

import pandas as pd
import pickle

s = pd.Series([3.3, 4.4], index=[2, 4])
with open('s-1.5.3.pkl', 'wb') as f:
    pickle.dump(s, f)

Or get it here: s-1.5.3.pkl.gz

then try to unpickle it with pandas-2.0:

import pickle

with open('s-1.5.3.pkl', 'rb') as f:
    s2 = pickle.load(f)

raises:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
ModuleNotFoundError: No module named 'pandas.core.indexes.numeric'

Issue Description

Some pickle objects created with pandas<2 cannot be loaded with pandas-2.0, since there is no longer a pandas.core.indexes.numeric module (removed with #51139).

See also Stack Overflow Q/A for this issue (not mine).

Expected Behavior

There is a pandas.compat.pickle_compat module that could potentially be used to help this scenario and read the pickle? Curiously enough, it references pandas.core.indexes.numeric which was removed for 2.0.

Installed Versions

>>> pd.show_versions()
/tmp/py310/lib/python3.10/site-packages/_distutils_hack/__init__.py:33: UserWarning: Setuptools is replacing distutils.
  warnings.warn("Setuptools is replacing distutils.")

INSTALLED VERSIONS
------------------
commit           : 37ea63d540fd27274cad6585082c91b1283f963d
python           : 3.10.11.final.0
python-bits      : 64
OS               : Linux
OS-release       : 5.4.0-148-generic
Version          : #165-Ubuntu SMP Tue Apr 18 08:53:12 UTC 2023
machine          : x86_64
processor        : x86_64
byteorder        : little
LC_ALL           : None
LANG             : en_AU.UTF-8
LOCALE           : en_AU.UTF-8

pandas           : 2.0.1
numpy            : 1.24.3
pytz             : 2023.3
dateutil         : 2.8.2
setuptools       : 65.5.0
pip              : 23.1.2
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          : 8.13.2
pandas_datareader: None
bs4              : None
bottleneck       : None
brotli           : None
fastparquet      : None
fsspec           : None
gcsfs            : None
matplotlib       : None
numba            : None
numexpr          : None
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : None
pyreadstat       : None
pyxlsb           : None
s3fs             : None
scipy            : None
snappy           : None
sqlalchemy       : None
tables           : None
tabulate         : None
xarray           : None
xlrd             : None
zstandard        : None
tzdata           : 2023.3
qtpy             : None
pyqt5            : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIO Pickleread_pickle, to_pickleNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions