Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix default fill_value
  • Loading branch information
dcherian committed Sep 24, 2024
commit efcf1f59d31535d3b7aecd6b437604c4747c6213
7 changes: 0 additions & 7 deletions src/zarr/core/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,6 @@ async def _create_v3(
shape = parse_shapelike(shape)
codecs = list(codecs) if codecs is not None else [BytesCodec()]

if fill_value is None:
if dtype == np.dtype("bool"):
fill_value = False
else:
fill_value = 0

if chunk_key_encoding is None:
chunk_key_encoding = ("default", "/")
assert chunk_key_encoding is not None
Expand All @@ -281,7 +275,6 @@ async def _create_v3(
)

array = cls(metadata=metadata, store_path=store_path)

await array._save_metadata(metadata)
return array

Expand Down
3 changes: 3 additions & 0 deletions src/zarr/core/buffer/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,9 @@ def __repr__(self) -> str:

def all_equal(self, other: Any, equal_nan: bool = True) -> bool:
"""Compare to `other` using np.array_equal."""
if other is None:
# Handle None fill_value for Zarr V2
return False
# use array_equal to obtain equal_nan=True functionality
data, other = np.broadcast_arrays(self._data, other)
result = np.array_equal(self._data, other, equal_nan=equal_nan)
Expand Down
6 changes: 4 additions & 2 deletions src/zarr/testing/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def arrays(
name = draw(array_names)
attributes = draw(attrs)
zarr_format = draw(zarr_formats)
fill_value = draw(npst.from_dtype(nparray.dtype))
# test that None works too.
fill_value = draw(st.one_of([st.none(), npst.from_dtype(nparray.dtype)]))
# compressor = draw(compressors)

expected_attrs = {} if attributes is None else attributes
Expand All @@ -93,11 +94,12 @@ def arrays(
chunks=chunks,
dtype=nparray.dtype,
attributes=attributes,
# compressor=compressor, # TODO: FIXME
# compressor=compressor, # FIXME
fill_value=fill_value,
)

assert isinstance(a, Array)
assert a.fill_value is not None
assert isinstance(root[array_path], Array)
assert nparray.shape == a.shape
assert chunks == a.chunks
Expand Down