Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/blosc2/schunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -1874,12 +1874,9 @@ def _open_special_store(urlpath, mode, offset, *, deserialize=DeserializeMode.SA
from blosc2.remote_store import RemoteStore

return RemoteStore._open_artifact(urlpath, mode=mode, **kwargs)
if "b2embed" in schunk_meta:
if offset != 0:
raise ValueError("Offset must be 0 for EmbedStore")
from blosc2.embed_store import EmbedStore

return EmbedStore(urlpath, mode=mode, deserialize=deserialize, **kwargs)
# No "b2embed" check: the embed.b2e of a .b2d/.b2z written by python-blosc2
# <= 4.0.0 carries that marker too (b2dict and b2tree came in 4.1.0), so it
# does not tell the store type. Those stores and .b2e files go by extension.
if "b2dict" in schunk_meta:
if offset != 0:
raise ValueError("Offset must be 0 for DictStore")
Expand Down
Binary file added tests/data/legacy_store_v4.0.0/dictstore.b2z
Binary file not shown.
25 changes: 25 additions & 0 deletions tests/test_dict_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,31 @@ def test_extensionless_store_is_a_directory(tmp_path):
assert np.array_equal(opened["/node1"][:], np.arange(4))


@pytest.mark.parametrize(("suffix", "store_type"), [("b2z", blosc2.TreeStore), ("b2d", blosc2.DictStore)])
def test_open_store_written_by_4_0_0(tmp_path, suffix, store_type):
# A DictStore written by 4.0.0 (no b2dict marker yet) with an embedded leaf,
# an external one and a nested key; it opens by its extension, as in 4.0.0
fixture = pathlib.Path(__file__).parent / "data" / "legacy_store_v4.0.0" / "dictstore.b2z"
path = tmp_path / f"legacy.{suffix}"
if suffix == "b2z":
shutil.copy(fixture, path)
else: # the same members, unzipped
with zipfile.ZipFile(fixture) as zf:
zf.extractall(path)
expected = {
"/embedded": np.arange(12, dtype="<i4").reshape(3, 4),
"/external": np.arange(20_000, dtype="<i4"),
"/group/leaf": np.linspace(0, 1, 5, dtype="<f4"),
}

# The default mode, then "a" (a .b2z is written back on close), then again
for kwargs in ({}, {"mode": "a"}, {"mode": "r"}):
with blosc2.open(str(path), **kwargs) as store:
assert type(store) is store_type
for key, value in expected.items():
np.testing.assert_array_equal(store[key][:], value)


def test_to_b2z_from_readonly_b2d():
b2d_path = "test_to_b2z_from_readonly.b2d"
b2z_path = "test_to_b2z_from_readonly.b2z"
Expand Down
Loading