-
-
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
Dead code breaks unpickling of timezone objects #12163
Comments
ok, if you want to submit a patch that passes all current tests (and would have to add a tests for this to the pickle generation script as well), would take it. Very odd that you are sub-classing the tz object, what is the purpose? |
I get a similar issue when pickling a DataFrame with a tz-aware index in pandas 0.18 under python 2.7, and unpickling under pandas 0.18 in Python 3.5 (no tz subclassing involved): Under Python 2.7:
Under Python 3.5:
packages installed:
|
@jreback, IIRC the subclassing of tz was an attempt to reduce the failing test case to a minimum. It probably went something like this:
|
Looks to work on master. Could use a test.
|
There is a problem when writing pickles with Pandas 0.14.1 and reading them with Pandas 0.17.1. The problem occurs if the pickles contain
isodate.UTC
or other timezone objects.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
pickle.load()
would fail when trying to load theSeries
object:which is why
pd.read_pickle()
attempts to usepandas.compat.pickle_compat.load()
. But then we get this instead for theMyTz
object:I see the following problems in pandas.compat.pickle_compat.load_reduce():
(1) It attemps to access
args[0]
whileargs
can be empty.(2) The above code is dead code anyway, since
n
isn't referenced to anywhere else in the function. Removing those two lines fixes the unpickling problem completely.Note that the
MyTz
class in the test above does implement a proper__init__()
method as required in Python documentation for tzinfo: "Special requirement for pickling: A tzinfo subclass must have an__init__
method that can be called with no arguments, else it can be pickled but possibly not unpickled again. This is a technical requirement that may be relaxed in the future." Whileisodate.UTC
violates this requirement, that doesn't seem to be the cause of this problem.(3) Also, at the very end of
load_reduce()
:is code that is never reached, since all previous code branches either return or raise. Also, this line is invalid, since
value
isn't initialized anywhere in the function.I originally sent this as a comment to issue #6871, but since it's not exactly the same thing (only a similar traceback), I think it deserves a separate issue.
The text was updated successfully, but these errors were encountered: