From 9e749e359cd5fc30d7f44cec4db8ac9af5b9ec30 Mon Sep 17 00:00:00 2001 From: Yuya Takashina Date: Fri, 11 Sep 2020 16:05:51 +0900 Subject: [PATCH 1/5] DOC: Fixed type hints for GroupBy.{any, all} The current documentation says the return value of GroupBy.all and GroupBy.any is `bool`. ``` def any(self, skipna: bool = True): """ Return True if any value in the group is truthful, else False. Parameters ---------- skipna : bool, default True Flag to ignore nan values during truth testing. Returns ------- bool """ ``` However, the actual returned type is DataFrame or Series (the same shape as `GroupBy.sum()`). ``` In [25]: df Out[25]: 0 1 2 3 0 1.0 0.0 0.0 0.0 1 0.0 1.0 0.0 0.0 2 0.0 0.0 1.0 0.0 3 0.0 0.0 0.0 1.0 In [26]: df.groupby(0).any() Out[26]: 1 2 3 0 0.0 True True True 1.0 False False False In [27]: type(df.groupby(0).any()) Out[27]: pandas.core.frame.DataFrame ``` This PR fixes the wrong type hints for `GroupBy.{any, all}`. --- pandas/core/groupby/groupby.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 1e3e56f4ff09f..7fddbd9f9916d 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -1330,7 +1330,7 @@ def any(self, skipna: bool = True): Returns ------- - bool + Series or DataFrame """ return self._bool_agg("any", skipna) @@ -1347,7 +1347,7 @@ def all(self, skipna: bool = True): Returns ------- - bool + Series or DataFrame """ return self._bool_agg("all", skipna) From 4de58962265a0e2d99ae8bb087238a649e2a3526 Mon Sep 17 00:00:00 2001 From: Yuya Takashina Date: Mon, 14 Sep 2020 16:06:39 +0900 Subject: [PATCH 2/5] Added description for the return value of GroupBy.{any, all} --- pandas/core/groupby/groupby.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 7fddbd9f9916d..33de67131962a 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -1331,6 +1331,7 @@ def any(self, skipna: bool = True): Returns ------- Series or DataFrame + DataFrame or Series of boolean values, which is True if any element is True within each group, False otherwise. """ return self._bool_agg("any", skipna) @@ -1348,6 +1349,7 @@ def all(self, skipna: bool = True): Returns ------- Series or DataFrame + DataFrame or Series of boolean values, which is True if all elements are True within each group, False otherwise. """ return self._bool_agg("all", skipna) From c9a15bc301f0906d1917d581a993ae78adac817b Mon Sep 17 00:00:00 2001 From: Yuya Takashina Date: Mon, 14 Sep 2020 16:11:10 +0900 Subject: [PATCH 3/5] Fixed violation of PEP8 --- pandas/core/groupby/groupby.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 33de67131962a..c55bd125f0fbe 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -1331,7 +1331,8 @@ def any(self, skipna: bool = True): Returns ------- Series or DataFrame - DataFrame or Series of boolean values, which is True if any element is True within each group, False otherwise. + DataFrame or Series of boolean values, which is True if any element is True + within each group, False otherwise. """ return self._bool_agg("any", skipna) @@ -1349,7 +1350,8 @@ def all(self, skipna: bool = True): Returns ------- Series or DataFrame - DataFrame or Series of boolean values, which is True if all elements are True within each group, False otherwise. + DataFrame or Series of boolean values, which is True if all elements are True + within each group, False otherwise. """ return self._bool_agg("all", skipna) From 7bfef62998ede51904b4905caca46dc590980c22 Mon Sep 17 00:00:00 2001 From: Yuya Takashina Date: Mon, 14 Sep 2020 16:36:34 +0900 Subject: [PATCH 4/5] Fixed violation of PEP8 --- pandas/core/groupby/groupby.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index c55bd125f0fbe..3bf0ecfd3b414 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -1331,8 +1331,8 @@ def any(self, skipna: bool = True): Returns ------- Series or DataFrame - DataFrame or Series of boolean values, which is True if any element is True - within each group, False otherwise. + DataFrame or Series of boolean values, which is True if any element is + True within each group, False otherwise. """ return self._bool_agg("any", skipna) @@ -1350,8 +1350,8 @@ def all(self, skipna: bool = True): Returns ------- Series or DataFrame - DataFrame or Series of boolean values, which is True if all elements are True - within each group, False otherwise. + DataFrame or Series of boolean values, which is True if all elements are + True within each group, False otherwise. """ return self._bool_agg("all", skipna) From b72ecc4a4dece122b4360ae3baa2db53f1c38d30 Mon Sep 17 00:00:00 2001 From: Yuya Takashina Date: Thu, 24 Sep 2020 01:35:54 +0900 Subject: [PATCH 5/5] Modified GroupBy.{any, all} docstring --- pandas/core/groupby/groupby.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 3bf0ecfd3b414..b3ec184d3fc72 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -1331,8 +1331,8 @@ def any(self, skipna: bool = True): Returns ------- Series or DataFrame - DataFrame or Series of boolean values, which is True if any element is - True within each group, False otherwise. + DataFrame or Series of boolean values, where a value is True if any element + is True within its respective group, False otherwise. """ return self._bool_agg("any", skipna) @@ -1350,8 +1350,8 @@ def all(self, skipna: bool = True): Returns ------- Series or DataFrame - DataFrame or Series of boolean values, which is True if all elements are - True within each group, False otherwise. + DataFrame or Series of boolean values, where a value is True if all elements + are True within its respective group, False otherwise. """ return self._bool_agg("all", skipna)