Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: add See Also section to groupby.DataFrameGroupBy.prod #59599

Merged
merged 6 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,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 @@ -252,7 +251,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
Loading