Repository navigation
Serialize datetime arrays on Linux and Windows (0.2.27) - #53
Merged
Merged
Conversation
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>
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.
The bug
SerializerMixin.serialize()raisedValueError: cannot include dtype 'M' in a bufferon Linux and Windows for:datetime64ortimedelta64column or index;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
CashFlowholds a table withstart_dtandend_dtcolumns: 20 of its roundtrip tests had failed on Linux since September.Cause
msgpack_numpyreads an array's bytes through the buffer protocol (ndarray.data) everywhere except macOS, where it callstobytes(). numpy does not export datetime arrays as buffers.The fix
_portable_arrayinMixins/Serializer.pyencodesdatetime64andtimedelta64arrays into the exact mapmsgpack_numpywrites on macOS._serialize_dataframeuses it for each column and the index;_serialize_valueuses it for a bare array.Tests
TestDatetimeArraysOnEveryPlatformruns the Linux, macOS and Windows paths on any machine (msgpack_numpyreadssys.platformat 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
datetime64andtimedelta64numpy data inSerializerMixin, which previously raisedValueError: cannot include dtype 'M' in a bufferon Linux and Windows while working on macOS.A new
_portable_arrayhelper pre-encodes those arrays into the same msgpack mapmsgpack_numpyalready produces on macOS (viatobytes()), so wire format stays byte-identical and deserialization is unchanged. It is wired into the generic serialize fallback and into_serialize_dataframefor columns and index.Release 0.2.27 updates
CHANGELOGand__version__.TestDatetimeArraysOnEveryPlatformsimulates 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.