Skip to content

Serialize datetime arrays on Linux and Windows (0.2.27) - #53

Merged
nicholas9182 merged 1 commit into
mainfrom
fix/serialize-datetime-arrays-linux
Nov 18, 2026
Merged

nicholas9182 merged 1 commit into
mainfrom
fix/serialize-datetime-arrays-linux

Conversation

@nicholas9182

@nicholas9182 nicholas9182 commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

The bug

SerializerMixin.serialize() raised ValueError: cannot include dtype 'M' in a buffer on Linux and Windows for:

  • a DataFrame with a datetime64 or timedelta64 column or index;
  • such an array held directly, or inside a list or dict.

It worked on macOS, so it passed on a developer's Mac and failed in CI and in production. It was found through steer-financing, whose CashFlow holds a table with start_dt and end_dt columns: 20 of its roundtrip tests had failed on Linux since September.

Cause

msgpack_numpy reads an array's bytes through the buffer protocol (ndarray.data) everywhere except macOS, where it calls tobytes(). numpy does not export datetime arrays as buffers.

The fix

  • _portable_array in Mixins/Serializer.py encodes datetime64 and timedelta64 arrays into the exact map msgpack_numpy writes on macOS.
  • _serialize_dataframe uses it for each column and the index; _serialize_value uses it for a bare array.
  • The payload is byte for byte what macOS always produced, so reading is unchanged and existing payloads still load.

Tests

TestDatetimeArraysOnEveryPlatform runs the Linux, macOS and Windows paths on any machine (msgpack_numpy reads sys.platform at call time) and checks the payload is identical on each. The tests fail without the fix. Locally: 406 pass, and 406 pass with the Linux path forced for every test.

Release

Bumps the version to 0.2.27 with a CHANGELOG entry. steer-financing carries a copy of this fix as a mixin, which it can drop once 0.2.27 is on PyPI.

🤖 Generated with Claude Code


Note

Overview
Fixes cross-platform serialization for datetime64 and timedelta64 numpy data in SerializerMixin, which previously raised ValueError: cannot include dtype 'M' in a buffer on Linux and Windows while working on macOS.

A new _portable_array helper pre-encodes those arrays into the same msgpack map msgpack_numpy already produces on macOS (via tobytes()), so wire format stays byte-identical and deserialization is unchanged. It is wired into the generic serialize fallback and into _serialize_dataframe for columns and index.

Release 0.2.27 updates CHANGELOG and __version__. TestDatetimeArraysOnEveryPlatform simulates linux/darwin/win32 and asserts round-trips and identical payloads across platforms.

Reviewed by Cursor Bugbot for commit 90fd523. Bugbot is set up for automated code reviews on this repo. Configure here.

SerializerMixin.serialize() raised "ValueError: cannot include dtype 'M' in a
buffer" on Linux and Windows for a DataFrame with a datetime64 or timedelta64
column or index, or for such an array held directly. It worked on macOS:
msgpack_numpy reads an array's bytes through the buffer protocol everywhere
except macOS, where it calls tobytes(), and numpy does not export datetime
arrays as buffers.

_portable_array encodes those arrays into the map msgpack_numpy writes on
macOS, so the payload is byte for byte what macOS always produced. Reading is
unchanged and existing payloads still load. The tests run every platform's
path on any machine, because msgpack_numpy reads sys.platform at call time.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@nicholas9182
nicholas9182 merged commit b5e72f1 into main Nov 18, 2026
3 checks passed
@nicholas9182
nicholas9182 deleted the fix/serialize-datetime-arrays-linux branch November 18, 2026 20:39
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.

1 participant