Skip to content

Commit 25e6036

Browse files
alanhdujoshmoore
andauthored
Fix normalize_fill_value for structured arrays (#1397)
* Add failing test case for normalize_fill_value * Fix normalize_fill_value for structured arrays * Add changelog --------- Co-authored-by: Josh Moore <[email protected]>
1 parent d54f25c commit 25e6036

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

docs/release.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ Bug fixes
5252
* Fix ``ReadOnlyError`` when opening V3 store via fsspec reference file system.
5353
By :user:`Joe Hamman <jhamman>` :issue:`1383`.
5454

55+
* Fix ``normalize_fill_value`` for structured arrays.
56+
By :user:`Alan Du <alanhdu>` :issue:`1397`.
57+
5558
.. _release_2.14.2:
5659

5760
2.14.2

zarr/tests/test_util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def test_normalize_fill_value():
119119
structured_dtype = np.dtype([('foo', 'S3'), ('bar', 'i4'), ('baz', 'f8')])
120120
expect = np.array((b'', 0, 0.), dtype=structured_dtype)[()]
121121
assert expect == normalize_fill_value(0, dtype=structured_dtype)
122+
assert expect == normalize_fill_value(expect, dtype=structured_dtype)
122123
assert '' == normalize_fill_value(0, dtype=np.dtype('U1'))
123124

124125

zarr/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def normalize_fill_value(fill_value, dtype: np.dtype):
295295
if fill_value is None or dtype.hasobject:
296296
# no fill value
297297
pass
298-
elif fill_value == 0:
298+
elif not isinstance(fill_value, np.void) and fill_value == 0:
299299
# this should be compatible across numpy versions for any array type, including
300300
# structured arrays
301301
fill_value = np.zeros((), dtype=dtype)[()]

0 commit comments

Comments
 (0)