Skip to content

Commit 1769f8e

Browse files
committed
raise ValueError if create_dataset's dimension_separator is inconsistent
1 parent 2d0acfb commit 1769f8e

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

zarr/creation.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ def create(shape, chunks=True, dtype=None, compressor='default',
124124
# optional array metadata
125125
if dimension_separator is None:
126126
dimension_separator = getattr(store, "_dimension_separator", None)
127+
else:
128+
if getattr(store, "_dimension_separator", None) != dimension_separator:
129+
raise ValueError(
130+
f"Specified dimension_separtor: {dimension_separator}"
131+
f"conflicts with store's separator: "
132+
f"{store._dimension_separator}")
127133
dimension_separator = normalize_dimension_separator(dimension_separator)
128134

129135
# initialize array metadata

zarr/tests/test_hierarchy.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,18 @@ def create_store():
10031003
store = FSStore(path, key_separator='/', auto_mkdir=True)
10041004
return store, None
10051005

1006+
def test_inconsistent_dimension_separator(self):
1007+
data = np.arange(1000).reshape(10, 10, 10)
1008+
name = 'raw'
1009+
1010+
store, _ = self.create_store()
1011+
f = open_group(store, mode='w')
1012+
1013+
# cannot specify dimension_separator that conflicts with the store
1014+
with pytest.raises(ValueError):
1015+
f.create_dataset(name, data=data, chunks=(5, 5, 5),
1016+
compressor=None, dimension_separator='.')
1017+
10061018

10071019
class TestGroupWithZipStore(TestGroup):
10081020

0 commit comments

Comments
 (0)