Skip to content

Commit c36e9f7

Browse files
CheuktingTomAugspurger
authored andcommitted
DOC: update the isna, isnull, notna and notnull docstring (#20459)
1 parent 2d491c3 commit c36e9f7

File tree

1 file changed

+128
-19
lines changed

1 file changed

+128
-19
lines changed

pandas/core/dtypes/missing.py

+128-19
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,78 @@
2929

3030

3131
def isna(obj):
32-
"""Detect missing values (NaN in numeric arrays, None/NaN in object arrays)
32+
"""
33+
Detect missing values for an array-like object.
34+
35+
This function takes a scalar or array-like object and indictates
36+
whether values are missing (``NaN`` in numeric arrays, ``None`` or ``NaN``
37+
in object arrays, ``NaT`` in datetimelike).
3338
3439
Parameters
3540
----------
36-
arr : ndarray or object value
37-
Object to check for null-ness
41+
obj : scalar or array-like
42+
Object to check for null or missing values.
3843
3944
Returns
4045
-------
41-
isna : array-like of bool or bool
42-
Array or bool indicating whether an object is null or if an array is
43-
given which of the element is null.
46+
bool or array-like of bool
47+
For scalar input, returns a scalar boolean.
48+
For array input, returns an array of boolean indicating whether each
49+
corresponding element is missing.
4450
45-
See also
51+
See Also
52+
--------
53+
notna : boolean inverse of pandas.isna.
54+
Series.isna : Detetct missing values in a Series.
55+
DataFrame.isna : Detect missing values in a DataFrame.
56+
Index.isna : Detect missing values in an Index.
57+
58+
Examples
4659
--------
47-
pandas.notna: boolean inverse of pandas.isna
48-
pandas.isnull: alias of isna
60+
Scalar arguments (including strings) result in a scalar boolean.
61+
62+
>>> pd.isna('dog')
63+
False
64+
65+
>>> pd.isna(np.nan)
66+
True
67+
68+
ndarrays result in an ndarray of booleans.
69+
70+
>>> array = np.array([[1, np.nan, 3], [4, 5, np.nan]])
71+
>>> array
72+
array([[ 1., nan, 3.],
73+
[ 4., 5., nan]])
74+
>>> pd.isna(array)
75+
array([[False, True, False],
76+
[False, False, True]])
77+
78+
For indexes, an ndarray of booleans is returned.
79+
80+
>>> index = pd.DatetimeIndex(["2017-07-05", "2017-07-06", None,
81+
... "2017-07-08"])
82+
>>> index
83+
DatetimeIndex(['2017-07-05', '2017-07-06', 'NaT', '2017-07-08'],
84+
dtype='datetime64[ns]', freq=None)
85+
>>> pd.isna(index)
86+
array([False, False, True, False])
87+
88+
For Series and DataFrame, the same type is returned, containing booleans.
89+
90+
>>> df = pd.DataFrame([['ant', 'bee', 'cat'], ['dog', None, 'fly']])
91+
>>> df
92+
0 1 2
93+
0 ant bee cat
94+
1 dog None fly
95+
>>> pd.isna(df)
96+
0 1 2
97+
0 False False False
98+
1 False True False
99+
100+
>>> pd.isna(df[1])
101+
0 False
102+
1 True
103+
Name: 1, dtype: bool
49104
"""
50105
return _isna(obj)
51106

@@ -197,24 +252,78 @@ def _isna_ndarraylike_old(obj):
197252

198253

199254
def notna(obj):
200-
"""Replacement for numpy.isfinite / -numpy.isnan which is suitable for use
201-
on object arrays.
255+
"""
256+
Detect non-missing values for an array-like object.
257+
258+
This function takes a scalar or array-like object and indictates
259+
whether values are valid (not missing, which is ``NaN`` in numeric
260+
arrays, ``None`` or ``NaN`` in object arrays, ``NaT`` in datetimelike).
202261
203262
Parameters
204263
----------
205-
arr : ndarray or object value
206-
Object to check for *not*-null-ness
264+
obj : array-like or object value
265+
Object to check for *not* null or *non*-missing values.
207266
208267
Returns
209268
-------
210-
notisna : array-like of bool or bool
211-
Array or bool indicating whether an object is *not* null or if an array
212-
is given which of the element is *not* null.
269+
bool or array-like of bool
270+
For scalar input, returns a scalar boolean.
271+
For array input, returns an array of boolean indicating whether each
272+
corresponding element is valid.
213273
214-
See also
274+
See Also
275+
--------
276+
isna : boolean inverse of pandas.notna.
277+
Series.notna : Detetct valid values in a Series.
278+
DataFrame.notna : Detect valid values in a DataFrame.
279+
Index.notna : Detect valid values in an Index.
280+
281+
Examples
215282
--------
216-
pandas.isna : boolean inverse of pandas.notna
217-
pandas.notnull : alias of notna
283+
Scalar arguments (including strings) result in a scalar boolean.
284+
285+
>>> pd.notna('dog')
286+
True
287+
288+
>>> pd.notna(np.nan)
289+
False
290+
291+
ndarrays result in an ndarray of booleans.
292+
293+
>>> array = np.array([[1, np.nan, 3], [4, 5, np.nan]])
294+
>>> array
295+
array([[ 1., nan, 3.],
296+
[ 4., 5., nan]])
297+
>>> pd.notna(array)
298+
array([[ True, False, True],
299+
[ True, True, False]])
300+
301+
For indexes, an ndarray of booleans is returned.
302+
303+
>>> index = pd.DatetimeIndex(["2017-07-05", "2017-07-06", None,
304+
... "2017-07-08"])
305+
>>> index
306+
DatetimeIndex(['2017-07-05', '2017-07-06', 'NaT', '2017-07-08'],
307+
dtype='datetime64[ns]', freq=None)
308+
>>> pd.notna(index)
309+
array([ True, True, False, True])
310+
311+
For Series and DataFrame, the same type is returned, containing booleans.
312+
313+
>>> df = pd.DataFrame([['ant', 'bee', 'cat'], ['dog', None, 'fly']])
314+
>>> df
315+
0 1 2
316+
0 ant bee cat
317+
1 dog None fly
318+
>>> pd.notna(df)
319+
0 1 2
320+
0 True True True
321+
1 True False True
322+
323+
>>> pd.notna(df[1])
324+
0 True
325+
1 False
326+
Name: 1, dtype: bool
218327
"""
219328
res = isna(obj)
220329
if is_scalar(res):

0 commit comments

Comments
 (0)