Skip to content

Commit 53a4e75

Browse files
committed
MNT: refactor tortured logic in test
1 parent b356e04 commit 53a4e75

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

numpy/_core/tests/test_stringdtype.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -228,19 +228,16 @@ def test_self_casts(dtype, dtype2, strings):
228228
if hasattr(dtype, "na_object") and hasattr(dtype2, "na_object"):
229229
na1 = dtype.na_object
230230
na2 = dtype2.na_object
231-
if na1 is na2:
232-
assert_array_equal(arr[:-1], newarr[:-1])
233-
else:
234-
# comparisons between arrays with distinct NA objects
235-
# aren't allowed
236-
if ((na1 is pd_NA or na2 is pd_NA or
237-
(na1 != na2 and not ((na1 != na1) and (na2 != na2))))):
238-
with pytest.raises(TypeError):
239-
arr[:-1] == newarr[:-1]
240-
else:
241-
assert_array_equal(arr[:-1], newarr[:-1])
242-
else:
243-
assert_array_equal(arr[:-1], newarr[:-1])
231+
if ((na1 is not na2 and
232+
# check for pd_NA first because bool(pd_NA) is an error
233+
((na1 is pd_NA or na2 is pd_NA) or
234+
# the second check is a NaN check, spelled this way
235+
# to avoid errors from math.isnan and np.isnan
236+
(na1 != na2 and not (na1 != na1 and na2 != na2))))):
237+
with pytest.raises(TypeError):
238+
arr[:-1] == newarr[:-1]
239+
return
240+
assert_array_equal(arr[:-1], newarr[:-1])
244241

245242

246243
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)