File tree 4 files changed +59
-1
lines changed
4 files changed +59
-1
lines changed Original file line number Diff line number Diff line change @@ -1356,8 +1356,16 @@ Modifying and Computations
1356
1356
Index.unique
1357
1357
Index.nunique
1358
1358
Index.value_counts
1359
+
1360
+ Missing Values
1361
+ ~~~~~~~~~~~~~~
1362
+ .. autosummary ::
1363
+ :toctree: generated/
1364
+
1359
1365
Index.fillna
1360
1366
Index.dropna
1367
+ Index.isnull
1368
+ Index.notnull
1361
1369
1362
1370
Conversion
1363
1371
~~~~~~~~~~
Original file line number Diff line number Diff line change @@ -125,7 +125,7 @@ Other enhancements
125
125
126
126
- ``pd.read_excel`` now preserves sheet order when using ``sheetname=None`` (:issue:`9930`)
127
127
- Multiple offset aliases with decimal points are now supported (e.g. '0.5min' is parsed as '30s') (:issue:`8419`)
128
-
128
+ - ``.isnull()`` and ``.notnull()`` have been added to ``Index`` object to make them more consistent with the ``Series`` API (:issue:``)
129
129
- ``pd.read_gbq`` method now allows query configuration preferences (:issue:`14742`)
130
130
131
131
- New ``UnsortedIndexError`` (subclass of ``KeyError``) raised when indexing/slicing into an
Original file line number Diff line number Diff line change @@ -1662,6 +1662,34 @@ def hasnans(self):
1662
1662
else :
1663
1663
return False
1664
1664
1665
+ def isnull (self ):
1666
+ """
1667
+ Detect missing values
1668
+
1669
+ Returns
1670
+ -------
1671
+ a boolean array of whether my values are null
1672
+
1673
+ See also
1674
+ --------
1675
+ pandas.isnull : pandas version
1676
+ """
1677
+ return self ._isnan
1678
+
1679
+ def notnull (self ):
1680
+ """
1681
+ Reverse of isnull
1682
+
1683
+ Returns
1684
+ -------
1685
+ a boolean array of whether my values are not null
1686
+
1687
+ See also
1688
+ --------
1689
+ pandas.notnull : pandas version
1690
+ """
1691
+ return ~ self .isnull ()
1692
+
1665
1693
def putmask (self , mask , value ):
1666
1694
"""
1667
1695
return a new Index of the values set with the mask
Original file line number Diff line number Diff line change @@ -879,3 +879,25 @@ 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 (index .isnull (), np .array ([], dtype = bool ))
890
+ elif isinstance (index , MultiIndex ):
891
+ idx = index .copy ()
892
+ msg = "isnull is not defined for MultiIndex"
893
+ with self .assertRaisesRegexp (NotImplementedError , msg ):
894
+ idx .isnull ()
895
+ else :
896
+
897
+ if not index .hasnans :
898
+ self .assert_numpy_array_equal (index .isnull (), np .zeros (len (index ), dtype = bool ))
899
+ self .assert_numpy_array_equal (index .notnull (), np .ones (len (index ), dtype = bool ))
900
+ else :
901
+ result = isnull (index )
902
+ self .assert_numpy_array_equal (index .isnull (), result )
903
+ self .assert_numpy_array_equal (index .notnull (), ~ result )
You can’t perform that action at this time.
0 commit comments