Repository navigation
Handle dicts with unsortable keys in serialize_object - #1058
Open
thelastbackspace wants to merge 1 commit into
Open
thelastbackspace wants to merge 1 commit into
thelastbackspace wants to merge 1 commit into
Conversation
serialize_object/deserialize_object walked small dicts with sorted(),
which raises TypeError for mixed key types like {'A': 1, 2: 2}.
Fall back to insertion order when sorting fails, and walk the unpickled
dict in its own order on the way back, which is the order the buffers
were extracted in.
Closes ipython#1057
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1057
serialize_objectanddeserialize_objectwalk small dicts (fewer thanMAX_ITEMSentries) withsorted(), so something like{'A': 1, 2: 2}raisesTypeError: '<' not supported between instances of 'int' and 'str'and can't be sent to engines at all.On the serialize side I kept
sorted()and only fall back to insertion order when sorting raises, so anything that worked before produces exactly the same message. On the deserialize side I just walk the unpickled dict in its own order instead of re-sorting. That dict is thecobjthatserialize_objectbuilt, so its order is the order the buffers were pulled out in. For messages from older clients that's still sorted order, so mixed versions keep working.Testing:
Added two tests: a plain mixed-key dict, and a mixed-key dict holding two numpy arrays big enough to go out as separate buffers, to check each one comes back under the right key. Both fail on main with the TypeError and pass with this change.
The full test suite passes apart from a couple of cluster tests that fail intermittently here with or without this change.
Thanks to @raisingchris2026 for the report and the suggested diff.