Skip to content
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

refactor metadata into metadata.v2 and metadata.v3 modules #2059

Closed
wants to merge 3 commits into from

Conversation

d-v-b
Copy link
Contributor

@d-v-b d-v-b commented Jul 31, 2024

In main, we handle v2 and v3 metadata differences by having functions with names like function_purpose_v2 and function_purpose_v3. I think it would be more clear to collect all the v2- and v3-specific routines into separate modules.

This PR creates new metadata.v2 and metadata.v3 modules for the metadata classes, as well as a metadata.common module, for some routines that have identical v2 and v3 semantics. Functions that previously signified v2-ness or v3-ness in their name now signify it from their location. In this PR The only exports from zarr.metadata are ArrayV2Metadata and ArrayV3Metadata.

I made a few other related changes:

  • in main, we annotate the metadata attribute of AsyncArray with the abstract array metadata base class. I changed these annotations to ArrayV2Metadata | ArrayV3Metadata, which should be much more useful. In a later effort we could consider making AsyncArray generic over the type of array metadata to give even more information to the type system.

  • In main v2 metadata creation relies on an import from zarr.v2. This will not be valid after v2 is gone, so I ported the v2.normalize_fill_value routine into zarr.metadata.v2.parse_fill_value, and made some minor internal changes to the exceptions in that routine.

TODO:

  • Add unit tests and/or doctests in docstrings
  • Add docstrings and API docs for any new/modified user-facing classes and functions
  • New/modified features documented in docs/tutorial.rst
  • Changes documented in docs/release.rst
  • GitHub Actions have all passed
  • Test coverage is 100% (Codecov passes)

refactor metadata into v2 and v3 modules

remove version signifiers from function names

fix tests
@d-v-b d-v-b requested review from normanrz and jhamman and removed request for normanrz July 31, 2024 09:45
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 file also get an __all__?

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'm open to this, but I think it would only affect cases where people did from zarr.metadata.v2 import *; from zarr.metadata.v2 import foo would still work whether or not foo is in __all__.

Copy link
Member

@jhamman jhamman left a comment

Choose a reason for hiding this comment

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

Nice cleanup @d-v-b.


@property
def byte_count(self) -> int:
data_type_byte_counts = {
Copy link
Member

Choose a reason for hiding this comment

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

I know this wasn't introduced here but we should pull all of these dicts into module level variables. No need to recreate them every time we use the datatype.

@@ -92,14 +92,14 @@ def create_codec_pipeline(metadata: ArrayV2Metadata | ArrayV3Metadata) -> CodecP

@dataclass(frozen=True)
class AsyncArray:
metadata: ArrayMetadata
metadata: ArrayV3Metadata | ArrayV2Metadata
Copy link
Member

Choose a reason for hiding this comment

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

I slightly favor reverting this change as a way to future proof this a bit.

@jhamman jhamman added the V3 Related to compatibility with V3 spec label Aug 9, 2024
@d-v-b
Copy link
Contributor Author

d-v-b commented Sep 13, 2024

this was addressed by #2163

@d-v-b d-v-b closed this Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
V3 Related to compatibility with V3 spec
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants