Skip to content

Commit

Permalink
replace np.NaN with np.nan in preparation for numpy 2.0 (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomNicholas authored Jun 13, 2024
1 parent dc62090 commit 18f195a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions virtualizarr/tests/test_kerchunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_dataset_from_df_refs():

assert da.data.zarray.compressor is None
assert da.data.zarray.filters is None
assert da.data.zarray.fill_value is np.NaN
assert da.data.zarray.fill_value is np.nan
assert da.data.zarray.order == "C"

assert da.data.manifest.dict() == {
Expand Down Expand Up @@ -76,7 +76,7 @@ def test_accessor_to_kerchunk_dict(self):
chunks=(2, 3),
compressor=None,
filters=None,
fill_value=np.NaN,
fill_value=np.nan,
order="C",
),
)
Expand Down Expand Up @@ -105,7 +105,7 @@ def test_accessor_to_kerchunk_json(self, tmp_path):
chunks=(2, 3),
compressor=None,
filters=None,
fill_value=np.NaN,
fill_value=np.nan,
order="C",
),
)
Expand Down Expand Up @@ -186,7 +186,7 @@ def test_kerchunk_roundtrip_in_memory_no_concat():
chunks=(2, 2),
compressor=None,
filters=None,
fill_value=np.NaN,
fill_value=np.nan,
order="C",
),
chunkmanifest=manifest,
Expand Down
2 changes: 1 addition & 1 deletion virtualizarr/tests/test_manifests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_create_manifestarray_from_kerchunk_refs(self):
assert marr.chunks == (2, 3)
assert marr.dtype == np.dtype("int64")
assert marr.zarray.compressor is None
assert marr.zarray.fill_value is np.NaN
assert marr.zarray.fill_value is np.nan
assert marr.zarray.filters is None
assert marr.zarray.order == "C"

Expand Down
2 changes: 1 addition & 1 deletion virtualizarr/tests/test_zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_zarr_v3_roundtrip(tmpdir):
chunks=(2, 3),
compressor=None,
filters=None,
fill_value=np.NaN,
fill_value=np.nan,
order="C",
zarr_format=3,
),
Expand Down
8 changes: 4 additions & 4 deletions virtualizarr/zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ZArray(BaseModel):
chunks: tuple[int, ...]
compressor: str | None = None
dtype: np.dtype
fill_value: float | int | None = np.NaN # float or int?
fill_value: float | int | None = np.nan # float or int?
filters: list[dict] | None = None
order: Literal["C", "F"]
shape: tuple[int, ...]
Expand Down Expand Up @@ -76,7 +76,7 @@ def from_kerchunk_refs(cls, decoded_arr_refs_zarray) -> "ZArray":
# coerce type of fill_value as kerchunk can be inconsistent with this
fill_value = decoded_arr_refs_zarray["fill_value"]
if fill_value is None or fill_value == "NaN":
fill_value = np.NaN
fill_value = np.nan

return ZArray(
chunks=tuple(decoded_arr_refs_zarray["chunks"]),
Expand All @@ -94,7 +94,7 @@ def dict(self) -> dict[str, Any]:

zarray_dict["dtype"] = encode_dtype(zarray_dict["dtype"])

if zarray_dict["fill_value"] is np.NaN:
if zarray_dict["fill_value"] is np.nan:
zarray_dict["fill_value"] = None

return zarray_dict
Expand Down Expand Up @@ -247,7 +247,7 @@ def metadata_from_zarr_json(filepath: Path) -> tuple[ZArray, list[str], dict]:
chunk_shape = metadata["chunk_grid"]["configuration"]["chunk_shape"]

if metadata["fill_value"] is None:
fill_value = np.NaN
fill_value = np.nan
else:
fill_value = metadata["fill_value"]

Expand Down

0 comments on commit 18f195a

Please sign in to comment.