Repository navigation
fix: hash datetime64 arrays in object_hash instead of crashing - #61
Merged
Merged
Conversation
construct_object_hash fed the ndarray's buffer (np.ascontiguousarray(obj.data))
straight to xxhash. datetime64 / timedelta64 ('M'/'m') arrays cannot be exposed
through the buffer protocol, so checkpointing any such variable raised
"cannot include dtype 'M' in a buffer" and aborted the checkpoint.
Hash the raw bytes via a uint8 view of the contiguous array, which works for
those dtypes, with a tobytes() fallback for object-dtype arrays that cannot be
reinterpreted.
Adds object_hash unit tests for datetime64/timedelta64/object arrays, and
removes numpy-datetime64 from the issue #48 coverage KNOWN_LIMITATIONS (the
coverage table now shows it as Migrated/Recomputed).
close #60
Co-Authored-By: Claude Opus 4.8 (1M context) <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.
概要
issue #60 の修正。numpy の
datetime64配列を変数に持つ状態で checkpoint しようとすると、object_hashのフィンガープリント計算がValueError: cannot include dtype 'M' in a bufferで落ち、チェックポイントの保存・復元が失敗していた問題を修正する。原因
construct_object_hashは ndarray のバッファ(np.ascontiguousarray(obj.data))をそのまま xxhash に渡していた。datetime64/timedelta64(dtype kind'M'/'m')の配列は buffer プロトコルで公開できないため、ここで例外になっていた。修正
連続化した配列の uint8 ビュー(
arr.view(np.uint8))でrawバイトをハッシュするように変更。これにより datetime64/timedelta64 もハッシュ可能になる。reinterpret できない object 配列はtobytes()にフォールバック。ゼロコピー(連続時)で、既存の数値・構造化・bool 等の配列の挙動は維持。テスト
tests/test_object_hash.pyに回帰テストを追加:datetime64 / timedelta64 / object 配列がクラッシュせずハッシュでき、内容差を検出できることを検証。numpy-datetime64が Migrate ✅ / Recompute ✅ になることを確認し、KNOWN_LIMITATIONSから除外。カバレッジ表も ✅ に更新(CI が自動同期)。補足
fix:(patch バンプ)。close #60
🤖 Generated with Claude Code