From a27c14158cd2efce3bfce8c0c1de763ab2a5e531 Mon Sep 17 00:00:00 2001 From: Amanda Potts Date: Wed, 20 Nov 2024 11:47:33 -0500 Subject: [PATCH] Closes #3905: assert_equivalent to compare shapes of pdarrays --- arkouda/testing/_asserters.py | 16 ++++++++++++++++ tests/testing/asserters_test.py | 12 ++++++++++++ 2 files changed, 28 insertions(+) diff --git a/arkouda/testing/_asserters.py b/arkouda/testing/_asserters.py index dedfd89459..784bf0e30b 100644 --- a/arkouda/testing/_asserters.py +++ b/arkouda/testing/_asserters.py @@ -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)}" diff --git a/tests/testing/asserters_test.py b/tests/testing/asserters_test.py index f25ef4178e..892d78163b 100644 --- a/tests/testing/asserters_test.py +++ b/tests/testing/asserters_test.py @@ -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))