Skip to content

Commit 3099218

Browse files
authored
PERF: avoid non-cython in testing.pyx (#51833)
1 parent 2a067ba commit 3099218

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

pandas/_libs/testing.pyx

+5-16
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@ from numpy cimport import_array
77

88
import_array()
99

10+
from pandas._libs.missing cimport checknull
1011
from pandas._libs.util cimport (
1112
is_array,
1213
is_complex_object,
1314
is_real_number_object,
1415
)
1516

16-
from pandas.core.dtypes.common import is_dtype_equal
17-
from pandas.core.dtypes.missing import (
18-
array_equivalent,
19-
isna,
20-
)
17+
from pandas.core.dtypes.missing import array_equivalent
2118

2219

2320
cdef bint isiterable(obj):
@@ -133,7 +130,7 @@ cpdef assert_almost_equal(a, b,
133130
raise_assert_detail(
134131
obj, f"{obj} shapes are different", a.shape, b.shape)
135132

136-
if check_dtype and not is_dtype_equal(a.dtype, b.dtype):
133+
if check_dtype and a.dtype != b.dtype:
137134
from pandas._testing import assert_attr_equal
138135
assert_attr_equal("dtype", a, b, obj=obj)
139136

@@ -181,12 +178,12 @@ cpdef assert_almost_equal(a, b,
181178
# classes can't be the same, to raise error
182179
assert_class_equal(a, b, obj=obj)
183180

184-
if isna(a) and isna(b):
181+
if checknull(a) and checknull(b):
185182
# TODO: Should require same-dtype NA?
186183
# nan / None comparison
187184
return True
188185

189-
if isna(a) and not isna(b) or not isna(a) and isna(b):
186+
if (checknull(a) and not checknull(b)) or (not checknull(a) and checknull(b)):
190187
# boolean value of pd.NA is ambiguous
191188
raise AssertionError(f"{a} != {b}")
192189

@@ -195,10 +192,6 @@ cpdef assert_almost_equal(a, b,
195192
return True
196193

197194
if is_real_number_object(a) and is_real_number_object(b):
198-
if array_equivalent(a, b, strict_nan=True):
199-
# inf comparison
200-
return True
201-
202195
fa, fb = a, b
203196

204197
if not math.isclose(fa, fb, rel_tol=rtol, abs_tol=atol):
@@ -207,10 +200,6 @@ cpdef assert_almost_equal(a, b,
207200
return True
208201

209202
if is_complex_object(a) and is_complex_object(b):
210-
if array_equivalent(a, b, strict_nan=True):
211-
# inf comparison
212-
return True
213-
214203
if not cmath.isclose(a, b, rel_tol=rtol, abs_tol=atol):
215204
assert False, (f"expected {b:.5f} but got {a:.5f}, "
216205
f"with rtol={rtol}, atol={atol}")

pandas/tests/util/test_assert_almost_equal.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def _assert_not_almost_equal(a, b, **kwargs):
4545
try:
4646
tm.assert_almost_equal(a, b, **kwargs)
4747
msg = f"{a} and {b} were approximately equal when they shouldn't have been"
48-
pytest.fail(msg=msg)
48+
pytest.fail(reason=msg)
4949
except AssertionError:
5050
pass
5151

0 commit comments

Comments
 (0)