-
-
Notifications
You must be signed in to change notification settings - Fork 286
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
Change ArrayV3Metadata.data_type to DataType #2278
Change ArrayV3Metadata.data_type to DataType #2278
Conversation
src/zarr/core/metadata/v3.py
Outdated
@@ -490,8 +492,11 @@ def to_numpy_shortname(self) -> str: | |||
} | |||
return data_type_to_numpy[self] | |||
|
|||
def to_numpy_dtype(self) -> np.dtype[Any]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could see to_numpy
as a slightly briefer name for this method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kind of prefer it more explicit, but I suppose that information is in the type annotation, so ok.
src/zarr/core/metadata/v3.py
Outdated
@classmethod | ||
def from_dtype(cls, dtype: np.dtype[Any]) -> DataType: | ||
def from_numpy_dtype(cls, dtype: np.dtype[Any]) -> DataType: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modulo to/from of course
In working on #2036, I realized that the current treatment of the
data_type
attribute in V3 metadata was somewhat inconsistent. This class is meant to represent the Zarr metadata in an abstract way, in alignment with the spec. However, it was just using numpy dtypes internally.This becomes a problem when we want to support dtypes that are not numpy dtypes, like
string
.This PR changes the
ArrayV3Metadata
class such that the type ofdata_type
is the existingDataType
enum. However, I've kept the.dtype
property returning a numpy dtype. This allows this change to be minimally disruptive to other parts of the code.