Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Aug 30, 2024
1 parent fc16e1f commit bc0abda
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
12 changes: 6 additions & 6 deletions pyiron_base/interfaces/has_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,21 @@ def _split_children_dict(obj_dict: dict[str, Any]) -> dict[str, Any | dict[str,
plain.update(subs)
return plain


def _from_dict_children(obj_dict: dict) -> dict:
def load(inner_dict):
# object is a not a dict, so nothing to do
if not isinstance(inner_dict, dict):
return inner_dict
# if object is a dict but doesn't have type information, recurse through it to load any sub dicts that might
if not all(
k in inner_dict for k in ("NAME", "TYPE", "OBJECT", "DICT_VERSION")
):
if not all(k in inner_dict for k in ("NAME", "TYPE", "OBJECT", "DICT_VERSION")):
return {k: load(v) for k, v in inner_dict.items()}
# object has type info, so just load it
return create_from_dict(inner_dict)

return {k: load(v) for k, v in obj_dict.items()}


def _join_children_dict(children: dict[str, dict[str, Any]]) -> dict[str, Any]:
"""
Given a nested dictionary, flatten the first level.
Expand All @@ -104,11 +105,10 @@ def _join_children_dict(children: dict[str, dict[str, Any]]) -> dict[str, Any]:
writing to ProjectHDFio.write_dict_to_hdf
"""
return {
"/".join((k1, k2)): v2
for k1, v1 in children.items()
for k2, v2 in v1.items()
"/".join((k1, k2)): v2 for k1, v1 in children.items() for k2, v2 in v1.items()
}


def _to_dict_children(obj_dict: dict) -> dict:
"""
Call to_dict on any objects that support it.
Expand Down
7 changes: 6 additions & 1 deletion pyiron_base/storage/datacontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
import numpy as np
import pandas

from pyiron_base.interfaces.has_dict import HasDict, HasDictfromHDF, _to_dict_children, _from_dict_children
from pyiron_base.interfaces.has_dict import (
HasDict,
HasDictfromHDF,
_from_dict_children,
_to_dict_children,
)
from pyiron_base.interfaces.has_groups import HasGroups
from pyiron_base.interfaces.has_hdf import HasHDF
from pyiron_base.interfaces.lockable import Lockable, sentinel
Expand Down

0 comments on commit bc0abda

Please sign in to comment.