Skip to content

Commit 2a3cf83

Browse files
BUG: avoid triggering numpy deprecation warning in assert functions for nested array with empty array/list (#59778)
1 parent 7acb965 commit 2a3cf83

File tree

4 files changed

+8
-22
lines changed

4 files changed

+8
-22
lines changed

pandas/_libs/lib.pyx

+2
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,8 @@ def array_equivalent_object(ndarray left, ndarray right) -> bool:
600600
if not array_equivalent(x, y):
601601
return False
602602

603+
elif PyArray_Check(x) or PyArray_Check(y):
604+
return False
603605
elif (x is C_NA) ^ (y is C_NA):
604606
return False
605607
elif not (

pandas/tests/dtypes/test_missing.py

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from contextlib import nullcontext
21
from datetime import datetime
32
from decimal import Decimal
43

@@ -7,7 +6,6 @@
76

87
from pandas._libs import missing as libmissing
98
from pandas._libs.tslibs import iNaT
10-
from pandas.compat.numpy import np_version_gte1p25
119

1210
from pandas.core.dtypes.common import (
1311
is_float,
@@ -458,15 +456,7 @@ def test_array_equivalent_dti(dtype_equal):
458456
)
459457
def test_array_equivalent_series(val):
460458
arr = np.array([1, 2])
461-
msg = "elementwise comparison failed"
462-
cm = (
463-
# stacklevel is chosen to make sense when called from .equals
464-
tm.assert_produces_warning(FutureWarning, match=msg, check_stacklevel=False)
465-
if isinstance(val, str) and not np_version_gte1p25
466-
else nullcontext()
467-
)
468-
with cm:
469-
assert not array_equivalent(Series([arr, arr]), Series([arr, val]))
459+
assert not array_equivalent(Series([arr, arr]), Series([arr, val]))
470460

471461

472462
def test_array_equivalent_array_mismatched_shape():

pandas/tests/series/methods/test_equals.py

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
from contextlib import nullcontext
21
import copy
32

43
import numpy as np
54
import pytest
65

76
from pandas._libs.missing import is_matching_na
8-
from pandas.compat.numpy import np_version_gte1p25
97

108
from pandas.core.dtypes.common import is_float
119

@@ -14,7 +12,6 @@
1412
MultiIndex,
1513
Series,
1614
)
17-
import pandas._testing as tm
1815

1916

2017
@pytest.mark.parametrize(
@@ -48,14 +45,7 @@ def test_equals_list_array(val):
4845
assert s1.equals(s2)
4946

5047
s1[1] = val
51-
52-
cm = (
53-
tm.assert_produces_warning(FutureWarning, check_stacklevel=False)
54-
if isinstance(val, str) and not np_version_gte1p25
55-
else nullcontext()
56-
)
57-
with cm:
58-
assert not s1.equals(s2)
48+
assert not s1.equals(s2)
5949

6050

6151
def test_equals_false_negative():

pandas/tests/util/test_assert_almost_equal.py

+4
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,10 @@ def test_assert_almost_equal_iterable_values_mismatch():
534534
np.array([np.array([1, 2, 3]), np.array([4, 5])], dtype=object),
535535
np.array([[1, 2, 3], [4, 5]], dtype=object),
536536
),
537+
(
538+
np.array([np.array([], dtype=object), None], dtype=object),
539+
np.array([[], None], dtype=object),
540+
),
537541
(
538542
np.array(
539543
[

0 commit comments

Comments
 (0)