Skip to content

Parametrize Array with v2/v3 metadata #3304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

dstansby
Copy link
Contributor

@dstansby dstansby commented Jul 28, 2025

It has been a longstanding bugbear of mine that there's no easy way to specify a v2 or v3 array type. This especially came up in the context of #3257, which deals specifically with v2/v3 arrays.

This PR ads type parametrization to the Array class.

After this PR, there is lots of improvements to adding overloads to functions and methods that could be made, but to keep review easier I'd like to leave that for a follow up PR.

@github-actions github-actions bot added the needs release notes Automatically applied to PRs which haven't added release notes label Jul 28, 2025
Copy link

codecov bot commented Jul 28, 2025

Codecov Report

❌ Patch coverage is 29.11392% with 56 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.79%. Comparing base (108ec58) to head (f4f3867).

Files with missing lines Patch % Lines
src/zarr/core/group.py 4.34% 22 Missing ⚠️
src/zarr/api/asynchronous.py 0.00% 12 Missing ⚠️
src/zarr/api/synchronous.py 0.00% 10 Missing ⚠️
src/zarr/core/indexing.py 0.00% 6 Missing ⚠️
src/zarr/core/array.py 62.50% 3 Missing ⚠️
src/zarr/core/attributes.py 0.00% 1 Missing ⚠️
src/zarr/core/metadata/__init__.py 0.00% 1 Missing ⚠️
src/zarr/core/sync_group.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3304      +/-   ##
==========================================
+ Coverage   60.73%   60.79%   +0.06%     
==========================================
  Files          78       79       +1     
  Lines        9407     9423      +16     
==========================================
+ Hits         5713     5729      +16     
  Misses       3694     3694              
Files with missing lines Coverage Δ
src/zarr/testing/strategies.py 97.82% <100.00%> (+0.01%) ⬆️
src/zarr/types.py 100.00% <100.00%> (ø)
src/zarr/core/attributes.py 46.15% <0.00%> (ø)
src/zarr/core/metadata/__init__.py 0.00% <0.00%> (ø)
src/zarr/core/sync_group.py 42.85% <0.00%> (ø)
src/zarr/core/array.py 69.63% <62.50%> (-0.04%) ⬇️
src/zarr/core/indexing.py 68.10% <0.00%> (ø)
src/zarr/api/synchronous.py 37.14% <0.00%> (ø)
src/zarr/api/asynchronous.py 69.56% <0.00%> (ø)
src/zarr/core/group.py 70.19% <4.34%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dstansby dstansby force-pushed the array-param branch 3 times, most recently from 53da48a to d9e50d2 Compare July 28, 2025 14:51
@dstansby dstansby marked this pull request as ready for review July 28, 2025 15:46
@github-actions github-actions bot removed the needs release notes Automatically applied to PRs which haven't added release notes label Jul 28, 2025
AsyncArrayV3: TypeAlias = AsyncArray[ArrayV3Metadata]
"""A Zarr format 3 `AsyncArray`"""

AnyArray: TypeAlias = Array[Any]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be Array[ArrayV2Metadata] | Array[ArrayV3Metadata]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I guess that's safer 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't get that to work, beacuse of an error that I sort of but not really understand ☹️ . I think the current state with Any is fine though - .metadata still gets inferred correctly:

import zarr
import zarr.storage

arr = zarr.ones(shape=(1,))
meta = arr.metadata
reveal_locals()
"""
test.py:6: note: Revealed local types are:
test.py:6: note:     arr: zarr.core.array.Array[Any]
test.py:6: note:     meta: zarr.core.metadata.v2.ArrayV2Metadata | zarr.core.metadata.v3.ArrayV3Metadata
"""

@dstansby dstansby added this to the 3.1.2 milestone Jul 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants