From 7abd7593c8b3904eedf3c65c88ac8c484d9833fe Mon Sep 17 00:00:00 2001 From: MasonGallo Date: Wed, 24 Feb 2016 15:04:56 -0500 Subject: [PATCH 1/4] Add examples and notes to empty documentation --- pandas/core/generic.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 14d788fdded7e..5260e7370b4e5 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -842,7 +842,25 @@ def __contains__(self, key): @property def empty(self): - """True if NDFrame is entirely empty [no items]""" + """True if NDFrame is entirely empty [no items], i.e. all of the axes + are of length 0. + + Notes + ----- + If NDFrame contains only NaNs, it is still not considered empty. + + Examples + -------- + + >>> # containing only NaNs does not make the df empty + >>> df = pd.DataFrame({'A' : [np.nan]}) + >>> df.empty + False + >>> # if we drop NAs, the axes are now of length 0 + >>> df.dropna().empty + True + + """ return not all(len(self._get_axis(a)) > 0 for a in self._AXIS_ORDERS) def __nonzero__(self): From f9ef74aae78567cda62f0dcd643e9ece9dbcab34 Mon Sep 17 00:00:00 2001 From: MasonGallo Date: Wed, 24 Feb 2016 15:23:09 -0500 Subject: [PATCH 2/4] Change any to all --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 5260e7370b4e5..0e6e1d54a3770 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -842,7 +842,7 @@ def __contains__(self, key): @property def empty(self): - """True if NDFrame is entirely empty [no items], i.e. all of the axes + """True if NDFrame is entirely empty [no items], i.e. any of the axes are of length 0. Notes From 59da0f9521f488301025557ee303313735802732 Mon Sep 17 00:00:00 2001 From: MasonGallo Date: Wed, 24 Feb 2016 21:00:12 -0500 Subject: [PATCH 3/4] Address feedback to include examples of empty and non-empty with NaNs --- pandas/core/generic.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 0e6e1d54a3770..5f3f4dd658655 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -847,16 +847,30 @@ def empty(self): Notes ----- - If NDFrame contains only NaNs, it is still not considered empty. + If NDFrame contains only NaNs, it is still not considered empty. See + the example below. Examples -------- + An example of an actual empty DataFrame. Notice the index is empty: + + >>> df_empty = pd.DataFrame({'A' : []}) + >>> df_empty + Empty DataFrame + Columns: [A] + Index: [] + >>> df_empty.empty + True + + If we only have NaNs in our DataFrame, it is not considered empty! We + will need to drop the NaNs to make the DataFrame empty: - >>> # containing only NaNs does not make the df empty >>> df = pd.DataFrame({'A' : [np.nan]}) + >>> df + A + 0 NaN >>> df.empty False - >>> # if we drop NAs, the axes are now of length 0 >>> df.dropna().empty True From 30f09eadfe0dbcc50cbe5d0919660ca5b36e9c9d Mon Sep 17 00:00:00 2001 From: MasonGallo Date: Thu, 25 Feb 2016 16:43:16 -0500 Subject: [PATCH 4/4] Add see also section and replace i.e. with meaning --- pandas/core/generic.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 5f3f4dd658655..f850bfba4f90e 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -842,8 +842,8 @@ def __contains__(self, key): @property def empty(self): - """True if NDFrame is entirely empty [no items], i.e. any of the axes - are of length 0. + """True if NDFrame is entirely empty [no items], meaning any of the + axes are of length 0. Notes ----- @@ -874,6 +874,10 @@ def empty(self): >>> df.dropna().empty True + See also + -------- + pandas.Series.dropna + pandas.DataFrame.dropna """ return not all(len(self._get_axis(a)) > 0 for a in self._AXIS_ORDERS)