Skip to content

Commit

Permalink
revert list groups
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-janssen committed Jun 7, 2024
1 parent 535a4ea commit 7fd75fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
15 changes: 7 additions & 8 deletions pyiron_base/storage/hdfio.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
"""

import numbers
from h5io_browser import Pointer, list_hdf, read_nested_dict_from_hdf
from h5io_browser import Pointer, read_nested_dict_from_hdf
from h5io_browser.base import (
_get_hdf_content,
_open_hdf,
_is_ragged_in_1st_dim_only,
_read_hdf,
Expand Down Expand Up @@ -49,20 +50,20 @@ def _extract_module_class_name(type_field: str) -> Tuple[str, str]:
return fully_qualified_path.rsplit(".", maxsplit=1)


def _list_groups_and_nodes(file_name, h5_path):
def _list_groups_and_nodes(hdf, h5_path):
"""
Get the list of groups and list of nodes from an open HDF5 file
Args:
file_name (str): file name of the HDF5 file
hdf (h5py.File): file handle of an open HDF5 file
h5_path (str): path inside the HDF5 file
Returns:
list, list: list of groups and list of nodes
"""
if h5_path[0] != "/":
h5_path = "/" + h5_path
nodes, groups = list_hdf(file_name=file_name, h5_path=h5_path, recursive=False)
nodes, groups = _get_hdf_content(hdf=hdf[h5_path], recursive=False)
return (
[group[len(h5_path) + 1 :] for group in groups],
[node[len(h5_path) + 1 :] for node in nodes],
Expand Down Expand Up @@ -534,10 +535,8 @@ def _list_all(self):
dict: {'groups': [list of groups], 'nodes': [list of nodes]}
"""
if self.file_exists:
groups, nodes = _list_groups_and_nodes(
file_name=self.file_name,
h5_path=self.h5_path,
)
with _open_hdf(self.file_name) as hdf:
groups, nodes = _list_groups_and_nodes(hdf=hdf, h5_path=self.h5_path)
iopy_nodes = self._filter_io_objects(set(groups))
return {
"groups": sorted(list(set(groups) - iopy_nodes)),
Expand Down
11 changes: 4 additions & 7 deletions tests/storage/test_helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@ def test_hdf5_structure(self):
)

def test_list_groups(self):
groups, nodes = _list_groups_and_nodes(
file_name=self.file_name, h5_path="data_hierarchical"
)
with h5py.File(self.file_name, "r") as f:
groups, nodes = _list_groups_and_nodes(hdf=f, h5_path="data_hierarchical")
self.assertEqual(list(sorted(groups)), ["key_a", "key_c"])
self.assertEqual(nodes, ["key_b"])

Expand Down Expand Up @@ -148,9 +147,7 @@ def test_hdf5_structure(self):
)

def test_list_groups(self):
groups, nodes = _list_groups_and_nodes(
file_name=self.file_name,
h5_path="data_hierarchical",
)
with h5py.File(self.file_name, "r") as f:
groups, nodes = _list_groups_and_nodes(hdf=f, h5_path="data_hierarchical")
self.assertEqual(groups, [])
self.assertEqual(list(sorted(nodes)), ["a", "b", "c"])

0 comments on commit 7fd75fa

Please sign in to comment.