Pandas: Reading Pickle File Crashes

Created on 8 Sep 2017  路  4Comments  路  Source: pandas-dev/pandas

Code Sample, a copy-pastable example if possible

# Your code here
import sys
import matplotlib.pyplot as plt
import pandas as pd
from zipline.api import order, record, symbol


def initialize(context):
    pass


def handle_data(context, data):
    order(symbol('AAPL'), 10)
    record(AAPL=data.current(symbol('AAPL'), 'price'))


perf = pd.read_pickle('buyapple_out.pickle') # read in perf DataFrame
perf.head()

Problem description

Error that I got:
Traceback (most recent call last):
File "/Users/tliu/anaconda3/lib/python3.5/site-packages/pandas/io/pickle.py", line 52, in try_read
return pkl.load(fh)
File "pandas/tslib.pyx", line 295, in pandas.tslib.Timestamp.__new__ (pandas/tslib.c:9203)
File "pandas/tslib.pyx", line 1343, in pandas.tslib.convert_to_tsobject (pandas/tslib.c:25854)
TypeError: Cannot convert input to Timestamp

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/tliu/anaconda3/lib/python3.5/site-packages/pandas/io/pickle.py", line 57, in try_read
return pc.load(fh, encoding=encoding, compat=False)
File "/Users/tliu/anaconda3/lib/python3.5/site-packages/pandas/compat/pickle_compat.py", line 117, in load
return up.load()
File "/Users/tliu/anaconda3/lib/python3.5/pickle.py", line 1043, in load
dispatchkey[0]
File "/Users/tliu/anaconda3/lib/python3.5/site-packages/pandas/compat/pickle_compat.py", line 17, in load_reduce
if type(args[0]) is type:
IndexError: tuple index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/tliu/anaconda3/lib/python3.5/site-packages/pandas/io/pickle.py", line 65, in read_pickle
return try_read(path)
File "/Users/tliu/anaconda3/lib/python3.5/site-packages/pandas/io/pickle.py", line 62, in try_read
return pc.load(fh, encoding=encoding, compat=True)
File "/Users/tliu/anaconda3/lib/python3.5/site-packages/pandas/compat/pickle_compat.py", line 117, in load
return up.load()
File "/Users/tliu/anaconda3/lib/python3.5/pickle.py", line 1043, in load
dispatchkey[0]
File "/Users/tliu/anaconda3/lib/python3.5/site-packages/pandas/compat/pickle_compat.py", line 17, in load_reduce
if type(args[0]) is type:
IndexError: tuple index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/tliu/anaconda3/lib/python3.5/site-packages/pandas/io/pickle.py", line 52, in try_read
return pkl.load(fh)
File "pandas/tslib.pyx", line 295, in pandas.tslib.Timestamp.__new__ (pandas/tslib.c:9203)
File "pandas/tslib.pyx", line 1343, in pandas.tslib.convert_to_tsobject (pandas/tslib.c:25854)
TypeError: Cannot convert input to Timestamp

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/tliu/anaconda3/lib/python3.5/site-packages/pandas/io/pickle.py", line 57, in try_read
return pc.load(fh, encoding=encoding, compat=False)
File "/Users/tliu/anaconda3/lib/python3.5/site-packages/pandas/compat/pickle_compat.py", line 117, in load
return up.load()
File "/Users/tliu/anaconda3/lib/python3.5/pickle.py", line 1043, in load
dispatchkey[0]
File "/Users/tliu/anaconda3/lib/python3.5/site-packages/pandas/compat/pickle_compat.py", line 17, in load_reduce
if type(args[0]) is type:
IndexError: tuple index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/tliu/Code/python3/buyapple.py", line 16, in
perf = pd.read_pickle('buyapple_out.pickle') # read in perf DataFrame
File "/Users/tliu/anaconda3/lib/python3.5/site-packages/pandas/io/pickle.py", line 68, in read_pickle
return try_read(path, encoding='latin1')
File "/Users/tliu/anaconda3/lib/python3.5/site-packages/pandas/io/pickle.py", line 62, in try_read
return pc.load(fh, encoding=encoding, compat=True)
File "/Users/tliu/anaconda3/lib/python3.5/site-packages/pandas/compat/pickle_compat.py", line 117, in load
return up.load()
File "/Users/tliu/anaconda3/lib/python3.5/pickle.py", line 1043, in load
dispatchkey[0]
File "/Users/tliu/anaconda3/lib/python3.5/site-packages/pandas/compat/pickle_compat.py", line 17, in load_reduce
if type(args[0]) is type:
IndexError: tuple index out of range

Expected Output

Outputs the header of the pickle file

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.5.4.final.0
python-bits: 64
OS: Darwin
OS-release: 16.7.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.20.3
pytest: 3.2.1
pip: 9.0.1
setuptools: 36.4.0
Cython: 0.26
numpy: 1.13.1
scipy: 0.19.1
xarray: None
IPython: 6.1.0
sphinx: 1.6.3
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.2
feather: None
matplotlib: 2.0.2
openpyxl: 2.4.8
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 0.9.8
lxml: 3.8.0
bs4: 4.6.0
html5lib: 0.9999999
sqlalchemy: 1.1.13
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
pandas_gbq: None
pandas_datareader: 0.5.0

Thank you very much, and I would really appreciate if someone can look at this problem for me!

Sincerely,
Terence Liu

IO Data

Most helpful comment

I found this page with the same error using the same package 'zipline' example. It turned out I had an error installing one of the pandas pieces without using Anaconda as an Admin on Windows. Had to restart everything for it to register.

All 4 comments

@NumberChiffre : Thanks for reporting this! It appears that pandas doesn't like your pickle file. Did this use to work for you?

you would have to show how you are pickling and what, which what versions / platform.

closing as not reproducible.

I found this page with the same error using the same package 'zipline' example. It turned out I had an error installing one of the pandas pieces without using Anaconda as an Admin on Windows. Had to restart everything for it to register.

Was this page helpful?
0 / 5 - 0 ratings