From d31aa834cef5a433938933f75ca20f0268a4ea83 Mon Sep 17 00:00:00 2001 From: ktseng4096 <32848825+ktseng4096@users.noreply.github.com> Date: Mon, 26 Aug 2024 11:33:43 -0700 Subject: [PATCH] DOC: add See Also section to groupby.DataFrameGroupBy.prod (#59599) * Update Groupby.prod * update code_check list * remove extra spaces * fix errors * ruff formatting --- ci/code_checks.sh | 2 - pandas/core/groupby/groupby.py | 77 ++++++++++++++++------------------ 2 files changed, 37 insertions(+), 42 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 4ddc429f2a51c..76cc02652ec24 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -226,7 +226,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" \ @@ -243,7 +242,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 b288dad63179f..8c9c92594ebe7 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,16 +3003,38 @@ 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. + + 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: - >>> lst = ['a', 'a', 'b', 'b'] + >>> lst = ["a", "a", "b", "b"] >>> ser = pd.Series([1, 2, 3, 4], index=lst) >>> ser a 1 @@ -3054,8 +3050,11 @@ def sum( 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 @@ -3066,10 +3065,8 @@ 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 + """ return self._agg_general( numeric_only=numeric_only, min_count=min_count, alias="prod", npfunc=np.prod )