Skip to content

Commit faba7ef

Browse files
Donk23TomAugspurger
authored andcommitted
DOC: Update the pandas.Index.isna docstring (#20123)
1 parent 591cef5 commit faba7ef

File tree

1 file changed

+45
-5
lines changed

1 file changed

+45
-5
lines changed

pandas/core/indexes/base.py

+45-5
Original file line numberDiff line numberDiff line change
@@ -2148,18 +2148,58 @@ def hasnans(self):
21482148

21492149
def isna(self):
21502150
"""
2151-
Detect missing values
2151+
Detect missing values.
2152+
2153+
Return a boolean same-sized object indicating if the values are NA.
2154+
NA values, such as ``None``, :attr:`numpy.NaN` or :attr:`pd.NaT`, get
2155+
mapped to ``True`` values.
2156+
Everything else get mapped to ``False`` values. Characters such as
2157+
empty strings `''` or :attr:`numpy.inf` are not considered NA values
2158+
(unless you set :attr:`pandas.options.mode.use_inf_as_na` `= True`).
21522159
21532160
.. versionadded:: 0.20.0
21542161
21552162
Returns
21562163
-------
2157-
a boolean array of whether my values are NA
2164+
numpy.ndarray
2165+
A boolean array of whether my values are NA
21582166
2159-
See also
2167+
See Also
21602168
--------
2161-
isnull : alias of isna
2162-
pandas.isna : top-level isna
2169+
pandas.Index.notna : boolean inverse of isna.
2170+
pandas.Index.dropna : omit entries with missing values.
2171+
pandas.isna : top-level isna.
2172+
Series.isna : detect missing values in Series object.
2173+
2174+
Examples
2175+
--------
2176+
Show which entries in a pandas.Index are NA. The result is an
2177+
array.
2178+
2179+
>>> idx = pd.Index([5.2, 6.0, np.NaN])
2180+
>>> idx
2181+
Float64Index([5.2, 6.0, nan], dtype='float64')
2182+
>>> idx.isna()
2183+
array([False, False, True], dtype=bool)
2184+
2185+
Empty strings are not considered NA values. None is considered an NA
2186+
value.
2187+
2188+
>>> idx = pd.Index(['black', '', 'red', None])
2189+
>>> idx
2190+
Index(['black', '', 'red', None], dtype='object')
2191+
>>> idx.isna()
2192+
array([False, False, False, True], dtype=bool)
2193+
2194+
For datetimes, `NaT` (Not a Time) is considered as an NA value.
2195+
2196+
>>> idx = pd.DatetimeIndex([pd.Timestamp('1940-04-25'),
2197+
... pd.Timestamp(''), None, pd.NaT])
2198+
>>> idx
2199+
DatetimeIndex(['1940-04-25', 'NaT', 'NaT', 'NaT'],
2200+
dtype='datetime64[ns]', freq=None)
2201+
>>> idx.isna()
2202+
array([False, True, True, True], dtype=bool)
21632203
"""
21642204
return self._isnan
21652205
isnull = isna

0 commit comments

Comments
 (0)