Skip to content

fix: make ShardingCodec equality work with rng field (#4005)#4007

Open
NIK-TIGER-BILL wants to merge 1 commit into
zarr-developers:mainfrom
NIK-TIGER-BILL:fix/sharding-codec-rng-equality
Open

fix: make ShardingCodec equality work with rng field (#4005)#4007
NIK-TIGER-BILL wants to merge 1 commit into
zarr-developers:mainfrom
NIK-TIGER-BILL:fix/sharding-codec-rng-equality

Conversation

@NIK-TIGER-BILL
Copy link
Copy Markdown
Contributor

This PR fixes the equality comparison for ShardingCodec when the rng field is present.

Because np.random.Generator does not implement __eq__, the auto-generated dataclass __eq__ always returned False when rng was not None, even for two identical codec instances.

Changes:

  • Add custom __eq__ that compares np.random.Generator objects by their bit_generator.state.
  • Add custom __hash__ that hashes the same state.
  • Add unit tests covering equal / not-equal / None cases.

Closes #4005

…#4005)

ShardingCodec gained a  field in a recent commit. Because
 does not implement , the auto-generated
dataclass  always returned  when  was not .

This patch adds custom  and  methods that compare
Generators by their , restoring deterministic
equality for otherwise-identical codec instances.

Closes zarr-developers#4005

Signed-off-by: NIK-TIGER-BILL <nik.tiger.bill@github.com>
@github-actions github-actions Bot added the needs release notes Automatically applied to PRs which haven't added release notes label May 25, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 25, 2026

Codecov Report

❌ Patch coverage is 75.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.47%. Comparing base (c0e2afa) to head (cb4d230).

Files with missing lines Patch % Lines
src/zarr/codecs/sharding.py 75.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4007      +/-   ##
==========================================
- Coverage   93.49%   93.47%   -0.03%     
==========================================
  Files          88       88              
  Lines       11873    11889      +16     
==========================================
+ Hits        11101    11113      +12     
- Misses        772      776       +4     
Files with missing lines Coverage Δ
src/zarr/codecs/sharding.py 91.39% <75.00%> (-0.74%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs release notes Automatically applied to PRs which haven't added release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sharding codec equality broken due to new rng field

1 participant