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
Recursive OrderedDict pickling #62100
Comments
Here is a patch which allows pickling of recursive OrderedDicts. Actually it simplifies __reduce__() code. |
In additional the patch decreases the size of the pickled data, speeds up pickling and unpickling. $ ./python -c "import collections, pickle; od = collections.OrderedDict((i, i) for i in range(100000)); print(len(pickle.dumps(od)))" Without patch: 1536827. $ ./python -m timeit -s "from pickle import dumps; import collections; od = collections.OrderedDict((i, i) for i in range(100000))" "dumps(od)" Without patch: 454 msec. $ ./python -m timeit -s "from pickle import dumps, loads; import collections; od = collections.OrderedDict((i, i) for i in range(100000)); x = dumps(od)" "loads(x)" Without patch: 1.41 sec. |
Ping. |
The patch looks good to me. So go ahead and submit it. :) |
New changeset 56f25569ba86 by Serhiy Storchaka in branch 'default': |
This patch caused a regression by breaking designed-in support for pickling using PyYAML (note, there was a test for yaml support, but this patch defeated the test). As a result of the patch, ordering now gets lost during a dump/load roundtrip. This change should not have been committed without my review (I would have caught the problem instantly). |
Can you explain what is broken independently of PyYAML? |
Oh, sorry, I did not notice test_yaml_linkage. And in any case this test was broken (should be rv[1][0] instead of rv[1]). I don't like to revert these changes, and the reversion can break a code written for 3.4 which pickles recursive OrderedDicts. I suggest following solution. PyYAML calls __reduce_ex_(2) or __reduce__(). Therefore we can return to old behavior with protocol < 3 and left current behavior with protocol >= 3. Recursive OrderedDicts will be pickleable with default protocol and with highest protocol, and PyYAML will be happy. Does this patch look good to your? |
I think it is too late to revert this change. Is it worth to add a workaround for PyYAML if it still hasn't fixed serialization of OrderedDicts? |
At this point, we can drop it. PyYAML will just have to deal with it. |
Reported PyYAML issue: https://bitbucket.org/xi/pyyaml/issues/61/ordereddict-doesnt-round-trip. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: