Skip to content

Commit

Permalink
Merge pull request #16 from bionumpy/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
knutdrand authored Mar 6, 2024
2 parents c3b9eef + f5e075f commit 029a870
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions npstructures/raggedarray/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ def __init__(self, data: npt.ArrayLike, shape: ShapeLike = None, dtype: npt.DTyp
shape = shape
else:
shape = RaggedShape.asshape(shape)
if not shape.size == len(data) and safe_mode:
raise ValueError(f"The total size of provided shape {shape.size} does not match the size of the data array: {len(data)}")
if not hasattr(data, "__array_ufunc__"):
data = np.asanyarray(data, dtype=dtype)
super().__init__(data, shape)
Expand Down
11 changes: 11 additions & 0 deletions tests/test_raggedarray_usage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pytest

from npstructures import RaggedArray

# this works

def test_assert_raises_value_error():
with pytest.raises(ValueError):
x = RaggedArray([0, 1, 2, 3], [4, 5, 6])


0 comments on commit 029a870

Please sign in to comment.