Skip to content

Commit be3d657

Browse files
authored
Ignore None dim_separators in save_array (fix #831) (#832)
* Ignore None dim_separators in save_array (fix #831) If a store does not have a `dimension_separator` set, then requesting a non-`None` value should not be an error. * Fix flake8
1 parent 7ec8c64 commit be3d657

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

zarr/creation.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,12 @@ def create(shape, chunks=True, dtype=None, compressor='default',
126126
if dimension_separator is None:
127127
dimension_separator = getattr(store, "_dimension_separator", None)
128128
else:
129-
if getattr(store, "_dimension_separator", None) != dimension_separator:
129+
store_separator = getattr(store, "_dimension_separator", None)
130+
if store_separator not in (None, dimension_separator):
130131
raise ValueError(
131132
f"Specified dimension_separtor: {dimension_separator}"
132133
f"conflicts with store's separator: "
133-
f"{store._dimension_separator}")
134+
f"{store_separator}")
134135
dimension_separator = normalize_dimension_separator(dimension_separator)
135136

136137
# initialize array metadata

zarr/tests/test_convenience.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
open_consolidated,
1919
save,
2020
save_group,
21+
save_array,
2122
copy_all,
2223
)
2324
from zarr.core import Array
@@ -225,6 +226,17 @@ def test_consolidated_with_chunk_store():
225226
chunk_store=chunk_store)
226227

227228

229+
@pytest.mark.parametrize("options", (
230+
{"dimension_separator": "/"},
231+
{"dimension_separator": "."},
232+
{"dimension_separator": None},
233+
))
234+
def test_save_array_separator(tmpdir, options):
235+
data = np.arange(6).reshape((3, 2))
236+
url = tmpdir.join("test.zarr")
237+
save_array(url, data, **options)
238+
239+
228240
class TestCopyStore(unittest.TestCase):
229241

230242
def setUp(self):

0 commit comments

Comments
 (0)