Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #3905: assert_equivalent to compare shapes of pdarrays #3906

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions arkouda/testing/_asserters.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,8 @@ def raise_assert_detail(


def assert_arkouda_pdarray_equal(
left,
right,
left: pdarray,
right: pdarray,
check_dtype: bool = True,
err_msg=None,
check_same=None,
Expand Down 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 Expand Up @@ -771,7 +787,7 @@ def assert_arkouda_array_equal(
check_same=check_same,
obj=obj,
)
else:
elif isinstance(left, pdarray) and isinstance(right, pdarray):
assert_arkouda_pdarray_equal(
left,
right,
Expand All @@ -781,6 +797,11 @@ def assert_arkouda_array_equal(
obj=obj,
index_values=index_values,
)
else:
raise TypeError(
"assert_arkouda_array_equal can only compare arrays of matching type: "
"pdarray | Strings | Categorical | SegArray"
)


# This could be refactored to use the NDFrame.equals method
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
Loading