Skip to content

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
@codecov
Copy link

codecov bot commented Jul 28, 2025

Codecov Report

❌ Patch coverage is 29.48718% with 55 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.93%. Comparing base (e3ee591) to head (e0de52d).

Files with missing lines Patch % Lines
src/zarr/core/group.py 4.54% 21 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 25.00% 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   61.86%   61.93%   +0.06%     
==========================================
  Files          85       86       +1     
  Lines       10112    10129      +17     
==========================================
+ Hits         6256     6273      +17     
  Misses       3856     3856              
Files with missing lines Coverage Δ
src/zarr/metadata/migrate_v3.py 98.36% <100.00%> (+0.01%) ⬆️
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 68.59% <25.00%> (-0.04%) ⬇️
src/zarr/core/indexing.py 69.46% <0.00%> (ø)
src/zarr/api/synchronous.py 36.61% <0.00%> (ø)
src/zarr/api/asynchronous.py 72.20% <0.00%> (ø)
... and 1 more
🚀 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
@dstansby dstansby added this to the 3.1.2 milestone Jul 30, 2025
@dstansby dstansby force-pushed the array-param branch 3 times, most recently from bbabb9b to a168b6c Compare August 5, 2025 12:00
@d-v-b d-v-b mentioned this pull request Aug 13, 2025
@dstansby dstansby force-pushed the array-param branch 3 times, most recently from 9c3938f to 2807003 Compare August 26, 2025 14:44
Comment on lines +3 to +5
from zarr.core.array import Array, AsyncArray
from zarr.core.metadata.v2 import ArrayV2Metadata
from zarr.core.metadata.v3 import ArrayV3Metadata
Copy link
Contributor

Choose a reason for hiding this comment

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

these imports will prevent zarr.core.array from using anything defined in zarr.types, is that intentional?

Copy link
Contributor

Choose a reason for hiding this comment

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

(outside of a type-checking context, I mean)

Copy link
Contributor

Choose a reason for hiding this comment

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

thinking more about this, I think as long as everything in zarr.types is imported exclusively in if TYPE_CHECKING blocks, then there's no risk of circular imports. we would only have circular imports if we tried to work with types as values outside of type-checking, for example using get_args(ZarrFormat). We can always avoid this by defining a typed constant value somewhere else in the codebase.

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 certinaly didn't think about this! So neither intentional or unintentional. I'm not sure I see a better solution, but open to suggestions.

Copy link
Contributor

Choose a reason for hiding this comment

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

What was the problem that necessitated defining type aliases in the top-level types file? I wonder if there's another way to solve that. This is my only concern about this PR btw, we can get it in soon after this is resolved

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 think there wasn't a problem, and this was a choice 😄 - the circular import mess seems a good reason to move these out and next to the array/group classes. Might be a little while until I find time, so someone else is very free to finish this PR off if I don't get there first.

@d-v-b
Copy link
Contributor

d-v-b commented Sep 3, 2025

I think these changes are good, as they make it easier to track the v2-ness of v3-ness of the Array class.

But since this PR changes the Array class, and it will also require anyone who annotated variables with the Array type to update that annotation, I think it's important that we get a lot of eyes on this PR.

cc @zarr-developers/core-devs

@github-actions github-actions bot added needs release notes Automatically applied to PRs which haven't added release notes and removed needs release notes Automatically applied to PRs which haven't added release notes labels Sep 21, 2025
@d-v-b d-v-b requested a review from a team September 25, 2025 12:24
@d-v-b
Copy link
Contributor

d-v-b commented Oct 1, 2025

I think these changes are good, as they make it easier to track the v2-ness of v3-ness of the Array class.

But since this PR changes the Array class, and it will also require anyone who annotated variables with the Array type to update that annotation, I think it's important that we get a lot of eyes on this PR.

cc @zarr-developers/core-devs

ping @zarr-developers/core-devs

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