Skip to content

Commit

Permalink
Merge pull request #1260 from pyiron/HasHDF_type_dict
Browse files Browse the repository at this point in the history
HasHDF: Add _store_type_to_dict()
  • Loading branch information
jan-janssen authored Dec 20, 2023
2 parents 2964d4d + 5c91969 commit 46b74c3
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions pyiron_base/interfaces/has_hdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,16 @@ def from_hdf_args(cls, hdf: ProjectHDFio) -> dict:
"""
return {}

def _store_type_to_hdf(self, hdf: ProjectHDFio):
hdf["NAME"] = self.__class__.__name__
hdf["TYPE"] = str(type(self))
hdf["OBJECT"] = hdf["NAME"] # unused alias
def _store_type_to_dict(self):
type_dict = {
"NAME": self.__class__.__name__,
"TYPE": str(type(self)),
"OBJECT": self.__class__.__name__, # unused alias
"HDF_VERSION": self.__hdf_version__,
}
if hasattr(self, "__version__"):
hdf["VERSION"] = self.__version__
hdf["HDF_VERSION"] = self.__hdf_version__
type_dict["VERSION"] = self.__version__
return type_dict

def from_hdf(self, hdf: ProjectHDFio, group_name: str = None):
"""
Expand Down Expand Up @@ -217,7 +220,8 @@ def to_hdf(self, hdf: ProjectHDFio, group_name: str = None):
):
raise ValueError("HDF group must be empty when group_name is not set.")
self._to_hdf(hdf)
self._store_type_to_hdf(hdf)
for k, v in self._store_type_to_dict().items():
hdf[k] = v

def rewrite_hdf(self, hdf: ProjectHDFio, group_name: str = None):
"""
Expand Down

0 comments on commit 46b74c3

Please sign in to comment.