|
7 | 7 |
|
8 | 8 | from pandas import (Series, Index, Float64Index, Int64Index, UInt64Index,
|
9 | 9 | RangeIndex, MultiIndex, CategoricalIndex, DatetimeIndex,
|
10 |
| - TimedeltaIndex, PeriodIndex, notnull) |
| 10 | + TimedeltaIndex, PeriodIndex, notnull, isnull) |
11 | 11 | from pandas.types.common import needs_i8_conversion
|
12 | 12 | from pandas.util.testing import assertRaisesRegexp
|
13 | 13 |
|
@@ -879,3 +879,28 @@ def test_fillna(self):
|
879 | 879 | expected[1] = True
|
880 | 880 | self.assert_numpy_array_equal(idx._isnan, expected)
|
881 | 881 | self.assertTrue(idx.hasnans)
|
| 882 | + |
| 883 | + def test_nulls(self): |
| 884 | + # this is really a smoke test for the methods |
| 885 | + # as these are adequantely tested for function elsewhere |
| 886 | + |
| 887 | + for name, index in self.indices.items(): |
| 888 | + if len(index) == 0: |
| 889 | + self.assert_numpy_array_equal( |
| 890 | + index.isnull(), np.array([], dtype=bool)) |
| 891 | + elif isinstance(index, MultiIndex): |
| 892 | + idx = index.copy() |
| 893 | + msg = "isnull is not defined for MultiIndex" |
| 894 | + with self.assertRaisesRegexp(NotImplementedError, msg): |
| 895 | + idx.isnull() |
| 896 | + else: |
| 897 | + |
| 898 | + if not index.hasnans: |
| 899 | + self.assert_numpy_array_equal( |
| 900 | + index.isnull(), np.zeros(len(index), dtype=bool)) |
| 901 | + self.assert_numpy_array_equal( |
| 902 | + index.notnull(), np.ones(len(index), dtype=bool)) |
| 903 | + else: |
| 904 | + result = isnull(index) |
| 905 | + self.assert_numpy_array_equal(index.isnull(), result) |
| 906 | + self.assert_numpy_array_equal(index.notnull(), ~result) |
0 commit comments