Skip to content

Commit

Permalink
check for order, add type hints for slice
Browse files Browse the repository at this point in the history
  • Loading branch information
jkanche committed Jun 22, 2023
1 parent cfa6459 commit 5dd082e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/filebackedarray/H5Dense.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Optional, Sequence, Tuple, Union

import h5py
import numpy as np

from .utils import _check_indices, infer_h5_dataset

Expand Down Expand Up @@ -31,6 +32,12 @@ def __init__(self, path: str, group: str, order: str = "C") -> None:
self._h5file = h5py.File(path, mode="r")
self._dataset = self._h5file[group]
self._dataset_info = infer_h5_dataset(self._dataset)

if order not in ("C", "F"):
raise ValueError(
"order must be C (c-style, row-major) or F (fortran-style, column-major)"
)

self._order = order

if self._dataset_info.format != "dense":
Expand Down Expand Up @@ -71,7 +78,7 @@ def mat_format(self) -> str:
def __getitem__(
self,
args: Tuple[Union[slice, Sequence[int]], Optional[Union[slice, Sequence[int]]]],
):
) -> np.ndarray:
if len(args) == 0:
raise ValueError("Arguments must contain one slice")

Expand Down
3 changes: 2 additions & 1 deletion src/filebackedarray/H5Sparse.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Optional, Sequence, Tuple, Union

import h5py
import scipy.sparse as sp

from .utils import _check_indices, _slice_h5_sparse, infer_h5_dataset

Expand Down Expand Up @@ -67,7 +68,7 @@ def mat_format(self) -> str:
def __getitem__(
self,
args: Tuple[Union[slice, Sequence[int]], Optional[Union[slice, Sequence[int]]]],
):
) -> sp.spmatrix:
if len(args) == 0:
raise ValueError("Arguments must contain one slice")

Expand Down

0 comments on commit 5dd082e

Please sign in to comment.