Skip to content

Pickled TimedeltaIndex from 0.19.2 cannot be unpickled in 0.20+ using pd.read_pickle #19939

Closed
@Liam3851

Description

@Liam3851

Code Sample, a copy-pastable example if possible

# On pandas 0.19.2, python 2.7
import pandas as pd
import cPickle as pickle

td30 = pd.timedelta_range('00:30:00', '01:30:00', freq='30T')
td30.to_series().to_pickle('C:/temp/td30.pkl')        

pd.read_pickle('c:/temp/td30.pkl')

Out[7]: 
00:30:00   00:30:00
01:00:00   01:00:00
01:30:00   01:30:00
Freq: 30T, dtype: timedelta64[ns]


# On latest master
In [1]: import pandas as pd

In [2]: pd.__version__
Out[2]: '0.23.0.dev0+394.gf4c9d96'

In [3]: pd.read_pickle('C:/temp/td30.pkl')
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
C:\projects\pandas-dk\pandas\io\pickle.py in try_read(path, encoding)
    101                 # We want to silencce any warnings about, e.g. moved modules.
--> 102                 return read_wrapper(lambda f: pkl.load(f))
    103         except Exception:

C:\projects\pandas-dk\pandas\io\pickle.py in read_wrapper(func)
     84         try:
---> 85             return func(f)
     86         finally:

C:\projects\pandas-dk\pandas\io\pickle.py in <lambda>(f)
    101                 # We want to silencce any warnings about, e.g. moved modules.
--> 102                 return read_wrapper(lambda f: pkl.load(f))
    103         except Exception:

ModuleNotFoundError: No module named 'pandas.indexes.base'

Problem description

Objects with TimedeltaIndexes created under pandas 0.19.2 cannot be unpickled using pandas.read_pickle on later versions of pandas. I have found the same behavior on python 2.7 and 3.6, with pandas 0.20.3 through latest master. On Python 3.6 it raises ModuleNotFoundError: No module named 'pandas.indexes.base'; under python 2.7, it raises ImportError saying "No module named tdi".

Apologies if this is a dupe; while I have seen other reports of problems unpickling objects created in 0.19.2, it appears all could be fixed by using read_pickle, while here using read_pickle does not solve the problem.

Expected Output

Correct unpickling without error. Given the above example, should be the following under 0.23 master:

00:30:00 00:30:00
01:00:00 01:00:00
01:30:00 01:30:00
Freq: 30T, dtype: timedelta64[ns]

Output of pd.show_versions()

Creating the pickle:

INSTALLED VERSIONS

commit: None
python: 2.7.14.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 62 Stepping 4, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.19.2
nose: 1.3.7
pip: 9.0.1
setuptools: 38.4.0
Cython: 0.25.2
numpy: 1.11.3
scipy: 0.19.0
statsmodels: 0.8.0
xarray: 0.9.6
IPython: 5.3.0
sphinx: 1.6.3
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: 1.2.1
tables: 3.2.2
numexpr: 2.6.2
matplotlib: 2.0.2
openpyxl: 2.4.8
xlrd: 1.0.0
xlwt: 1.2.0
xlsxwriter: 0.9.6
lxml: 3.8.0
bs4: 4.6.0
html5lib: 0.999
httplib2: None
apiclient: None
sqlalchemy: 1.1.13
pymysql: None
psycopg2: None
jinja2: 2.9.6
boto: 2.48.0
pandas_datareader: 0.5.0

Reading the pickle (master):

INSTALLED VERSIONS

commit: f4c9d96
python: 3.6.4.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 62 Stepping 4, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.23.0.dev0+394.gf4c9d96
pytest: 3.3.2
pip: 9.0.1
setuptools: 38.4.0
Cython: 0.27.3
numpy: 1.14.0
scipy: 1.0.0
pyarrow: 0.8.0
xarray: 0.10.0
IPython: 6.2.1
sphinx: 1.6.6
patsy: 0.5.0
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.4
feather: 0.4.0
matplotlib: 2.1.2
openpyxl: 2.4.10
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.0.2
lxml: 4.1.1
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.2.1
pymysql: 0.7.11.None
psycopg2: None
jinja2: 2.10
s3fs: 0.1.2
fastparquet: 0.1.4
pandas_gbq: None
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Compatpandas objects compatability with Numpy or Python functionsIO DataIO issues that don't fit into a more specific label

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions