Skip to content

Commit

Permalink
passing missing parameters to ZarrStore.open_store when opening a dat…
Browse files Browse the repository at this point in the history
…atree (#9377)

* passing missing parameters to ZarrStore.open_store when opening a datatree

* Fix issue with passing parameters to ZarrStore.open_store when opening
  datatree in zarr format

* whats-new formatting

---------

Co-authored-by: Justus Magin <[email protected]>
  • Loading branch information
aladinor and keewis authored Aug 20, 2024
1 parent ca2e9d6 commit 40291ad
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
3 changes: 3 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ Bug fixes
date "0001-01-01". (:issue:`9108`, :pull:`9116`) By `Spencer Clark
<https://github.com/spencerkclark>`_ and `Deepak Cherian
<https://github.com/dcherian>`_.
- Fix issue with passing parameters to ZarrStore.open_store when opening
datatree in zarr format (:issue:`9376`, :pull:`9377`).
By `Alfonso Ladino <https://github.com/aladinor>`_

Documentation
~~~~~~~~~~~~~
Expand Down
26 changes: 24 additions & 2 deletions xarray/backends/zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1225,15 +1225,37 @@ def open_datatree(
filename_or_obj = _normalize_path(filename_or_obj)
if group:
parent = NodePath("/") / NodePath(group)
stores = ZarrStore.open_store(filename_or_obj, group=parent)
stores = ZarrStore.open_store(
filename_or_obj,
group=parent,
mode=mode,
synchronizer=synchronizer,
consolidated=consolidated,
consolidate_on_close=False,
chunk_store=chunk_store,
storage_options=storage_options,
stacklevel=stacklevel + 1,
zarr_version=zarr_version,
)
if not stores:
ds = open_dataset(
filename_or_obj, group=parent, engine="zarr", **kwargs
)
return DataTree.from_dict({str(parent): ds})
else:
parent = NodePath("/")
stores = ZarrStore.open_store(filename_or_obj, group=parent)
stores = ZarrStore.open_store(
filename_or_obj,
group=parent,
mode=mode,
synchronizer=synchronizer,
consolidated=consolidated,
consolidate_on_close=False,
chunk_store=chunk_store,
storage_options=storage_options,
stacklevel=stacklevel + 1,
zarr_version=zarr_version,
)
ds = open_dataset(filename_or_obj, group=parent, engine="zarr", **kwargs)
tree_root = DataTree.from_dict({str(parent): ds})
for path_group, store in stores.items():
Expand Down

0 comments on commit 40291ad

Please sign in to comment.