Skip to content

Commit b5a66d7

Browse files
authored
Fix icechunk tests with Zarr 3.0.9 (#653)
1 parent f1c3d69 commit b5a66d7

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

virtualizarr/tests/test_integration.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,24 @@ def roundtrip_as_in_memory_icechunk(
141141

142142
# write those references to an icechunk store
143143
vdata.virtualize.to_icechunk(session.store, **(virtualize_kwargs or {}))
144+
session.commit("Test")
145+
146+
read_only_session = repo.readonly_session("main")
144147

145148
if isinstance(vdata, xr.DataTree):
146149
# read the dataset from icechunk
147150
return xr.open_datatree(
148-
session.store, # type: ignore
151+
read_only_session.store, # type: ignore
149152
engine="zarr",
150153
zarr_format=3,
151154
consolidated=False,
152155
**kwargs,
153156
)
154157

155158
# read the dataset from icechunk
156-
return xr.open_zarr(session.store, zarr_format=3, consolidated=False, **kwargs)
159+
return xr.open_zarr(
160+
read_only_session.store, zarr_format=3, consolidated=False, **kwargs
161+
)
157162

158163

159164
@requires_zarr_python

virtualizarr/tests/test_writers/test_icechunk.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ def test_write_new_virtual_variable(
103103

104104

105105
def test_set_single_virtual_ref_without_encoding(
106-
icechunk_filestore: "IcechunkStore", simple_netcdf4: Path, array_v3_metadata
106+
icechunk_filestore: "IcechunkStore",
107+
icechunk_repo: "Repository",
108+
simple_netcdf4: Path,
109+
array_v3_metadata,
107110
):
108111
# TODO kerchunk doesn't work with zarr-python v3 yet so we can't use open_virtual_dataset and icechunk together!
109112
# vds = open_virtual_dataset(netcdf4_file, indexes={})
@@ -128,15 +131,20 @@ def test_set_single_virtual_ref_without_encoding(
128131

129132
vds.virtualize.to_icechunk(icechunk_filestore)
130133

131-
root_group = zarr.group(store=icechunk_filestore)
134+
icechunk_filestore.session.commit("test")
135+
136+
icechunk_readonly_session = icechunk_repo.readonly_session("main")
137+
root_group = zarr.open_group(store=icechunk_readonly_session.store, mode="r")
132138
array = root_group["foo"]
133139

134140
# check chunk references
135141
# TODO we can't explicitly check that the path/offset/length is correct because
136142
# icechunk doesn't yet expose any get_virtual_refs method
137143

138144
with (
139-
xr.open_zarr(store=icechunk_filestore, zarr_format=3, consolidated=False) as ds,
145+
xr.open_zarr(
146+
store=icechunk_readonly_session.store, zarr_format=3, consolidated=False
147+
) as ds,
140148
xr.open_dataset(simple_netcdf4) as expected_ds,
141149
):
142150
expected_array = expected_ds["foo"].to_numpy()
@@ -149,7 +157,10 @@ def test_set_single_virtual_ref_without_encoding(
149157

150158

151159
def test_set_single_virtual_ref_with_encoding(
152-
icechunk_filestore: "IcechunkStore", netcdf4_file: Path, array_v3_metadata
160+
icechunk_filestore: "IcechunkStore",
161+
icechunk_repo: "Repository",
162+
netcdf4_file: Path,
163+
array_v3_metadata,
153164
):
154165
with xr.open_dataset(netcdf4_file) as ds:
155166
# We drop the coordinates because we don't have them in the zarr test case
@@ -179,7 +190,10 @@ def test_set_single_virtual_ref_with_encoding(
179190

180191
vds.virtualize.to_icechunk(icechunk_filestore)
181192

182-
root_group = zarr.group(store=icechunk_filestore)
193+
icechunk_filestore.session.commit("test")
194+
195+
icechunk_readonly_session = icechunk_repo.readonly_session("main")
196+
root_group = zarr.open_group(store=icechunk_readonly_session.store, mode="r")
183197
air_array = root_group["air"]
184198
assert isinstance(air_array, zarr.Array)
185199

@@ -195,7 +209,7 @@ def test_set_single_virtual_ref_with_encoding(
195209

196210
# check the data
197211
with xr.open_zarr(
198-
store=icechunk_filestore, zarr_format=3, consolidated=False
212+
store=icechunk_readonly_session.store, zarr_format=3, consolidated=False
199213
) as actual_ds:
200214
# Because we encode attributes, attributes may differ, for example
201215
# actual_range for expected_ds.air is array([185.16, 322.1 ], dtype=float32)
@@ -429,7 +443,9 @@ def test_generate_chunk_key_append_axis_out_of_bounds():
429443
generate_chunk_key(index, append_axis=append_axis, existing_num_chunks=1)
430444

431445

432-
def test_roundtrip_coords(manifest_array, icechunk_filestore: "IcechunkStore"):
446+
def test_roundtrip_coords(
447+
manifest_array, icechunk_filestore: "IcechunkStore", icechunk_repo: "Repository"
448+
):
433449
# regression test for GH issue #574
434450

435451
vds = xr.Dataset(
@@ -450,8 +466,10 @@ def test_roundtrip_coords(manifest_array, icechunk_filestore: "IcechunkStore"):
450466
},
451467
)
452468
vds.virtualize.to_icechunk(icechunk_filestore)
469+
icechunk_filestore.session.commit("test")
453470

454-
roundtrip = xr.open_zarr(icechunk_filestore, consolidated=False)
471+
icechunk_readonly_session = icechunk_repo.readonly_session("main")
472+
roundtrip = xr.open_zarr(icechunk_readonly_session.store, consolidated=False)
455473
assert set(roundtrip.coords) == set(vds.coords)
456474

457475

0 commit comments

Comments
 (0)