Skip to content

Commit

Permalink
DOC: add See Also section to groupby.DataFrameGroupBy.prod (#59599)
Browse files Browse the repository at this point in the history
* Update Groupby.prod

* update code_check list

* remove extra spaces

* fix errors

* ruff formatting
  • Loading branch information
ktseng4096 authored Aug 26, 2024
1 parent 6fa4eb4 commit d31aa83
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 42 deletions.
2 changes: 0 additions & 2 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand All @@ -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" \
Expand Down
77 changes: 37 additions & 40 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
)
Expand Down

0 comments on commit d31aa83

Please sign in to comment.