@@ -655,7 +655,11 @@ def open_groups_as_dict(
655655 open_kwargs : dict [str , Any ] | None = None ,
656656 ** kwargs ,
657657 ) -> dict [str , Dataset ]:
658- from xarray .backends .common import _iter_nc_groups
658+ from xarray .backends .common import (
659+ _is_glob_pattern ,
660+ _iter_nc_groups ,
661+ _resolve_group_and_filter ,
662+ )
659663 from xarray .core .treenode import NodePath
660664 from xarray .core .utils import close_on_error
661665
@@ -664,10 +668,12 @@ def open_groups_as_dict(
664668 emit_phony_dims_warning , phony_dims = _check_phony_dims (phony_dims )
665669
666670 filename_or_obj = _normalize_filename_or_obj (filename_or_obj )
671+
672+ effective_group = None if (group and _is_glob_pattern (group )) else group
667673 store = H5NetCDFStore .open (
668674 filename_or_obj ,
669675 format = format ,
670- group = group ,
676+ group = effective_group ,
671677 lock = lock ,
672678 invalid_netcdf = invalid_netcdf ,
673679 phony_dims = phony_dims ,
@@ -678,15 +684,17 @@ def open_groups_as_dict(
678684 open_kwargs = open_kwargs ,
679685 )
680686
681- # Check for a group and make it a parent if it exists
682- if group :
683- parent = NodePath ("/" ) / NodePath (group )
687+ if effective_group :
688+ parent = NodePath ("/" ) / NodePath (effective_group )
684689 else :
685690 parent = NodePath ("/" )
686691
687692 manager = store ._manager
693+ all_group_paths = list (_iter_nc_groups (store .ds , parent = parent ))
694+ _ , filtered_paths = _resolve_group_and_filter (group , all_group_paths )
695+
688696 groups_dict = {}
689- for path_group in _iter_nc_groups ( store . ds , parent = parent ) :
697+ for path_group in filtered_paths :
690698 group_store = H5NetCDFStore (manager , group = path_group , ** kwargs )
691699 store_entrypoint = StoreBackendEntrypoint ()
692700 with close_on_error (group_store ):
@@ -701,7 +709,7 @@ def open_groups_as_dict(
701709 decode_timedelta = decode_timedelta ,
702710 )
703711
704- if group :
712+ if effective_group :
705713 group_name = str (NodePath (path_group ).relative_to (parent ))
706714 else :
707715 group_name = str (NodePath (path_group ))
0 commit comments