Skip to content

Commit

Permalink
Closes #3905: assert_equivalent to compare shapes of pdarrays
Browse files Browse the repository at this point in the history
  • Loading branch information
ajpotts committed Nov 20, 2024
1 parent 19d1ca9 commit a27c141
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
16 changes: 16 additions & 0 deletions arkouda/testing/_asserters.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,22 @@ def assert_arkouda_pdarray_equal(
# both classes must be an ak.pdarray
_check_isinstance(left, right, pdarray)

assert (
left.ndim == right.ndim
), f"left dimension {left.ndim} does not match right dimension {right.ndim}."
assert left.size == right.size, f"left size {left.size} does not match right size {right.size}."
if left.shape:
assert (
left.shape == right.shape
), f"left shape {left.shape} does not match right shape {right.shape}."
else:
assert (
isinstance(left.shape, tuple)
and isinstance(right.shape, tuple)
and len(left.shape) == 0
and len(right.shape == 0)
), f"left shape {left.shape} does not match right shape {right.shape}."

assert len(left) == len(
right
), f"Arrays were not same size. left had length {len(left)} and right had length {len(right)}"
Expand Down
12 changes: 12 additions & 0 deletions tests/testing/asserters_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,18 @@ def test_assert_arkouda_array_equal_multi_dim(self, size, left_as_arkouda, right
with pytest.raises(AssertionError):
assert_arkouda_array_equivalent(convert_left(a), convert_right(a2))

@pytest.mark.skip_if_max_rank_less_than(2)
@pytest.mark.parametrize("left_as_arkouda", [True, False])
@pytest.mark.parametrize("right_as_arkouda", [True, False])
def test_assert_arkouda_array_equal_shape(self, left_as_arkouda, right_as_arkouda):
convert_left = self.get_converter(left_as_arkouda)
convert_right = self.get_converter(right_as_arkouda)

a = ak.arange(4).reshape((2, 2))
b = ak.arange(4).reshape((1, 4))
with pytest.raises(AssertionError):
assert_arkouda_array_equivalent(convert_left(a), convert_right(b))

def test_assert_arkouda_segarray_equal(self):

seg = ak.SegArray(ak.array([0, 3, 9]), ak.arange(10))
Expand Down

0 comments on commit a27c141

Please sign in to comment.