-
-
Notifications
You must be signed in to change notification settings - Fork 326
Fix nan fill value metadata comparison #2930
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -233,7 +233,7 @@ class ArrayV3MetadataDict(TypedDict): | |
attributes: dict[str, JSON] | ||
|
||
|
||
@dataclass(frozen=True, kw_only=True) | ||
@dataclass(frozen=True, kw_only=True, eq=False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should do this for |
||
class ArrayV3Metadata(Metadata): | ||
shape: ChunkCoords | ||
data_type: DataType | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -411,3 +411,20 @@ def test_dtypes(dtype_str: str) -> None: | |
else: | ||
# return type for vlen types may vary depending on numpy version | ||
assert dt.byte_count is None | ||
|
||
|
||
def test_metadata_comparison_with_nan_fill_value(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test could presumably be parametrized over both v2 and v3 metadata, but you don't appear to have any other tests which do that. Is there a reason for that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the two metadata documents are separate entities, so they get tested separately. if there's shared functionality that they both depend on, but isn't part of their shared base class, then that shared functionality should have its own test. higher up in the stack we test the array classes against the two metadata varieties, because part of the job of the array classes is to abstract over the v2 v3 differences. |
||
# regression test for https://github.com/zarr-developers/zarr-python/issues/2929 | ||
metadata_dict = { | ||
"zarr_format": 3, | ||
"node_type": "array", | ||
"shape": (1,), | ||
"chunk_grid": {"name": "regular", "configuration": {"chunk_shape": (1,)}}, | ||
"data_type": np.dtype("float32"), | ||
"chunk_key_encoding": {"name": "default", "separator": "."}, | ||
"codecs": ({'name': 'bytes', 'configuration': {'endian': 'little'}},), | ||
"fill_value": np.float32("nan"), | ||
} | ||
metadata1 = ArrayV3Metadata.from_dict(metadata_dict) | ||
metadata2 = ArrayV3Metadata.from_dict(metadata_dict) | ||
assert metadata1 == metadata2 |
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.
Overriding this means we lose the nice auto-generated dataclass
__eq__
method, which prints out like this:But I don't see an easy way to keep that formatting and make it handle
fill_value
properly too...