From 31b80ae4b6aaf0f4c527ebfed46143aafd86d928 Mon Sep 17 00:00:00 2001 From: donk23 Date: Sat, 10 Mar 2018 13:56:14 +0100 Subject: [PATCH 1/7] DOC: improved docstring of pandas.Index.isna --- pandas/core/indexes/base.py | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 7e6ae88a26e7c..359139c41eddb 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2022,18 +2022,46 @@ def hasnans(self): def isna(self): """ - Detect missing values + Detect missing values. + + Return a boolean same-sized object indicating if the values are NA. + NA values, such as None or :attr:`numpy.NaN`, get mapped to True values. + Everything else get mapped to False values. Characters such as empty + strings `''` or :attr:`numpy.inf` are not considered NA values + (unless you set :attr:`pandas.options.mode.use_inf_as_na` `= True`). .. versionadded:: 0.20.0 Returns ------- - a boolean array of whether my values are NA + numpy.ndarray + A boolean array of whether my values are NA See also -------- - isnull : alias of isna + pandas.Index.isnull : alias of isna + pandas.Index.notna : boolean inverse of isna + pandas.Index.dropna : omit entries with missing values pandas.isna : top-level isna + + Examples + -------- + Show which entries in a pandas.Index are NA. The result is a + array. + + >>> idx = pd.Index([5.2, 6.0, np.NaN]) + >>> idx + Float64Index([5.2, 6.0, nan], dtype='float64') + >>> idx.isna() + array([False, False, True]) + + Empty strings are not considered NA values. None is considered NA value. + + >>> idx = pd.Index(['black', '', 'red', None]) + >>> idx + Index(['black', '', 'red', None], dtype='object') + >>> idx.isna() + array([False, False, False, True]) """ return self._isnan isnull = isna From c25704fa5b9d2b02e16eb7bcdf4bfebdbc9d2265 Mon Sep 17 00:00:00 2001 From: donk23 Date: Sat, 10 Mar 2018 14:00:17 +0100 Subject: [PATCH 2/7] DOC: improved docstring of pandas.Index.isna --- pandas/core/indexes/base.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 359139c41eddb..b186a8485f10b 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2025,7 +2025,8 @@ def isna(self): Detect missing values. Return a boolean same-sized object indicating if the values are NA. - NA values, such as None or :attr:`numpy.NaN`, get mapped to True values. + NA values, such as None or :attr:`numpy.NaN`, get mapped to True + values. Everything else get mapped to False values. Characters such as empty strings `''` or :attr:`numpy.inf` are not considered NA values (unless you set :attr:`pandas.options.mode.use_inf_as_na` `= True`). @@ -2055,7 +2056,8 @@ def isna(self): >>> idx.isna() array([False, False, True]) - Empty strings are not considered NA values. None is considered NA value. + Empty strings are not considered NA values. None is considered a NA + value. >>> idx = pd.Index(['black', '', 'red', None]) >>> idx From d42569d94bd44888f57e7e326f953daf54029c3d Mon Sep 17 00:00:00 2001 From: donK23 Date: Sat, 10 Mar 2018 14:29:04 +0100 Subject: [PATCH 3/7] DOC: pandas.Index.isna grammar Fixed grammar --- pandas/core/indexes/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index b186a8485f10b..9a7441c2c1ec5 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2047,7 +2047,7 @@ def isna(self): Examples -------- - Show which entries in a pandas.Index are NA. The result is a + Show which entries in a pandas.Index are NA. The result is an array. >>> idx = pd.Index([5.2, 6.0, np.NaN]) @@ -2056,7 +2056,7 @@ def isna(self): >>> idx.isna() array([False, False, True]) - Empty strings are not considered NA values. None is considered a NA + Empty strings are not considered NA values. None is considered an NA value. >>> idx = pd.Index(['black', '', 'red', None]) From 87fb1e2a66b0523d434179e16972d0ea50a52771 Mon Sep 17 00:00:00 2001 From: donk23 Date: Sat, 10 Mar 2018 23:25:22 +0100 Subject: [PATCH 4/7] Fixed description, See Also section and added DatetimeIndex example --- pandas/core/indexes/base.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index b186a8485f10b..04363f5b396e5 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2025,10 +2025,10 @@ def isna(self): Detect missing values. Return a boolean same-sized object indicating if the values are NA. - NA values, such as None or :attr:`numpy.NaN`, get mapped to True - values. - Everything else get mapped to False values. Characters such as empty - strings `''` or :attr:`numpy.inf` are not considered NA values + NA values, such as ``None``, :attr:`numpy.NaN` or :attr:`pd.NaT`, get + mapped to ``True`` values. + Everything else get mapped to ``False`` values. Characters such as + empty strings `''` or :attr:`numpy.inf` are not considered NA values (unless you set :attr:`pandas.options.mode.use_inf_as_na` `= True`). .. versionadded:: 0.20.0 @@ -2038,12 +2038,13 @@ def isna(self): numpy.ndarray A boolean array of whether my values are NA - See also + See Also -------- pandas.Index.isnull : alias of isna pandas.Index.notna : boolean inverse of isna pandas.Index.dropna : omit entries with missing values pandas.isna : top-level isna + Series.isna : detect missing values in Series object Examples -------- @@ -2064,6 +2065,16 @@ def isna(self): Index(['black', '', 'red', None], dtype='object') >>> idx.isna() array([False, False, False, True]) + + In pandas.DatetimeIndex, a `NaT` value is considered as a NA value. + + >>> idx = pd.DatetimeIndex([pd.Timestamp('1940-04-25'), + ... pd.Timestamp(''), None, pd.NaT]) + >>> idx + DatetimeIndex(['1940-04-25', 'NaT', 'NaT', 'NaT'], + dtype='datetime64[ns]', freq=None) + >>> idx.isna() + array([False, True, True, True]) """ return self._isnan isnull = isna From 6e859ba43548c392f4f234b6a12a615cf843cd9f Mon Sep 17 00:00:00 2001 From: donK23 Date: Sat, 10 Mar 2018 23:44:32 +0100 Subject: [PATCH 5/7] Fixed description and See Also section, added DatetimeIndex example --- pandas/core/indexes/base.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 9a7441c2c1ec5..ccc2c807d2522 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2025,10 +2025,10 @@ def isna(self): Detect missing values. Return a boolean same-sized object indicating if the values are NA. - NA values, such as None or :attr:`numpy.NaN`, get mapped to True - values. - Everything else get mapped to False values. Characters such as empty - strings `''` or :attr:`numpy.inf` are not considered NA values + NA values, such as ``None``, :attr:`numpy.NaN` or :attr:`pd.NaT`, get + mapped to ``True`` values. + Everything else get mapped to ``False`` values. Characters such as + empty strings `''` or :attr:`numpy.inf` are not considered NA values (unless you set :attr:`pandas.options.mode.use_inf_as_na` `= True`). .. versionadded:: 0.20.0 @@ -2038,12 +2038,13 @@ def isna(self): numpy.ndarray A boolean array of whether my values are NA - See also + See Also -------- pandas.Index.isnull : alias of isna pandas.Index.notna : boolean inverse of isna pandas.Index.dropna : omit entries with missing values pandas.isna : top-level isna + Series.isna : detect missing values in Series object Examples -------- @@ -2064,6 +2065,16 @@ def isna(self): Index(['black', '', 'red', None], dtype='object') >>> idx.isna() array([False, False, False, True]) + + In pandas.DatetimeIndex, a `NaT` value is considered as a NA value. + + >>> idx = pd.DatetimeIndex([pd.Timestamp('1940-04-25'), + ... pd.Timestamp(''), None, pd.NaT]) + >>> idx + DatetimeIndex(['1940-04-25', 'NaT', 'NaT', 'NaT'], + dtype='datetime64[ns]', freq=None) + >>> idx.isna() + array([False, True, True, True]) """ return self._isnan isnull = isna From 3f23997a5b2ddaf08852c35b1cd5603105103f63 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Mon, 12 Mar 2018 16:15:47 -0500 Subject: [PATCH 6/7] Updated --- pandas/core/indexes/base.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index b81e6d21e8a4d..a56b866183c76 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2040,11 +2040,10 @@ def isna(self): See Also -------- - pandas.Index.isnull : alias of isna - pandas.Index.notna : boolean inverse of isna - pandas.Index.dropna : omit entries with missing values - pandas.isna : top-level isna - Series.isna : detect missing values in Series object + pandas.Index.notna : boolean inverse of isna. + pandas.Index.dropna : omit entries with missing values. + pandas.isna : top-level isna. + Series.isna : detect missing values in Series object. Examples -------- @@ -2066,7 +2065,7 @@ def isna(self): >>> idx.isna() array([False, False, False, True]) - In pandas.DatetimeIndex, a `NaT` value is considered as a NA value. + For datetimes, `NaT` (Not a Time) is considered as an NA value. >>> idx = pd.DatetimeIndex([pd.Timestamp('1940-04-25'), ... pd.Timestamp(''), None, pd.NaT]) From 195421e1fd1cace5ea50d8cc11001df540d78b18 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Mon, 12 Mar 2018 16:16:45 -0500 Subject: [PATCH 7/7] Include dtype in array --- pandas/core/indexes/base.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index a56b866183c76..f387afde24117 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2054,7 +2054,7 @@ def isna(self): >>> idx Float64Index([5.2, 6.0, nan], dtype='float64') >>> idx.isna() - array([False, False, True]) + array([False, False, True], dtype=bool) Empty strings are not considered NA values. None is considered an NA value. @@ -2063,7 +2063,7 @@ def isna(self): >>> idx Index(['black', '', 'red', None], dtype='object') >>> idx.isna() - array([False, False, False, True]) + array([False, False, False, True], dtype=bool) For datetimes, `NaT` (Not a Time) is considered as an NA value. @@ -2073,7 +2073,7 @@ def isna(self): DatetimeIndex(['1940-04-25', 'NaT', 'NaT', 'NaT'], dtype='datetime64[ns]', freq=None) >>> idx.isna() - array([False, True, True, True]) + array([False, True, True, True], dtype=bool) """ return self._isnan isnull = isna