Skip to content

Commit a8d473b

Browse files
committed
(fix): handle fill_value
1 parent f3e2e2d commit a8d473b

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/zarr/core/buffer/core.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,9 @@ def all_equal(self, other: Any, equal_nan: bool = True) -> bool:
470470
# every single time we have to write data?
471471
_data, other = np.broadcast_arrays(self._data, other)
472472
return np.array_equal(
473-
self._data, other, equal_nan=equal_nan if self._data.dtype.kind not in "USTO" else False
473+
self._data,
474+
other,
475+
equal_nan=equal_nan if self._data.dtype.kind not in "USTOV" else False,
474476
)
475477

476478
def fill(self, value: Any) -> None:

tests/test_v2.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,16 @@ def test_default_filters_and_compressor(dtype_expected: Any) -> None:
245245
assert arr.metadata.filters[0].codec_id == expected_filter
246246

247247

248-
def test_structured_dtype() -> None:
248+
@pytest.mark.parametrize("fill_value", [None, (b"", 0, 0.0)], ids=["no_fill", "fill"])
249+
def test_structured_dtype(fill_value, tmp_path) -> None:
249250
a = np.array(
250251
[(b"aaa", 1, 4.2), (b"bbb", 2, 8.4), (b"ccc", 3, 12.6)],
251252
dtype=[("foo", "S3"), ("bar", "i4"), ("baz", "f8")],
252253
)
253-
za = zarr.array(a, chunks=2, fill_value=None, zarr_format=2)
254+
za = zarr.create(
255+
shape=(3,), path=tmp_path, chunks=(2,), fill_value=fill_value, zarr_format=2, dtype=a.dtype
256+
)
257+
if fill_value is not None:
258+
assert (np.array([fill_value] * a.shape[0], dtype=a.dtype) == za[:]).all()
259+
za[...] = a
254260
assert (a == za[:]).all()

0 commit comments

Comments
 (0)