Repository navigation
Serialize numpy scalars, set, frozenset, Path, datetime, date and time - #3
Merged
Merged
Conversation
numpy scalars keep their dtype, except float64, int64, complex128 and bool_ which are deserialized as the equivalent python types (same value, what libraries such as json expect). set and frozenset go through the list serializer, paths as strings, datetime/date/time as ISO 8601 strings. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RKuN82pfthquUdrxJy1DaY
Contributor
Author
|
The Generated by Claude Code |
This was referenced Nov 14, 2026
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.
What
Registers more standard types in the factory. Until now any of them raised
NotImplementedError: There is no known method to serialize ..., which is easy to hit with theextra_attributesof PyMoDAQ data (see PyMoDAQ/PyMoDAQ#1495).float16/32,int8/16/32,uint8/16/32/64,complex64keep their dtype after a round trip. The ones with an exact python equivalent (float64,int64,complex128,bool_) are deserialized asfloat,int,complex,bool: same value and behaviour, and what libraries expecting pure python (json...) need. This matches whatScalarSerializeDeserializealready did for python numbers.set,frozenset: serialized as a list of their items (no order guaranteed).pathlib.Path(PosixPath,WindowsPath): serialized as a string, rebuilt as aPathof the local platform.datetime,date,time: serialized as ISO 8601 strings (timezone and microseconds are kept).The type name written in the stream is the class name, as for the other types. New types are new entries in the stream: data serialized before stays readable, but an older serializall refuses these types.
Tests
tests/serializer_test.py: round trip of each type, dtype preserved or cast as described, new types inside dict/list/tuple with leftover bytes, unregistered types still raise. 46 passed (21 before), Python 3.13 only, numpy 2.5 (not run on the older Python versions of the classifiers, nor with numpy 1.x).datetime.fromisoformatis used on Python 3.8+ for strings produced byisoformat(), which it parses on all those versions.Generated by Claude Code