Skip to content

Commit 58b4070

Browse files
committed
Reorganize structured fill parsing
1 parent 042d815 commit 58b4070

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/zarr/core/metadata/v2.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -294,22 +294,21 @@ def parse_metadata(data: ArrayV2Metadata) -> ArrayV2Metadata:
294294

295295
def _parse_structured_fill_value(fill_value: Any, dtype: np.dtype[Any]) -> Any:
296296
"""Handle structured dtype/fill value pairs"""
297+
print("FILL VALUE", fill_value, "DT", dtype)
297298
try:
298299
if isinstance(fill_value, list):
299300
fill_value = tuple(fill_value)
300301
if isinstance(fill_value, tuple):
301-
fill_value = np.array([fill_value], dtype=dtype)[0]
302+
return np.array([fill_value], dtype=dtype)[0]
302303
elif isinstance(fill_value, bytes):
303-
fill_value = np.frombuffer(fill_value, dtype=dtype)[0]
304+
return np.frombuffer(fill_value, dtype=dtype)[0]
304305
elif isinstance(fill_value, str):
305306
decoded = base64.standard_b64decode(fill_value)
306-
fill_value = np.frombuffer(decoded, dtype=dtype)[0]
307+
return np.frombuffer(decoded, dtype=dtype)[0]
307308
else:
308-
fill_value = np.array(fill_value, dtype=dtype)[()]
309+
return np.array(fill_value, dtype=dtype)[()]
309310
except Exception as e:
310-
msg = f"Fill_value {fill_value} is not valid for dtype {dtype}."
311-
raise ValueError(msg) from e
312-
return fill_value
311+
raise ValueError(f"Fill_value {fill_value} is not valid for dtype {dtype}.") from e
313312

314313

315314
def parse_fill_value(fill_value: Any, dtype: np.dtype[Any]) -> Any:

tests/test_v2.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ def test_parse_structured_fill_value_valid(
367367
fill_value: Any, dtype: np.dtype[Any], expected_result: Any
368368
) -> None:
369369
result = _parse_structured_fill_value(fill_value, dtype)
370+
print(result)
370371
assert result.dtype == expected_result.dtype
371372
assert result == expected_result
372373
if isinstance(expected_result, np.void):

0 commit comments

Comments
 (0)