Skip to content

Commit a2d7a13

Browse files
aaronspringclaude
andcommitted
Open existing groups when writing a DataTree with region/append_dim
virtual_datatree_to_icechunk unconditionally created each node's group with Group.from_store, so forwarding region or append_dim (which require the group and its arrays to already exist) always failed with ContainsGroupError. Mirror the branch virtual_dataset_to_icechunk already had: open the existing group for region/append_dim, create it otherwise. Removes the now-passing xfail on test_write_datatree_region, whose stated reason (an xarray region limitation) was a misdiagnosis of this ContainsGroupError. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent e1ebb4b commit a2d7a13

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

docs/about/releases.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
### Bug fixes
1111

12+
- Writing a virtual `DataTree` with `region` or `append_dim` (forwarded to each node) previously always failed with `ContainsGroupError`, because every group was unconditionally created; the existing groups are now opened instead.
13+
By [Aaron Spring](https://github.com/aaronspring).
14+
1215
### Documentation
1316

1417
### Internal changes

virtualizarr/tests/test_writers/test_icechunk.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -996,9 +996,6 @@ def test_write_region_unaligned_chunks_raises(
996996
write_session.store, region={"y": "auto", "x": "auto"}
997997
)
998998

999-
@pytest.mark.xfail(
1000-
reason="This doesn't work in xarray either, maybe not even intended?",
1001-
)
1002999
def test_write_datatree_region(
10031000
self,
10041001
icechunk_repo: "Repository",

virtualizarr/writers/icechunk.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,12 @@ def get_store_path(subtree, vdt) -> StorePath:
238238

239239
# TODO this serial loop could be slow writing lots of groups to high-latency store, see https://github.com/pydata/xarray/issues/9455
240240
for store_path, vds in paths_and_virtual_datasets:
241-
group = Group.from_store(store=store_path, zarr_format=3)
241+
if kwargs.get("append_dim") or kwargs.get("region"):
242+
# both require the group (and arrays) to already exist
243+
group = Group.open(store=store_path, zarr_format=3)
244+
else:
245+
# create the group if it doesn't already exist
246+
group = Group.from_store(store=store_path, zarr_format=3)
242247

243248
write_virtual_dataset_to_icechunk_group(
244249
vds=vds,

0 commit comments

Comments
 (0)