Repository navigation
fix: make cached mapping indices read-only - #85
Merged
paulmueller merged 1 commit intoNov 23, 2026
Merged
Conversation
`get_mapping_indices` returns the same cached array for the same integer or slice mapping. A caller that modified the returned array in place changed the result of all later calls with that mapping. The cached arrays are read-only now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #85 +/- ##
==========================================
+ Coverage 88.23% 88.26% +0.02%
==========================================
Files 63 63
Lines 4539 4541 +2
==========================================
+ Hits 4005 4008 +3
+ Misses 534 533 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
paulmueller
approved these changes
Nov 23, 2026
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.
get_mapping_indicescaches its result for integer and slice mappings (functools.lru_cachein_get_mapping_indices_cached), so every caller gets the same array object. A caller that modified the returned array in place changed the result of all later calls with that mapping:No code in dcnum modifies these arrays, but code outside dcnum, or future code, could silently corrupt the mapping of unrelated
HDF5Datainstances.Fix
The cached arrays are made read-only (
setflags(write=False)). An in-place modification now raisesValueError: assignment destination is read-only. This is cheaper than copying on every call, which matters for largearangemappings. The docstring now has a "Returns" section that mentions this.Tests
test_mapping_indices_cache_not_modifiable[10|slice(2, 8)|slice(1, 9, 2)]. It fails on main and passes here.🤖 Generated with Claude Code