Skip to content

Commit 8765ac7

Browse files
authored
TST: avoid re-running tests 14 times (#43922)
1 parent 0b671ad commit 8765ac7

File tree

2 files changed

+33
-32
lines changed

2 files changed

+33
-32
lines changed

pandas/tests/indexes/common.py

-32
Original file line numberDiff line numberDiff line change
@@ -525,38 +525,6 @@ def test_format_empty(self):
525525
assert empty_idx.format() == []
526526
assert empty_idx.format(name=True) == [""]
527527

528-
def test_hasnans_isnans(self, index_flat):
529-
# GH 11343, added tests for hasnans / isnans
530-
index = index_flat
531-
532-
# cases in indices doesn't include NaN
533-
idx = index.copy(deep=True)
534-
expected = np.array([False] * len(idx), dtype=bool)
535-
tm.assert_numpy_array_equal(idx._isnan, expected)
536-
assert idx.hasnans is False
537-
538-
idx = index.copy(deep=True)
539-
values = np.asarray(idx.values)
540-
541-
if len(index) == 0:
542-
return
543-
elif isinstance(index, NumericIndex) and is_integer_dtype(index.dtype):
544-
return
545-
elif isinstance(index, DatetimeIndexOpsMixin):
546-
values[1] = iNaT
547-
else:
548-
values[1] = np.nan
549-
550-
if isinstance(index, PeriodIndex):
551-
idx = type(index)(values, freq=index.freq)
552-
else:
553-
idx = type(index)(values)
554-
555-
expected = np.array([False] * len(idx), dtype=bool)
556-
expected[1] = True
557-
tm.assert_numpy_array_equal(idx._isnan, expected)
558-
assert idx.hasnans is True
559-
560528
def test_fillna(self, index):
561529
# GH 11343
562530
if len(index) == 0:

pandas/tests/indexes/test_common.py

+33
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from pandas.compat import IS64
1313

1414
from pandas.core.dtypes.common import (
15+
is_integer_dtype,
1516
is_period_dtype,
1617
needs_i8_conversion,
1718
)
@@ -366,6 +367,38 @@ def test_asi8_deprecation(self, index):
366367
with tm.assert_produces_warning(warn):
367368
index.asi8
368369

370+
def test_hasnans_isnans(self, index_flat):
371+
# GH#11343, added tests for hasnans / isnans
372+
index = index_flat
373+
374+
# cases in indices doesn't include NaN
375+
idx = index.copy(deep=True)
376+
expected = np.array([False] * len(idx), dtype=bool)
377+
tm.assert_numpy_array_equal(idx._isnan, expected)
378+
assert idx.hasnans is False
379+
380+
idx = index.copy(deep=True)
381+
values = np.asarray(idx.values)
382+
383+
if len(index) == 0:
384+
return
385+
elif isinstance(index, NumericIndex) and is_integer_dtype(index.dtype):
386+
return
387+
elif needs_i8_conversion(index.dtype):
388+
values[1] = iNaT
389+
else:
390+
values[1] = np.nan
391+
392+
if isinstance(index, PeriodIndex):
393+
idx = type(index)(values, freq=index.freq)
394+
else:
395+
idx = type(index)(values)
396+
397+
expected = np.array([False] * len(idx), dtype=bool)
398+
expected[1] = True
399+
tm.assert_numpy_array_equal(idx._isnan, expected)
400+
assert idx.hasnans is True
401+
369402

370403
@pytest.mark.parametrize("na_position", [None, "middle"])
371404
def test_sort_values_invalid_na_position(index_with_missing, na_position):

0 commit comments

Comments
 (0)