Skip to content

Commit

Permalink
moved DeprecationWarning into a separate function and added `LH5Sto…
Browse files Browse the repository at this point in the history
…re` and `LH5Iterator` back into the `__init__` file
  • Loading branch information
MoritzNeuberger committed Oct 31, 2023
1 parent 052e175 commit 6205b9b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
9 changes: 3 additions & 6 deletions src/lgdo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,8 @@
"""

from ._version import version as __version__

# from .lh5 import Iterator, Store, load_dfs, load_nda, ls, show
from .lh5 import Iterator, Store, load_dfs, load_nda, ls, show

# from .lh5_store import LH5Iterator, LH5Store
from .lh5_store import LH5Iterator, LH5Store
from .types import (
LGDO,
Array,
Expand Down Expand Up @@ -76,7 +73,7 @@
"load_nda",
"ls",
"show",
# "LH5Iterator",
# "LH5Store"
"LH5Iterator",
"LH5Store",
"__version__",
]
19 changes: 12 additions & 7 deletions src/lgdo/lgdo_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@

from .lh5 import utils

warn(
"lgdo.lh5_store has moved to a subfolder lgdo.lh5 containing Store and Iterator. "
"Please replace 'import lgdo.lh5_store' with 'import lgdo.lh5'. "
"lgdo.lh5_store will be removed in a future release.",
DeprecationWarning,
stacklevel=2,
)

def throw_dep_warning():
warn(
"lgdo.lh5_store has moved to a subfolder lgdo.lh5 containing Store and Iterator. "
"Please replace 'import lgdo.lh5_store' with 'import lgdo.lh5'. "
"lgdo.lh5_store will be removed in a future release.",
DeprecationWarning,
stacklevel=2,
)


def parse_datatype(datatype: str) -> tuple[str, tuple[int, ...], str | list[str]]:
throw_dep_warning()
return utils.parse_datatype(datatype)


def expand_vars(expr: str, substitute: dict[str, str] = None) -> str:
throw_dep_warning()
return utils.expand_vars(expr, substitute)


Expand All @@ -27,4 +31,5 @@ def expand_path(
list: bool = False,
base_path: str = None,
) -> str | list:
throw_dep_warning()
return utils.expand_path(path, substitute, list, base_path)
20 changes: 10 additions & 10 deletions src/lgdo/lh5_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@
DEFAULT_HDF5_COMPRESSION = None


class LH5Iterator(lh5.Iterator):
def throw_dep_warning():
warn(
"lgdo.lh5_store has moved to a subfolder lgdo.lh5 containing Store and Iterator. "
"Please replace 'from lgdo.lh5_store import LH5Iterator' with 'from lgdo.lh5 import Iterator'. "
"Please replace 'import lgdo.lh5_store' with 'import lgdo.lh5'. "
"lgdo.lh5_store will be removed in a future release.",
DeprecationWarning,
stacklevel=2,
)


class LH5Iterator(lh5.Iterator):
def __init__(
self,
lh5_files: str | list[str],
Expand All @@ -42,6 +44,7 @@ def __init__(
buffer_len: int = 3200,
friend: Iterator = None,
) -> None:
throw_dep_warning()
super().__init__(
lh5_files,
groups,
Expand All @@ -55,15 +58,8 @@ def __init__(


class LH5Store(lh5.Store):
warn(
"lgdo.lh5_store has moved to a subfolder lgdo.lh5 containing Store and Iterator. "
"Please replace 'from lgdo.lh5_store import LH5Store' with 'from lgdo.lh5 import Store'. "
"lgdo.lh5_store will be removed in a future release.",
DeprecationWarning,
stacklevel=2,
)

def __init__(self, base_path: str = "", keep_open: bool = False):
throw_dep_warning()
super().__init__(base_path, keep_open)


Expand All @@ -73,6 +69,7 @@ def load_dfs(
lh5_group: str = "",
idx_list: list[np.ndarray | list | tuple] = None,
) -> pd.DataFrame:
throw_dep_warning()
return lh5.load_dfs(f_list, par_list, lh5_group, idx_list)


Expand All @@ -82,10 +79,12 @@ def load_nda(
lh5_group: str = "",
idx_list: list[np.ndarray | list | tuple] = None,
) -> dict[str, np.ndarray]:
throw_dep_warning()
return lh5.load_nda(f_list, par_list, lh5_group, idx_list)


def ls(lh5_file: str | h5py.Group, lh5_group: str = "") -> list[str]:
throw_dep_warning()
return lh5.ls(lh5_file, lh5_group)


Expand All @@ -96,4 +95,5 @@ def show(
indent: str = "",
header: bool = True,
) -> None:
throw_dep_warning()
show(lh5_file, lh5_group, attrs, indent, header)

0 comments on commit 6205b9b

Please sign in to comment.