Skip to content

Commit a8caaa4

Browse files
committed
Fixup
1 parent 1daf5f3 commit a8caaa4

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

src/zarr/codecs/pipeline.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,12 @@ async def read_batch(
250250
else:
251251
fill_value = chunk_spec.fill_value
252252

253-
# this should maybe be version specific?
254253
if fill_value is None:
254+
# Zarr V2 allowed `fill_value` to be null in the metadata.
255+
# Zarr V3 requires it to be set. This has already been
256+
# validated when decoding the metadata, but we support reading
257+
# Zarr V2 data and need to support the case where fill_value
258+
# is None.
255259
fill_value = default_fill_value(dtype=chunk_spec.dtype)
256260

257261
out[out_selection] = fill_value

src/zarr/core/metadata/v2.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,7 @@ def __init__(
6262
order_parsed = parse_indexing_order(order)
6363
dimension_separator_parsed = parse_separator(dimension_separator)
6464
filters_parsed = parse_filters(filters)
65-
if fill_value is None:
66-
fill_value_parsed = None
67-
else:
68-
fill_value_parsed = parse_fill_value(fill_value, dtype=data_type_parsed)
65+
fill_value_parsed = parse_fill_value(fill_value, dtype=data_type_parsed)
6966
attributes_parsed = parse_attributes(attributes)
7067

7168
object.__setattr__(self, "shape", shape_parsed)
@@ -290,4 +287,16 @@ def parse_fill_value(fill_value: object, dtype: np.dtype[Any]) -> Any:
290287

291288

292289
def default_fill_value(dtype: np.dtype[Any]) -> Any:
290+
"""
291+
Get the default fill value for a type.
292+
293+
Notes
294+
-----
295+
This differs from :func:`parse_fill_value`, which parses a fill value
296+
stored in the Array metadata into an in-memory value. This only gives
297+
the default fill value for some type.
298+
299+
This is useful for reading Zarr V2 arrays, which allow the fill
300+
value to be unspecified.
301+
"""
293302
return dtype.type(0)

tests/v3/test_v2.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,3 @@ def test_codec_pipeline() -> None:
5555
result = array[:]
5656
expected = np.ones(1)
5757
np.testing.assert_array_equal(result, expected)
58-
59-

0 commit comments

Comments
 (0)