Skip to content

Commit eec5625

Browse files
Updated documentation such that it correctly displays "int_" now. Added additional typecheck and possibility to use an integer as id (#1635)
1 parent a4e55ef commit eec5625

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

pypesto/history/hdf5.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,8 @@ def _editable(self) -> bool:
479479
@staticmethod
480480
def from_history(
481481
other: HistoryBase,
482-
file: Union[str, Path],
483-
id_: str,
482+
file: str | Path,
483+
id_: str | int,
484484
overwrite: bool = False,
485485
) -> "Hdf5History":
486486
"""Write some History to HDF5.
@@ -491,7 +491,7 @@ def from_history(
491491
History to be copied to HDF5.
492492
file:
493493
HDF5 file to write to (append or create).
494-
id_:
494+
``id_``:
495495
ID of the history.
496496
overwrite:
497497
Whether to overwrite an existing history with the same id.
@@ -501,6 +501,12 @@ def from_history(
501501
-------
502502
The newly created :class:`Hdf5History`.
503503
"""
504+
if isinstance(id_, int):
505+
id_ = str(id_)
506+
if not isinstance(id_, str):
507+
raise ValueError(
508+
f"ID must be a string or integer, not {type(id_)}"
509+
)
504510
history = Hdf5History(file=file, id=id_)
505511
history._f = h5py.File(history.file, mode="a")
506512

0 commit comments

Comments
 (0)