Skip to content

Commit a765bad

Browse files
boazmoharjoshmoore
authored andcommitted
Fix: N5 keywords now emit UserWarning instead of raising a ValueError (#860)
* Changed n5 keywords to print a warning Changed N5 and N5FS Added test fixture to capture stdout Updated test making sure a warning is printed * flake8 * Change to UserWarning
1 parent d1dc987 commit a765bad

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

zarr/n5.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def __setitem__(self, key, value):
128128

129129
for k in n5_keywords:
130130
if k in zarr_attrs.keys():
131-
raise ValueError("Can not set attribute %s, this is a reserved N5 keyword" % k)
131+
warnings.warn("attribute %s is a reserved N5 keyword" % k, UserWarning)
132132

133133
# replace previous user attributes
134134
for k in list(n5_attrs.keys()):
@@ -424,9 +424,7 @@ def __setitem__(self, key, value):
424424

425425
for k in n5_keywords:
426426
if k in zarr_attrs.keys():
427-
raise ValueError(
428-
"Can not set attribute %s, this is a reserved N5 keyword" % k
429-
)
427+
warnings.warn("attribute %s is a reserved N5 keyword" % k, UserWarning)
430428

431429
# replace previous user attributes
432430
for k in list(n5_attrs.keys()):

zarr/tests/test_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1951,7 +1951,7 @@ def test_structured_array_contain_object(self):
19511951
def test_attrs_n5_keywords(self):
19521952
z = self.create_array(shape=(1050,), chunks=100, dtype='i4')
19531953
for k in n5_keywords:
1954-
with pytest.raises(ValueError):
1954+
with pytest.warns(UserWarning):
19551955
z.attrs[k] = ""
19561956

19571957
def test_compressors(self):

0 commit comments

Comments
 (0)