Skip to content

Commit 919be15

Browse files
committed
fixup: Make sure we don't copy arrays as we check for zeroes
1 parent c65774c commit 919be15

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/zarr/core/buffer/core.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,11 +525,12 @@ def all_equal(self, other: Any, equal_nan: bool = True) -> bool:
525525
return False
526526
# Handle positive and negative zero by comparing bit patterns:
527527
if (
528-
np.array(other).dtype.kind == "f"
528+
np.asarray(other).dtype.kind == "f"
529529
and other == 0.0
530530
and self._data.dtype.kind not in ("U", "S", "T", "O", "V")
531531
):
532-
return np.array_equiv(np.array(self._data).view("V"), np.array(other).view("V"))
532+
_data, other = np.broadcast_arrays(self._data, other)
533+
return np.array_equal(_data.view("V"), other.view("V"))
533534
# use array_equal to obtain equal_nan=True functionality
534535
# Since fill-value is a scalar, isn't there a faster path than allocating a new array for fill value
535536
# every single time we have to write data?

tests/test_array.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -906,21 +906,21 @@ def test_write_empty_chunks_behavior(
906906

907907
@pytest.mark.parametrize("store", ["memory"], indirect=True)
908908
@pytest.mark.parametrize("fill_value", [0.0, -0.0])
909+
@pytest.mark.parametrize("dtype", ["f4", "f2"])
909910
def test_write_empty_chunks_negative_zero(
910-
zarr_format: ZarrFormat, store: MemoryStore, fill_value: float
911+
zarr_format: ZarrFormat, store: MemoryStore, fill_value: float, dtype: str
911912
) -> None:
912913
# regression test for https://github.com/zarr-developers/zarr-python/issues/3144
913914

914915
arr = zarr.create_array(
915916
store=store,
916917
shape=(2,),
917918
zarr_format=zarr_format,
918-
dtype="f4",
919+
dtype=dtype,
919920
fill_value=fill_value,
920921
chunks=(1,),
921922
config={"write_empty_chunks": False},
922923
)
923-
924924
assert arr.nchunks_initialized == 0
925925

926926
# initialize the with the negated fill value (-0.0 for +0.0, +0.0 for -0.0)

0 commit comments

Comments
 (0)