Skip to content

CLN/BUG: array_equivalent on nested objects #28347

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

Merged
merged 4 commits into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then
# invgrep -R --include="*.py*" -E "from numpy import nan " pandas # GH#24822 not yet implemented since the offending imports have not all been removed
RET=$(($RET + $?)) ; echo $MSG "DONE"

# flake8 check will find bare except E722 in .py files, need to grep
# to find these in cython files
MSG='Check for bare except statements' ; echo $MSG
invgrep -R --include="*.py*" -E "except:" pandas
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Check for pytest warns' ; echo $MSG
invgrep -r -E --include '*.py' 'pytest\.warns' pandas/tests/
RET=$(($RET + $?)) ; echo $MSG "DONE"
Expand Down
8 changes: 3 additions & 5 deletions pandas/_libs/testing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,9 @@ cpdef assert_almost_equal(a, b,
from pandas.util.testing import assert_attr_equal
assert_attr_equal('dtype', a, b, obj=obj)

try:
if array_equivalent(a, b, strict_nan=True):
return True
except:
pass
if array_equivalent(a, b, strict_nan=True):
return True

else:
na, nb = len(a), len(b)

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/dtypes/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ def array_equivalent(left, right, strict_nan=False):
if not isinstance(right_value, float) or not np.isnan(right_value):
return False
else:
if left_value != right_value:
if np.any(left_value != right_value):
return False
return True

Expand Down
14 changes: 14 additions & 0 deletions pandas/tests/dtypes/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,20 @@ def test_array_equivalent_str():
)


def test_array_equivalent_nested():
# reached in groupby aggregations, make sure we use np.any when checking
# if the comparison is truthy
left = np.array([np.array([50, 70, 90]), np.array([20, 30, 40])], dtype=object)
right = np.array([np.array([50, 70, 90]), np.array([20, 30, 40])], dtype=object)

assert array_equivalent(left, right, strict_nan=True)
assert not array_equivalent(left, right[::-1], strict_nan=True)

left = np.array([np.array([50, 50, 50]), np.array([40, 40, 40])], dtype=object)
right = np.array([50, 40])
assert not array_equivalent(left, right, strict_nan=True)


@pytest.mark.parametrize(
"dtype, na_value",
[
Expand Down