Skip to content

Commit

Permalink
Merge pull request #1606 from pyiron/dependabot/pip/h5io-browser-0.0.18
Browse files Browse the repository at this point in the history
Bump h5io-browser from 0.0.17 to 0.0.18
  • Loading branch information
jan-janssen authored Aug 19, 2024
2 parents f4d79ef + 67c2a59 commit 8b3ee9e
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .ci_support/environment-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies:
- conda_subprocess =0.0.4
- cloudpickle =3.0.0
- gitpython =3.1.43
- h5io_browser =0.0.17
- h5io_browser =0.0.18
- h5py =3.11.0
- jinja2 =3.1.4
- monty =2024.7.30
Expand Down
2 changes: 1 addition & 1 deletion .ci_support/environment-mini.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ channels:
- conda-forge
dependencies:
- cloudpickle =3.0.0
- h5io_browser =0.0.17
- h5io_browser =0.0.18
- h5py =3.11.0
- monty =2024.7.30
- numpy =2.0.1
Expand Down
2 changes: 1 addition & 1 deletion .ci_support/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dependencies:
- conda_subprocess =0.0.4
- cloudpickle =3.0.0
- gitpython =3.1.43
- h5io_browser =0.0.17
- h5io_browser =0.0.18
- h5py =3.11.0
- jinja2 =3.1.4
- monty =2024.7.30
Expand Down
2 changes: 1 addition & 1 deletion binder/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dependencies:
- conda_subprocess =0.0.4
- cloudpickle =3.0.0
- gitpython =3.1.43
- h5io_browser =0.0.17
- h5io_browser =0.0.18
- h5py =3.11.0
- jinja2 =3.1.4
- monty =2024.7.30
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ classifiers = [
dependencies = [
"cloudpickle==3.0.0",
"executorlib==0.0.1",
"h5io_browser==0.0.17",
"h5io_browser==0.0.18",
"h5py==3.11.0",
"numpy==2.0.1",
"monty==2024.7.30",
Expand Down
113 changes: 59 additions & 54 deletions tests/unit/storage/test_helper_functions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import posixpath
import numpy as np
import h5py
from unittest import TestCase
from pyiron_base.storage.hdfio import _list_groups_and_nodes
Expand All @@ -23,58 +24,65 @@ class TestWriteHdfIO(TestCase):
def setUp(self):
self.file_name = "test_write_hdf5.h5"
self.h5_path = "data_hierarchical"
self.data_hierarchical = {"a": [1, 2], "b": 3, "c": {"d": 4, "e": {"f": 5}}}
_write_hdf(
hdf_filehandle=self.file_name,
data=self.data_hierarchical,
h5_path=self.h5_path,
self.data_hierarchical = {
"a": np.array([1, 2]),
"b": 3,
"c": {"d": np.array([4, 5]), "e": np.array([6, 7])},
}
write_dict_to_hdf(
file_name=self.file_name,
data_dict={
posixpath.join(self.h5_path, "a"): self.data_hierarchical["a"],
posixpath.join(self.h5_path, "b"): self.data_hierarchical["b"],
posixpath.join(self.h5_path, "c", "d"): self.data_hierarchical["c"][
"d"
],
posixpath.join(self.h5_path, "c", "e"): self.data_hierarchical["c"][
"e"
],
},
)

def tearDown(self):
os.remove(self.file_name)

def test_read_hierarchical(self):
self.assertEqual(
self.data_hierarchical,
_read_hdf(hdf_filehandle=self.file_name, h5_path=self.h5_path),
)

def test_read_dict_hierarchical(self):
self.assertEqual(
{"key_b": 3},
read_nested_dict_from_hdf(file_name=self.file_name, h5_path=self.h5_path),
output = read_nested_dict_from_hdf(
file_name=self.file_name, h5_path=self.h5_path
)
self.assertEqual(
{"key_a": {"idx_0": 1, "idx_1": 2}, "key_b": 3, "key_c": {"key_d": 4}},
read_nested_dict_from_hdf(
file_name=self.file_name,
h5_path=self.h5_path,
group_paths=["key_a", "key_c"],
),
self.assertTrue(
np.all(np.equal(output["a"], np.array([1, 2]))),
)
self.assertEqual(
{
"key_a": {"idx_0": 1, "idx_1": 2},
"key_b": 3,
"key_c": {"key_d": 4, "key_e": {"key_f": 5}},
},
read_nested_dict_from_hdf(
file_name=self.file_name,
h5_path=self.h5_path,
group_paths=["key_a", "key_c", "key_c/key_e"],
),
self.assertEqual(output["b"], 3)
output = read_nested_dict_from_hdf(
file_name=self.file_name,
h5_path=self.h5_path,
group_paths=["c"],
)
self.assertEqual(
{
"key_a": {"idx_0": 1, "idx_1": 2},
"key_b": 3,
"key_c": {"key_d": 4, "key_e": {"key_f": 5}},
},
read_nested_dict_from_hdf(
file_name=self.file_name,
h5_path=self.h5_path,
recursive=True,
),
self.assertTrue(
np.all(np.equal(output["a"], np.array([1, 2]))),
)
self.assertEqual(output["b"], 3)
self.assertTrue(
np.all(np.equal(output["c"]["d"], np.array([4, 5]))),
)
self.assertTrue(
np.all(np.equal(output["c"]["e"], np.array([6, 7]))),
)
output = read_nested_dict_from_hdf(
file_name=self.file_name,
h5_path=self.h5_path,
recursive=True,
)
self.assertTrue(
np.all(np.equal(output["a"], np.array([1, 2]))),
)
self.assertEqual(output["b"], 3)
self.assertTrue(
np.all(np.equal(output["c"]["d"], np.array([4, 5]))),
)
self.assertTrue(
np.all(np.equal(output["c"]["e"], np.array([6, 7]))),
)

def test_write_overwrite_error(self):
Expand All @@ -90,23 +98,20 @@ def test_hdf5_structure(self):
self.assertEqual(
get_hdf5_raw_content(file_name=self.file_name),
[
{"data_hierarchical": {"TITLE": "dict"}},
{"data_hierarchical/key_a": {"TITLE": "list"}},
{"data_hierarchical/key_a/idx_0": {"TITLE": "int"}},
{"data_hierarchical/key_a/idx_1": {"TITLE": "int"}},
{"data_hierarchical/key_b": {"TITLE": "int"}},
{"data_hierarchical/key_c": {"TITLE": "dict"}},
{"data_hierarchical/key_c/key_d": {"TITLE": "int"}},
{"data_hierarchical/key_c/key_e": {"TITLE": "dict"}},
{"data_hierarchical/key_c/key_e/key_f": {"TITLE": "int"}},
{"data_hierarchical": {}},
{"data_hierarchical/a": {"TITLE": "ndarray"}},
{"data_hierarchical/b": {"TITLE": "int"}},
{"data_hierarchical/c": {}},
{"data_hierarchical/c/d": {"TITLE": "ndarray"}},
{"data_hierarchical/c/e": {"TITLE": "ndarray"}},
],
)

def test_list_groups(self):
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"])
self.assertEqual(list(sorted(groups)), ["c"])
self.assertEqual(list(sorted(nodes)), ["a", "b"])


class TestWriteDictHdfIO(TestCase):
Expand Down

0 comments on commit 8b3ee9e

Please sign in to comment.