Skip to content

Serialize numpy scalars, set, frozenset, Path, datetime, date and time - #3

Merged
seb5g merged 2 commits into
mainfrom
feature/more-standard-types
Nov 14, 2026
Merged

seb5g merged 2 commits into
mainfrom
feature/more-standard-types

Conversation

@seb5g

@seb5g seb5g commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

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 the extra_attributes of PyMoDAQ data (see PyMoDAQ/PyMoDAQ#1495).

  • numpy scalars: float16/32, int8/16/32, uint8/16/32/64, complex64 keep their dtype after a round trip. The ones with an exact python equivalent (float64, int64, complex128, bool_) are deserialized as float, int, complex, bool: same value and behaviour, and what libraries expecting pure python (json...) need. This matches what ScalarSerializeDeserialize already 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 a Path of 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.fromisoformat is used on Python 3.8+ for strings produced by isoformat(), which it parses on all those versions.


Generated by Claude Code

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

seb5g commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

The tests (ubuntu-latest, 3.9) job fails before running any test: The version '3.9' with architecture 'x64' was not found for Ubuntu 26.04 (actions/setup-python step, see https://github.com/PyMoDAQ/serializall/actions/runs/43601569589/job/132467232567). ubuntu-latest now resolves to Ubuntu 26.04, which has no Python 3.9 build, so this is a runner image issue and not related to this diff. The other jobs of the matrix are not affected by it. Python 3.9 is still in the matrix of .github/workflows/tests.yml; the options are pinning that entry to an older runner (ubuntu-24.04) or dropping 3.9, which is a decision for the maintainers.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants