[bug] Ignore padding bytes when tokenizing structured numpy arrays - #273
Merged
Merged
Conversation
Structured dtypes can carry padding between their fields, and those bytes are never written. normalize_token hashed the raw buffer, so two arrays holding identical field values could produce different cache tokens depending on whatever happened to occupy the padding. This is easiest to hit with np.empty followed by field assignment, which leaves the padding holding unrelated heap contents. Recurse per field for structured dtypes instead of hashing the buffer. Arrays with object fields are unaffected, since the earlier hasobject branch already handles them via tolist() and never sees padding. Tokens for structured arrays change as a result, so cache entries keyed on one are invalidated once. Signed-off-by: Pascal Tomecek <pascal.tomecek@cubistsystematic.com>
ptomecek
marked this pull request as ready for review
September 21, 2026 23:25
Contributor
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #273 +/- ##
=======================================
Coverage 93.58% 93.59%
=======================================
Files 176 176
Lines 20586 20613 +27
Branches 1359 1361 +2
=======================================
+ Hits 19265 19292 +27
Misses 1048 1048
Partials 273 273 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Structured numpy dtypes can carry padding between their fields, and those bytes are never written.
normalize_tokenhashed the raw buffer, so two arrays holding identical field values could produce different cache tokens depending on whatever happened to occupy the padding. The easiest way to hit this isnp.emptyfollowed by field assignment, which leaves the padding holding unrelated heap contents.For structured dtypes the handler now recurses per field rather than hashing the buffer, which skips the padding. Arrays with object fields are unaffected — they are already matched by an earlier branch that goes through
tolist().Tokens for structured arrays change as a result, so any cache entry keyed on one is invalidated once.