From 31b80ae4b6aaf0f4c527ebfed46143aafd86d928 Mon Sep 17 00:00:00 2001 From: donk23 Date: Sat, 10 Mar 2018 13:56:14 +0100 Subject: [PATCH 01/11] 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 02/11] 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 bab00126b6fa905742db57047f03aa83501215ce Mon Sep 17 00:00:00 2001 From: donk23 Date: Sat, 10 Mar 2018 14:41:13 +0100 Subject: [PATCH 03/11] DOC: update pandas.DataFrame.isna and pandas.Series.isna --- pandas/core/generic.py | 52 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index a893b2ba1a189..06f0408c4934e 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -5458,13 +5458,63 @@ def asof(self, where, subset=None): # Action Methods _shared_docs['isna'] = """ + 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`). + + Returns + ------- + bool of type %(klass)s + Mask of True/False values for each element in %(klass)s that + indicates whether an element is an NA value See Also -------- - %(klass)s.notna : boolean inverse of isna %(klass)s.isnull : alias of isna + %(klass)s.notna : boolean inverse of isna + %(klass)s.dropna : omit axes labels with missing values isna : top-level isna + + Examples + -------- + Show which entries in a DataFrame are NA. + + >>> df = pd.DataFrame({'age': [5, 6, np.NaN], + ... 'born': [pd.NaT, pd.Timestamp('1939-05-27'), + ... pd.Timestamp('1940-04-25')], + ... 'name': ['Alfred', 'Batman', ''], + ... 'toy': [None, 'Batmobile', 'Joker']}) + >>> df + age born name toy + 0 5.0 NaT Alfred None + 1 6.0 1939-05-27 Batman Batmobile + 2 NaN 1940-04-25 Joker + + >>> df.isna() + age born name toy + 0 False True False True + 1 False False False False + 2 True False False False + + Show which entries in a Series are NA. + + >>> ser = pd.Series([5, 6, np.NaN]) + >>> ser + 0 5.0 + 1 6.0 + 2 NaN + dtype: float64 + + >>> ser.isna() + 0 False + 1 False + 2 True + dtype: bool """ @Appender(_shared_docs['isna'] % _shared_doc_kwargs) From 742e566b954c5995f6ce475eeebf796fc4b88d1a Mon Sep 17 00:00:00 2001 From: donk23 Date: Sat, 10 Mar 2018 15:33:57 +0100 Subject: [PATCH 04/11] DOC: update pandas.DataFrame.notna and pandas.Series.notna --- pandas/core/generic.py | 55 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 06f0408c4934e..a2a27f1246734 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -5526,14 +5526,63 @@ def isnull(self): return isna(self).__finalize__(self) _shared_docs['notna'] = """ - Return a boolean same-sized object indicating if the values are - not NA. + Detect existing (non-missing) values. + + Return a boolean same-sized object indicating if the values are not NA. + Non-missing values get mapped to True. 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`). + NA values, such as None or :attr:`numpy.NaN`, get mapped to False + values. + + Returns + ------- + bool of type %(klass)s + Mask of True/False values for each element in %(klass)s that + indicates whether an element is not an NA value See Also -------- - %(klass)s.isna : boolean inverse of notna %(klass)s.notnull : alias of notna + %(klass)s.isna : boolean inverse of notna + %(klass)s.dropna : omit axes labels with missing values notna : top-level notna + + Examples + -------- + Show which entries in a DataFrame are not NA. + + >>> df = pd.DataFrame({'age': [5, 6, np.NaN], + ... 'born': [pd.NaT, pd.Timestamp('1939-05-27'), + ... pd.Timestamp('1940-04-25')], + ... 'name': ['Alfred', 'Batman', ''], + ... 'toy': [None, 'Batmobile', 'Joker']}) + >>> df + age born name toy + 0 5.0 NaT Alfred None + 1 6.0 1939-05-27 Batman Batmobile + 2 NaN 1940-04-25 Joker + + >>> df.notna() + age born name toy + 0 True False True False + 1 True True True True + 2 False True True True + + Show which entries in a Series are not NA. + + >>> ser = pd.Series([5, 6, np.NaN]) + >>> ser + 0 5.0 + 1 6.0 + 2 NaN + dtype: float64 + + >>> ser.notna() + 0 True + 1 True + 2 False + dtype: bool """ @Appender(_shared_docs['notna'] % _shared_doc_kwargs) From 04bf6b6c7e7c81bf6f539c1000bb8193bde30363 Mon Sep 17 00:00:00 2001 From: donk23 Date: Sat, 10 Mar 2018 16:01:53 +0100 Subject: [PATCH 05/11] DOC: Trying to undo accidental commit --- pandas/core/indexes/base.py | 38 ++++--------------------------------- 1 file changed, 4 insertions(+), 34 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index b186a8485f10b..52283e4e223b4 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1156,7 +1156,7 @@ def to_frame(self, index=True): >>> idx = pd.Index(['Ant', 'Bear', 'Cow'], name='animal') >>> idx.to_frame() animal - animal + animal Ant Ant Bear Bear Cow Cow @@ -2022,48 +2022,18 @@ def hasnans(self): 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 - (unless you set :attr:`pandas.options.mode.use_inf_as_na` `= True`). + Detect missing values .. versionadded:: 0.20.0 Returns ------- - numpy.ndarray - A boolean array of whether my values are NA + a boolean array of whether my values are NA See also -------- - pandas.Index.isnull : alias of isna - pandas.Index.notna : boolean inverse of isna - pandas.Index.dropna : omit entries with missing values + isnull : alias of isna 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 a 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 cf7bd71fcb6c9c816a85394d76ab39a76391e05d Mon Sep 17 00:00:00 2001 From: donK23 Date: Sun, 11 Mar 2018 00:18:39 +0100 Subject: [PATCH 06/11] Fixed Returns --- pandas/core/generic.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index a2a27f1246734..802210a0cb13c 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -5537,9 +5537,9 @@ def isnull(self): Returns ------- - bool of type %(klass)s - Mask of True/False values for each element in %(klass)s that - indicates whether an element is not an NA value + %(klass)s + Mask of bool values for each element in %(klass)s that + indicates whether an element is not an NA value. See Also -------- From 4a6acea827255a267fea7066d208a2c78f57ebfb Mon Sep 17 00:00:00 2001 From: donk23 Date: Mon, 12 Mar 2018 21:32:20 +0100 Subject: [PATCH 07/11] Undo wrong file edit --- pandas/core/indexes/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 52283e4e223b4..683f538502382 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1156,7 +1156,7 @@ def to_frame(self, index=True): >>> idx = pd.Index(['Ant', 'Bear', 'Cow'], name='animal') >>> idx.to_frame() animal - animal + animal Ant Ant Bear Bear Cow Cow From 939d897231de9bdd83cd1f188536fe409c27794a Mon Sep 17 00:00:00 2001 From: donk23 Date: Mon, 12 Mar 2018 21:34:15 +0100 Subject: [PATCH 08/11] Undo wrong file edit --- pandas/core/indexes/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 683f538502382..52283e4e223b4 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1156,7 +1156,7 @@ def to_frame(self, index=True): >>> idx = pd.Index(['Ant', 'Bear', 'Cow'], name='animal') >>> idx.to_frame() animal - animal + animal Ant Ant Bear Bear Cow Cow From 006ca9b39162be50193ad28fdd186f89f881d786 Mon Sep 17 00:00:00 2001 From: donk23 Date: Mon, 12 Mar 2018 21:36:26 +0100 Subject: [PATCH 09/11] Undo wrong file edit --- pandas/core/indexes/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 52283e4e223b4..7e6ae88a26e7c 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1156,7 +1156,7 @@ def to_frame(self, index=True): >>> idx = pd.Index(['Ant', 'Bear', 'Cow'], name='animal') >>> idx.to_frame() animal - animal + animal Ant Ant Bear Bear Cow Cow From 657539a982a16f138ab9364463641d3ffffb02d6 Mon Sep 17 00:00:00 2001 From: donk23 Date: Tue, 13 Mar 2018 13:30:06 +0100 Subject: [PATCH 10/11] Fixed typos and update link --- pandas/core/generic.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 802210a0cb13c..1ef3f2155853a 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -5529,10 +5529,10 @@ def isnull(self): Detect existing (non-missing) values. Return a boolean same-sized object indicating if the values are not NA. - Non-missing values get mapped to True. Characters such as empty + Non-missing values gets mapped to True. 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`). - NA values, such as None or :attr:`numpy.NaN`, get mapped to False + (unless you set ``pandas.options.mode.use_inf_as_na = True``). + NA values, such as None or :attr:`numpy.NaN`, gets mapped to False values. Returns From 744dc6162e8ab30a0a99b11df1874a1457fa9c51 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Tue, 13 Mar 2018 14:49:10 +0100 Subject: [PATCH 11/11] Update generic.py --- pandas/core/generic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 674b4cf4c92e7..bfb251b0995ec 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -5656,10 +5656,10 @@ def isnull(self): Detect existing (non-missing) values. Return a boolean same-sized object indicating if the values are not NA. - Non-missing values gets mapped to True. Characters such as empty + Non-missing values get mapped to True. Characters such as empty strings ``''`` or :attr:`numpy.inf` are not considered NA values (unless you set ``pandas.options.mode.use_inf_as_na = True``). - NA values, such as None or :attr:`numpy.NaN`, gets mapped to False + NA values, such as None or :attr:`numpy.NaN`, get mapped to False values. Returns