Skip to content

Commit

Permalink
Merge pull request #290 from WenjieDu/dev
Browse files Browse the repository at this point in the history
Updating load_dict_from_h5() and release v0.3
  • Loading branch information
WenjieDu authored Jan 1, 2024
2 parents a432038 + 2ece024 commit eb02440
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pypots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#
# Dev branch marker is: 'X.Y.dev' or 'X.Y.devN' where N is an integer.
# 'X.Y.dev0' is the canonical version of 'X.Y.dev'
__version__ = "0.2.1"
__version__ = "0.3"


from . import imputation, classification, clustering, forecasting, optim, data, utils
Expand Down
8 changes: 5 additions & 3 deletions pypots/data/saving/h5.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from typing import Optional

import h5py
import yaml

from ...utils.file import extract_parent_dir, create_dir_if_not_exist
from ...utils.logging import logger
Expand Down Expand Up @@ -93,6 +92,10 @@ def load_dict_from_h5(
) -> dict:
"""Load the data from the given h5 file and return as a Python dictionary.
Notes
-----
This implementation was inspired by https://github.com/SiggiGue/hdfdict/blob/master/hdfdict/hdfdict.py#L93
Parameters
----------
file_path : str,
Expand All @@ -117,13 +120,12 @@ def load_set(handle, datadict):
elif isinstance(item, h5py.Dataset):
value = item[()]
if "_type_" in item.attrs:
# in case that datetime type of data was saved as timestamps
if item.attrs["_type_"].astype(str) == "datetime":
if hasattr(value, "__iter__"):
value = [datetime.fromtimestamp(ts) for ts in value]
else:
value = datetime.fromtimestamp(value)
elif item.attrs["_type_"].astype(str) == "yaml":
value = yaml.safe_load(value.decode())
datadict[key] = value

return datadict
Expand Down

0 comments on commit eb02440

Please sign in to comment.