Skip to content

DOC: update the isna, isnull, notna and notnull docstring #20459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 26, 2018
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 73 additions & 14 deletions pandas/core/dtypes/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,53 @@


def isna(obj):
"""Detect missing values (NaN in numeric arrays, None/NaN in object arrays)
"""Detect missing values for an array-like object.

This function takes an array-like object, for each element, if it is
a missing value (`NaN` in numeric arrays, `None`/`NaN` in object arrays)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NaT in datetimelike

the correisponding element of the output boolean array will be `True`,
otherwise `False`.

Parameters
----------
arr : ndarray or object value
Object to check for null-ness
obj : array-like or object
Object to check for null-ness.

Returns
-------
isna : array-like of bool or bool
array-like of bool or bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you rephrase as bool or array-like of bool, so that it goes small to big?

Array or bool indicating whether an object is null or if an array is
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wording tripped me up. Could try rephrasing it? Maybe something like, "Indicator for missing values. For a scalar, input, a scalar boolean is returned. For an array-like input, and array (of the same type?) of booleans indicating NA values element-wise is returned.

given which of the element is null.

See also
See Also
--------
notna : boolean inverse of pandas.isna
isnull : alias of isna
Series.isna
DataFrame.isna
Index.isna

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add Series.isna, DataFrame.isna, and Index.isna.

Examples
--------
pandas.notna: boolean inverse of pandas.isna
pandas.isnull: alias of isna
>>> pd.isna('dog')
False
>>> pd.isna(np.nan)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an you add blank lines between cases

True
>>> array
array([[ 1., nan, 3.],
[ 4., 5., nan]])
>>> pd.isna(array)
array([[False, True, False],
[False, False, True]])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an you show a datetimelike example (DatetimeIndex is good)

>>> df = pd.DataFrame([['ant', 'bee', 'cat'], ['dog', None, 'fly']])
>>> df
0 1 2
0 ant bee cat
1 dog None fly
>>> pd.isna(df)
0 1 2
0 False False False
1 False True False
"""
return _isna(obj)

Expand Down Expand Up @@ -197,24 +227,53 @@ def _isna_ndarraylike_old(obj):


def notna(obj):
"""Replacement for numpy.isfinite / -numpy.isnan which is suitable for use
on object arrays.
"""Detect non-missing values for an array-like object.

This function takes an array-like object, for each element, if it is *not*
a missing.value (`NaN` in numeric arrays, `None`/`NaN` in object arrays)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

the correisponding element of the output boolean array will be `True`,
otherwise `False`.

Parameters
----------
arr : ndarray or object value
obj : array-like or object value
Object to check for *not*-null-ness

Returns
-------
notisna : array-like of bool or bool
array-like of bool or bool
Array or bool indicating whether an object is *not* null or if an array
is given which of the element is *not* null.

See also
See Also
--------
isna : boolean inverse of pandas.notna
notnull : alias of notna
Series.notna
DataFrame.notna
Index.notna

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add Series.notna, DataFrame.notna, and Index.notna

Examples
--------
pandas.isna : boolean inverse of pandas.notna
pandas.notnull : alias of notna
>>> pd.notna('dog')
True
>>> pd.notna(np.nan)
False
>>> array
array([[ 1., nan, 3.],
[ 4., 5., nan]])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

>>> pd.notna(array)
array([[ True, False, True],
[ True, True, False]])
>>> df = pd.DataFrame([['ant', 'bee', 'cat'], ['dog', None, 'fly']])
>>> df
0 1 2
0 ant bee cat
1 dog None fly
>>> pd.notna(df)
0 1 2
0 True True True
1 True False True
"""
res = isna(obj)
if is_scalar(res):
Expand Down