From 816b4aff36cd9b2688ee5e1237d91526452c3e2c Mon Sep 17 00:00:00 2001 From: ktseng37 Date: Sat, 24 Aug 2024 18:24:37 -0700 Subject: [PATCH 1/5] Update Groupby.prod --- pandas/core/groupby/groupby.py | 67 +++++++++++++++------------------- 1 file changed, 30 insertions(+), 37 deletions(-) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index b288dad63179f..a867737ce51b6 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -164,32 +164,6 @@ class providing the base-class of operations. to each row or column of a DataFrame. """ -_groupby_agg_method_template = """ -Compute {fname} of group values. - -Parameters ----------- -numeric_only : bool, default {no} - Include only float, int, boolean columns. - - .. versionchanged:: 2.0.0 - - numeric_only no longer accepts ``None``. - -min_count : int, default {mc} - The required number of valid values to perform the operation. If fewer - than ``min_count`` non-NA values are present the result will be NA. - -Returns -------- -Series or DataFrame - Computed {fname} of values within each group. - -Examples --------- -{example} -""" - _groupby_agg_method_engine_template = """ Compute {fname} of group values. @@ -3029,13 +3003,30 @@ def sum( return result @final - @doc( - _groupby_agg_method_template, - fname="prod", - no=False, - mc=0, - example=dedent( - """\ + def prod(self, numeric_only: bool = False, min_count: int = 0) -> NDFrameT: + """ + Compute prod of group values. + + Parameters + ---------- + numeric_only : bool, default False + Include only float, int, boolean columns. + + .. versionchanged:: 2.0.0 + + numeric_only no longer accepts ``None``. + + min_count : int, default 0 + The required number of valid values to perform the operation. If fewer + than ``min_count`` non-NA values are present the result will be NA. + + Returns + ------- + Series or DataFrame + Computed prod of values within each group. + + Examples + -------- For SeriesGroupBy: >>> lst = ['a', 'a', 'b', 'b'] @@ -3066,10 +3057,12 @@ def sum( b c a 1 16 10 - 2 30 72""" - ), - ) - def prod(self, numeric_only: bool = False, min_count: int = 0) -> NDFrameT: + 2 30 72 + + See Also + -------- + DataFrame.prod : Return the product of the values over the requested axis. + """ return self._agg_general( numeric_only=numeric_only, min_count=min_count, alias="prod", npfunc=np.prod ) From e43d2a9a8d22198b3fad261c58abcd66fbdba416 Mon Sep 17 00:00:00 2001 From: ktseng37 Date: Sat, 24 Aug 2024 18:28:13 -0700 Subject: [PATCH 2/5] update code_check list --- ci/code_checks.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index e9f4ee1f391a2..fac29106c4b37 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -259,7 +259,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.core.groupby.DataFrameGroupBy.nunique SA01" \ -i "pandas.core.groupby.DataFrameGroupBy.ohlc SA01" \ -i "pandas.core.groupby.DataFrameGroupBy.plot PR02" \ - -i "pandas.core.groupby.DataFrameGroupBy.prod SA01" \ -i "pandas.core.groupby.DataFrameGroupBy.sem SA01" \ -i "pandas.core.groupby.DataFrameGroupBy.sum SA01" \ -i "pandas.core.groupby.SeriesGroupBy.__iter__ RT03,SA01" \ From a42d9824f09e8abbfaa42dfaec0b3b3fa8075db2 Mon Sep 17 00:00:00 2001 From: ktseng37 Date: Sat, 24 Aug 2024 18:30:56 -0700 Subject: [PATCH 3/5] remove extra spaces --- 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 a867737ce51b6..40db83741655e 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -3025,6 +3025,10 @@ def prod(self, numeric_only: bool = False, min_count: int = 0) -> NDFrameT: Series or DataFrame Computed prod of values within each group. + See Also + -------- + DataFrame.prod : Return the product of the values over the requested axis. + Examples -------- For SeriesGroupBy: @@ -3058,10 +3062,6 @@ def prod(self, numeric_only: bool = False, min_count: int = 0) -> NDFrameT: a 1 16 10 2 30 72 - - See Also - -------- - DataFrame.prod : Return the product of the values over the requested axis. """ return self._agg_general( numeric_only=numeric_only, min_count=min_count, alias="prod", npfunc=np.prod From e10c70a1e7165236e9ed7fc428a1760750521f53 Mon Sep 17 00:00:00 2001 From: ktseng37 Date: Sat, 24 Aug 2024 18:58:28 -0700 Subject: [PATCH 4/5] fix errors --- ci/code_checks.sh | 1 - pandas/core/groupby/groupby.py | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index fac29106c4b37..b5a5eeefa8bbe 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -275,7 +275,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.core.groupby.SeriesGroupBy.nth PR02" \ -i "pandas.core.groupby.SeriesGroupBy.ohlc SA01" \ -i "pandas.core.groupby.SeriesGroupBy.plot PR02" \ - -i "pandas.core.groupby.SeriesGroupBy.prod SA01" \ -i "pandas.core.groupby.SeriesGroupBy.sem SA01" \ -i "pandas.core.groupby.SeriesGroupBy.sum SA01" \ -i "pandas.core.resample.Resampler.__iter__ RT03,SA01" \ diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 40db83741655e..515f15967cd53 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -3027,8 +3027,9 @@ def prod(self, numeric_only: bool = False, min_count: int = 0) -> NDFrameT: See Also -------- + Series.prod : Return the product of the values over the requested axis. DataFrame.prod : Return the product of the values over the requested axis. - + Examples -------- For SeriesGroupBy: From f5d640960b618589167a84a1554885bbdd76c30d Mon Sep 17 00:00:00 2001 From: ktseng37 Date: Mon, 26 Aug 2024 09:24:16 -0700 Subject: [PATCH 5/5] ruff formatting --- pandas/core/groupby/groupby.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 515f15967cd53..8c9c92594ebe7 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -3034,7 +3034,7 @@ def prod(self, numeric_only: bool = False, min_count: int = 0) -> NDFrameT: -------- For SeriesGroupBy: - >>> lst = ['a', 'a', 'b', 'b'] + >>> lst = ["a", "a", "b", "b"] >>> ser = pd.Series([1, 2, 3, 4], index=lst) >>> ser a 1 @@ -3050,8 +3050,11 @@ def prod(self, numeric_only: bool = False, min_count: int = 0) -> NDFrameT: For DataFrameGroupBy: >>> data = [[1, 8, 2], [1, 2, 5], [2, 5, 8], [2, 6, 9]] - >>> df = pd.DataFrame(data, columns=["a", "b", "c"], - ... index=["tiger", "leopard", "cheetah", "lion"]) + >>> df = pd.DataFrame( + ... data, + ... columns=["a", "b", "c"], + ... index=["tiger", "leopard", "cheetah", "lion"], + ... ) >>> df a b c tiger 1 8 2