Skip to content

DOC: Fix PR01 errors in multiple files (#57438) #57504

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

Merged
merged 8 commits into from
Feb 21, 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
15 changes: 0 additions & 15 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
pandas.DatetimeIndex.std\
pandas.ExcelFile\
pandas.ExcelFile.parse\
pandas.Grouper\
pandas.HDFStore.append\
pandas.HDFStore.put\
pandas.Index.get_indexer_for\
Expand Down Expand Up @@ -1538,21 +1537,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
pandas.api.types.is_float\
pandas.api.types.is_hashable\
pandas.api.types.is_integer\
pandas.core.groupby.DataFrameGroupBy.cummax\
pandas.core.groupby.DataFrameGroupBy.cummin\
pandas.core.groupby.DataFrameGroupBy.cumprod\
pandas.core.groupby.DataFrameGroupBy.cumsum\
pandas.core.groupby.DataFrameGroupBy.filter\
pandas.core.groupby.DataFrameGroupBy.pct_change\
pandas.core.groupby.DataFrameGroupBy.rolling\
pandas.core.groupby.SeriesGroupBy.cummax\
pandas.core.groupby.SeriesGroupBy.cummin\
pandas.core.groupby.SeriesGroupBy.cumprod\
pandas.core.groupby.SeriesGroupBy.cumsum\
pandas.core.groupby.SeriesGroupBy.filter\
pandas.core.groupby.SeriesGroupBy.nunique\
pandas.core.groupby.SeriesGroupBy.pct_change\
pandas.core.groupby.SeriesGroupBy.rolling\
pandas.core.resample.Resampler.max\
pandas.core.resample.Resampler.min\
pandas.core.resample.Resampler.quantile\
Expand Down
34 changes: 13 additions & 21 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,15 +723,22 @@ def nunique(self, dropna: bool = True) -> Series | DataFrame:
"""
Return number of unique elements in the group.

Parameters
----------
dropna : bool, default True
Don't include NaN in the counts.

Returns
-------
Series
Number of unique values within each group.

Examples
See Also
--------
For SeriesGroupby:
core.resample.Resampler.nunique : Method nunique for Resampler.

Examples
--------
>>> lst = ["a", "a", "b", "b"]
>>> ser = pd.Series([1, 2, 3, 3], index=lst)
>>> ser
Expand All @@ -744,25 +751,6 @@ def nunique(self, dropna: bool = True) -> Series | DataFrame:
a 2
b 1
dtype: int64

For Resampler:

>>> ser = pd.Series(
... [1, 2, 3, 3],
... index=pd.DatetimeIndex(
... ["2023-01-01", "2023-01-15", "2023-02-01", "2023-02-15"]
... ),
... )
>>> ser
2023-01-01 1
2023-01-15 2
2023-02-01 3
2023-02-15 3
dtype: int64
>>> ser.resample("MS").nunique()
2023-01-01 2
2023-02-01 1
Freq: MS, dtype: int64
"""
ids, ngroups = self._grouper.group_info
val = self.obj._values
Expand Down Expand Up @@ -1942,6 +1930,10 @@ def filter(self, func, dropna: bool = True, *args, **kwargs) -> DataFrame:
dropna : bool
Drop groups that do not pass the filter. True by default; if False,
groups that evaluate False are filled with NaNs.
*args
Additional positional arguments to pass to `func`.
**kwargs
Additional keyword arguments to pass to `func`.

Returns
-------
Expand Down
58 changes: 58 additions & 0 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -4672,6 +4672,14 @@ def cumprod(self, *args, **kwargs) -> NDFrameT:
"""
Cumulative product for each group.

Parameters
----------
*args : tuple
Positional arguments to be passed to `func`.
**kwargs : dict
Additional/specific keyword arguments to be passed to the function,
such as `numeric_only` and `skipna`.

Returns
-------
Series or DataFrame
Expand Down Expand Up @@ -4722,6 +4730,14 @@ def cumsum(self, *args, **kwargs) -> NDFrameT:
"""
Cumulative sum for each group.

Parameters
----------
*args : tuple
Positional arguments to be passed to `func`.
**kwargs : dict
Additional/specific keyword arguments to be passed to the function,
such as `numeric_only` and `skipna`.

Returns
-------
Series or DataFrame
Expand Down Expand Up @@ -4776,6 +4792,14 @@ def cummin(
"""
Cumulative min for each group.

Parameters
----------
numeric_only : bool, default False
Include only `float`, `int` or `boolean` data.
**kwargs : dict, optional
Additional keyword arguments to be passed to the function, such as `skipna`,
to control whether NA/null values are ignored.

Returns
-------
Series or DataFrame
Expand Down Expand Up @@ -4838,6 +4862,14 @@ def cummax(
"""
Cumulative max for each group.

Parameters
----------
numeric_only : bool, default False
Include only `float`, `int` or `boolean` data.
**kwargs : dict, optional
Additional keyword arguments to be passed to the function, such as `skipna`,
to control whether NA/null values are ignored.

Returns
-------
Series or DataFrame
Expand Down Expand Up @@ -5134,6 +5166,32 @@ def pct_change(
"""
Calculate pct_change of each value to previous entry in group.

Parameters
----------
periods : int, default 1
Periods to shift for calculating percentage change. Comparing with
a period of 1 means adjacent elements are compared, whereas a period
of 2 compares every other element.

fill_method : FillnaOptions or None, default None
Specifies how to handle missing values after the initial shift
operation necessary for percentage change calculation. Users are
encouraged to handle missing values manually in future versions.
Valid options are:
- A FillnaOptions value ('ffill', 'bfill') for forward or backward filling.
- None to avoid filling.
Note: Usage is discouraged due to impending deprecation.

limit : int or None, default None
The maximum number of consecutive NA values to fill, based on the chosen
`fill_method`. Address NaN values prior to using `pct_change` as this
parameter is nearing deprecation.

freq : str, pandas offset object, or None, default None
The frequency increment for time series data (e.g., 'M' for month-end).
If None, the frequency is inferred from the index. Relevant for time
series data only.

Returns
-------
Series or DataFrame
Expand Down
4 changes: 4 additions & 0 deletions pandas/core/groupby/grouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class Grouper:

Parameters
----------
*args
Currently unused, reserved for future use.
**kwargs
Dictionary of the keyword arguments to pass to Grouper.
key : str, defaults to None
Groupby key, which selects the grouping column of the target.
level : name/number, defaults to None
Expand Down
33 changes: 31 additions & 2 deletions pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
NDFrame,
_shared_docs,
)
from pandas.core.groupby.generic import SeriesGroupBy
from pandas.core.groupby.groupby import (
BaseGroupBy,
GroupBy,
Expand Down Expand Up @@ -1358,8 +1357,38 @@ def ohlc(self):
return self._downsample("ohlc")

@final
@doc(SeriesGroupBy.nunique)
def nunique(self):
"""
Return number of unique elements in the group.

Returns
-------
Series
Number of unique values within each group.

See Also
--------
core.groupby.SeriesGroupBy.nunique : Method nunique for SeriesGroupBy.

Examples
--------
>>> ser = pd.Series(
... [1, 2, 3, 3],
... index=pd.DatetimeIndex(
... ["2023-01-01", "2023-01-15", "2023-02-01", "2023-02-15"]
... ),
... )
>>> ser
2023-01-01 1
2023-01-15 2
2023-02-01 3
2023-02-15 3
dtype: int64
>>> ser.resample("MS").nunique()
2023-01-01 2
2023-02-01 1
Freq: MS, dtype: int64
"""
return self._downsample("nunique")

@final
Expand Down