-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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
Uncompatibility of pandas.read_pickle with pytz #6871
Comments
I'll mark it as a bug, but why would you do this anyhow? surely you want an |
With datetime/pytz matplotlib "understands", that axis(es) is/are date/time, with numpy.datetime64 - doesn't. Please, run example below: import pandas, datetime, pytz
import matplotlib.pyplot as plt
dates = [datetime.datetime(2014,1,1,1,1, tzinfo=pytz.utc),
datetime.datetime(2014,2,2,2,2, tzinfo=pytz.utc),
datetime.datetime(2014,3,3,3,3, tzinfo=pytz.utc)]
s1 = pandas.Series(pandas.DatetimeIndex(dates))
plt.plot(s1, s1)
plt.show()
s2 = pandas.Series(dates)
plt.plot(s2, s2)
plt.show() |
is their a reason you are not using |
s1.plot() (from my example) gives an error:
|
what exactly are you trying to do? |
I'm running into a similar problem. If I generate a timeseries with UTC timezone in python 2.7.6 and pickle it like, import pandas as pd
import numpy as np
drange = pd.date_range('2014-07-01 00:00:00', '2014-07-01 12:00:00', freq='H')
ser = pd.Series(np.random.rand(len(drange)), index=drange).tz_localize('UTC')
ser.to_pickle('/tmp/test2to3_ser') and then try and read it in python 3.4.1 import pandas as pd
pd.read_pickle('/tmp/test2to3_ser') I get ---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-2-0b7937eff7fa> in <module>()
----> 1 pd.read_pickle('/tmp/test2to3_ser')
/home/tony/.virtualenvs/dev3/lib/python3.4/site-packages/pandas/io/pickle.py in read_pickle(path)
62 except:
63 if PY3:
---> 64 return try_read(path, encoding='latin1')
65 raise
/home/tony/.virtualenvs/dev3/lib/python3.4/site-packages/pandas/io/pickle.py in try_read(path, encoding)
56 except:
57 with open(path, 'rb') as fh:
---> 58 return pc.load(fh, encoding=encoding, compat=True)
59
60 try:
/home/tony/.virtualenvs/dev3/lib/python3.4/site-packages/pandas/compat/pickle_compat.py in load(fh, encoding, compat, is_verbose)
87 up.is_verbose = is_verbose
88
---> 89 return up.load()
90 except:
91 raise
/home/supas/forecasting_python/python3.4.1/lib/python3.4/pickle.py in load(self)
1034 raise EOFError
1035 assert isinstance(key, bytes_types)
-> 1036 dispatch[key[0]](self)
1037 except _Stop as stopinst:
1038 return stopinst.value
/home/supas/forecasting_python/python3.4.1/lib/python3.4/pickle.py in load_newobj(self)
1306 args = self.stack.pop()
1307 cls = self.stack.pop()
-> 1308 obj = cls.__new__(cls, *args)
1309 self.append(obj)
1310 dispatch[NEWOBJ[0]] = load_newobj
TypeError: Required argument 'shape' (pos 1) not found My system info for python2.7.6 is
and for 3.4.1
|
Same problem here |
try in 0.15.2 and master |
Edit: We decided to post this as a separate issue (#12163) since it's not identical to this issue (only a similar traceback). We have this problem when writing pickles with Pandas 0.14.1 and reading them with Pandas 0.17.1. The problem occurs if the pickles contain The problem can be reduced to this test case: my_tz.py:
write_pickle_test.py (run with Pandas 0.14.1):
read_pickle_test.py (run with Pandas 0.17.1):
Reading the pickle with
which is why
I see the following problems in pandas.compat.pickle_compat.load_reduce(): (1) It attemps to access
(2) The above code is dead code anyway, since Note that the (3) Also, at the very end of
is code that is never reached, since all previous code branches either return or raise. Also, this line is invalid, since |
@jreback : can't reproduce this anymore: ... # run the code above
>>> import pandas.util.testing as tm
>>> tm.assert_series_equal(s, s2)
>>> |
yeah it should be supported by |
So how to fix this? |
this was fixed quite a long time ago you would have to show a reproducible example |
I am using this zipline example, which creates a pickle file as follows:
which gives me an error: |
@saitam1 you would have to show a pure pandas example, otherwise you should report this to zipline. |
Test program below:
crashes at the last line with long stack trace. If replace "pytz.utc" by "datetime.timezone.utc", error disappears. Commented code fragment works properly in both cases.
Best regards,
Andrew
The text was updated successfully, but these errors were encountered: