Skip to content

Commit b9c8f59

Browse files
authored
Merge branch 'master' into fancy-indexing
2 parents cf9051c + d1dc987 commit b9c8f59

File tree

12 files changed

+128
-20
lines changed

12 files changed

+128
-20
lines changed

.github/workflows/minimal.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ jobs:
2424
shell: "bash -l {0}"
2525
run: |
2626
conda activate minimal
27-
python -m pip install -e .
27+
python -m pip install .
2828
pytest -svx

.github/workflows/python-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
python -m pip install --upgrade pip
5858
python -m pip install -U pip setuptools wheel codecov line_profiler
5959
python -m pip install -rrequirements_dev_minimal.txt numpy${{ matrix.numpy_version}} -rrequirements_dev_optional.txt pymongo redis
60-
python -m pip install -e .
60+
python -m pip install .
6161
python -m pip freeze
6262
- name: Tests
6363
shell: "bash -l {0}"

.github/workflows/windows-testing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
python -m pip install --upgrade pip
4040
python -m pip install -U pip setuptools wheel
4141
python -m pip install -r requirements_dev_numpy.txt -r requirements_dev_minimal.txt -r requirements_dev_optional.txt
42-
python -m pip install -e .
42+
python -m pip install .
4343
python -m pip freeze
4444
npm install -g azurite
4545
- name: Run Tests

docs/release.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ Enhancements
1212
* array indexing with [] (getitem and setitem) now supports fancy indexing.
1313
By :user:`Juan Nunez-Iglesias <jni>`; :issue:`725`.
1414

15+
.. _release_2.10.2:
16+
17+
2.10.2
18+
------
19+
20+
Bug fixes
21+
~~~~~~~~~
22+
23+
* Fix NestedDirectoryStore datasets without dimension_separator metadata.
24+
By :user:`Josh Moore <joshmoore>`; :issue:`850`.
25+
1526
.. _release_2.10.1:
1627

1728
2.10.1

fixture/flat/.zarray

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"id": "blosc",
1111
"shuffle": 1
1212
},
13+
"dimension_separator": ".",
1314
"dtype": "<i8",
1415
"fill_value": 0,
1516
"filters": null,
@@ -19,4 +20,4 @@
1920
2
2021
],
2122
"zarr_format": 2
22-
}
23+
}

fixture/flat_legacy/.zarray

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"chunks": [
3+
2,
4+
2
5+
],
6+
"compressor": {
7+
"blocksize": 0,
8+
"clevel": 5,
9+
"cname": "lz4",
10+
"id": "blosc",
11+
"shuffle": 1
12+
},
13+
"dtype": "<i8",
14+
"fill_value": 0,
15+
"filters": null,
16+
"order": "C",
17+
"shape": [
18+
2,
19+
2
20+
],
21+
"zarr_format": 2
22+
}

fixture/flat_legacy/0.0

48 Bytes
Binary file not shown.

fixture/nested_legacy/.zarray

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"chunks": [
3+
2,
4+
2
5+
],
6+
"compressor": {
7+
"blocksize": 0,
8+
"clevel": 5,
9+
"cname": "lz4",
10+
"id": "blosc",
11+
"shuffle": 1
12+
},
13+
"dtype": "<i8",
14+
"fill_value": 0,
15+
"filters": null,
16+
"order": "C",
17+
"shape": [
18+
2,
19+
2
20+
],
21+
"zarr_format": 2
22+
}

fixture/nested_legacy/0/0

48 Bytes
Binary file not shown.

zarr/core.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,18 @@ def _load_metadata_nosync(self):
196196
self._dtype = meta['dtype']
197197
self._fill_value = meta['fill_value']
198198
self._order = meta['order']
199-
self._dimension_separator = meta.get('dimension_separator', '.')
199+
200+
dimension_separator = meta.get('dimension_separator', None)
201+
if dimension_separator is None:
202+
try:
203+
dimension_separator = self._store._dimension_separator
204+
except (AttributeError, KeyError):
205+
pass
206+
207+
# Fallback for any stores which do not choose a default
208+
if dimension_separator is None:
209+
dimension_separator = "."
210+
self._dimension_separator = dimension_separator
200211

201212
# setup compressor
202213
config = meta['compressor']

zarr/meta.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def decode_array_metadata(s: Union[MappingType, str]) -> MappingType[str, Any]:
4747
else:
4848
object_codec = None
4949

50+
dimension_separator = meta.get('dimension_separator', None)
5051
fill_value = decode_fill_value(meta['fill_value'], dtype, object_codec)
5152
meta = dict(
5253
zarr_format=meta['zarr_format'],
@@ -57,8 +58,9 @@ def decode_array_metadata(s: Union[MappingType, str]) -> MappingType[str, Any]:
5758
fill_value=fill_value,
5859
order=meta['order'],
5960
filters=meta['filters'],
60-
dimension_separator=meta.get('dimension_separator', '.'),
6161
)
62+
if dimension_separator:
63+
meta['dimension_separator'] = dimension_separator
6264

6365
except Exception as e:
6466
raise MetadataError('error decoding metadata: %s' % e)

zarr/tests/test_dim_separator.py

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
needs_fsspec = pytest.mark.skipif(not have_fsspec, reason="needs fsspec")
1313

1414

15-
@pytest.fixture(params=("static_nested",
16-
"static_flat",
15+
@pytest.fixture(params=("static_flat",
16+
"static_flat_legacy",
17+
"static_nested",
18+
"static_nested_legacy",
1719
"directory_nested",
1820
"directory_flat",
1921
"directory_default",
@@ -35,14 +37,16 @@ def dataset(tmpdir, request):
3537

3638
if which.startswith("static"):
3739
project_root = pathlib.Path(zarr.__file__).resolve().parent.parent
38-
if which.endswith("nested"):
39-
static = project_root / "fixture/nested"
40-
generator = NestedDirectoryStore
41-
else:
42-
static = project_root / "fixture/flat"
43-
generator = DirectoryStore
40+
suffix = which[len("static_"):]
41+
static = project_root / "fixture" / suffix
4442

4543
if not static.exists(): # pragma: no cover
44+
45+
if "nested" in which:
46+
generator = NestedDirectoryStore
47+
else:
48+
generator = DirectoryStore
49+
4650
# store the data - should be one-time operation
4751
s = generator(str(static))
4852
a = zarr.open(store=s, mode="w", shape=(2, 2), dtype="<i8")
@@ -69,22 +73,57 @@ def dataset(tmpdir, request):
6973
return str(loc)
7074

7175

72-
def verify(array):
73-
assert_array_equal(array[:], [[1, 2], [3, 4]])
76+
def verify(array, expect_failure=False):
77+
try:
78+
assert_array_equal(array[:], [[1, 2], [3, 4]])
79+
except AssertionError:
80+
if expect_failure:
81+
pytest.xfail()
82+
else:
83+
raise # pragma: no cover
7484

7585

7686
def test_open(dataset):
77-
verify(zarr.open(dataset, "r"))
87+
"""
88+
Use zarr.open to open the dataset fixture. Legacy nested datatsets
89+
without the dimension_separator metadata are not expected to be
90+
openable.
91+
"""
92+
failure = "nested_legacy" in dataset
93+
verify(zarr.open(dataset, "r"), failure)
7894

7995

8096
@needs_fsspec
8197
def test_fsstore(dataset):
82-
verify(Array(store=FSStore(dataset)))
98+
"""
99+
Use FSStore to open the dataset fixture. Legacy nested datatsets
100+
without the dimension_separator metadata are not expected to be
101+
openable.
102+
"""
103+
failure = "nested_legacy" in dataset
104+
verify(Array(store=FSStore(dataset)), failure)
83105

84106

85107
def test_directory(dataset):
86-
verify(zarr.Array(store=DirectoryStore(dataset)))
108+
"""
109+
Use DirectoryStore to open the dataset fixture. Legacy nested datatsets
110+
without the dimension_separator metadata are not expected to be
111+
openable.
112+
"""
113+
failure = "nested_legacy" in dataset
114+
verify(zarr.Array(store=DirectoryStore(dataset)), failure)
87115

88116

89117
def test_nested(dataset):
90-
verify(Array(store=NestedDirectoryStore(dataset)))
118+
"""
119+
Use NestedDirectoryStore to open the dataset fixture. This is the only
120+
method that is expected to successfully open legacy nested datasets
121+
without the dimension_separator metadata. However, for none-Nested
122+
datasets without any metadata, NestedDirectoryStore will fail.
123+
"""
124+
failure = (
125+
"flat_legacy" in dataset or
126+
"directory_default" in dataset or
127+
"fs_default" in dataset
128+
)
129+
verify(Array(store=NestedDirectoryStore(dataset)), failure)

0 commit comments

Comments
 (0)