Skip to content

Commit

Permalink
Data type of patch must match.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielballan committed Nov 18, 2024
1 parent cb395d4 commit 24b9027
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tiled/_tests/test_writing.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ def test_extend_array(tree):
ac.patch(ones * 8, offset=8, extend=True)
numpy.testing.assert_equal(ac[8:9], ones * 8)

# Data type must match.
with pytest.raises(ValueError):
ac.patch(ones.astype("uint8"), offset=9, extend=True)


def test_write_dataframe_full(tree):
with Context.from_app(
Expand Down
5 changes: 5 additions & 0 deletions tiled/client/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ def patch(self, array: NDArray, offset: Union[int, tuple[int, ...]], extend=Fals
[[0., 0.],
[0., 0.]]])
"""
if array.dtype != self.dtype:
raise ValueError(
f"Data given to patch has dtype {array.dtype} which does not "
f"match the dtype of this array {self.dtype}."
)
array_ = numpy.ascontiguousarray(array)
if isinstance(offset, int):
offset = (offset,)
Expand Down

0 comments on commit 24b9027

Please sign in to comment.