Skip to content

Commit 2493681

Browse files
authored
DOC: Fix PR01 errors in multiple files (#57438) (#57504)
* DOC: Fix PR01 errors in multiple files (#57438) Fixed PR01 errors (#57438) and added parameter descriptions for: - `pandas.Grouper` - `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.cumprod` Fixed functions also removed from code_checks.sh * Updated formatting * Corrected E501 formatting * Remove trailing whitespaces * Fix PR02 error from docstring inheritance for resampler nunique method Resolved a PR02 documentation error arising from the inherited `nunique` method docstring within `groupby.SeriesGroupBy.nunique`. The issue was due to the `resample.Resampler.nunique` method lacking a `dropna` parameter, which is present in the inherited docstring. - Introduced `_nunique_extra_params` to dynamically insert parameter documentation only where applicable (i.e. where `groupby.SeriesGroupBy.nunique`is). * Resolve request * Undo mistake * Remove unnecessary import to fix ruff check
1 parent 2b568ce commit 2493681

File tree

5 files changed

+106
-38
lines changed

5 files changed

+106
-38
lines changed

Diff for: ci/code_checks.sh

-15
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
14771477
pandas.DatetimeIndex.std\
14781478
pandas.ExcelFile\
14791479
pandas.ExcelFile.parse\
1480-
pandas.Grouper\
14811480
pandas.HDFStore.append\
14821481
pandas.HDFStore.put\
14831482
pandas.Index.get_indexer_for\
@@ -1538,21 +1537,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
15381537
pandas.api.types.is_float\
15391538
pandas.api.types.is_hashable\
15401539
pandas.api.types.is_integer\
1541-
pandas.core.groupby.DataFrameGroupBy.cummax\
1542-
pandas.core.groupby.DataFrameGroupBy.cummin\
1543-
pandas.core.groupby.DataFrameGroupBy.cumprod\
1544-
pandas.core.groupby.DataFrameGroupBy.cumsum\
1545-
pandas.core.groupby.DataFrameGroupBy.filter\
1546-
pandas.core.groupby.DataFrameGroupBy.pct_change\
1547-
pandas.core.groupby.DataFrameGroupBy.rolling\
1548-
pandas.core.groupby.SeriesGroupBy.cummax\
1549-
pandas.core.groupby.SeriesGroupBy.cummin\
1550-
pandas.core.groupby.SeriesGroupBy.cumprod\
1551-
pandas.core.groupby.SeriesGroupBy.cumsum\
15521540
pandas.core.groupby.SeriesGroupBy.filter\
1553-
pandas.core.groupby.SeriesGroupBy.nunique\
1554-
pandas.core.groupby.SeriesGroupBy.pct_change\
1555-
pandas.core.groupby.SeriesGroupBy.rolling\
15561541
pandas.core.resample.Resampler.max\
15571542
pandas.core.resample.Resampler.min\
15581543
pandas.core.resample.Resampler.quantile\

Diff for: pandas/core/groupby/generic.py

+13-21
Original file line numberDiff line numberDiff line change
@@ -723,15 +723,22 @@ def nunique(self, dropna: bool = True) -> Series | DataFrame:
723723
"""
724724
Return number of unique elements in the group.
725725
726+
Parameters
727+
----------
728+
dropna : bool, default True
729+
Don't include NaN in the counts.
730+
726731
Returns
727732
-------
728733
Series
729734
Number of unique values within each group.
730735
731-
Examples
736+
See Also
732737
--------
733-
For SeriesGroupby:
738+
core.resample.Resampler.nunique : Method nunique for Resampler.
734739
740+
Examples
741+
--------
735742
>>> lst = ["a", "a", "b", "b"]
736743
>>> ser = pd.Series([1, 2, 3, 3], index=lst)
737744
>>> ser
@@ -744,25 +751,6 @@ def nunique(self, dropna: bool = True) -> Series | DataFrame:
744751
a 2
745752
b 1
746753
dtype: int64
747-
748-
For Resampler:
749-
750-
>>> ser = pd.Series(
751-
... [1, 2, 3, 3],
752-
... index=pd.DatetimeIndex(
753-
... ["2023-01-01", "2023-01-15", "2023-02-01", "2023-02-15"]
754-
... ),
755-
... )
756-
>>> ser
757-
2023-01-01 1
758-
2023-01-15 2
759-
2023-02-01 3
760-
2023-02-15 3
761-
dtype: int64
762-
>>> ser.resample("MS").nunique()
763-
2023-01-01 2
764-
2023-02-01 1
765-
Freq: MS, dtype: int64
766754
"""
767755
ids, ngroups = self._grouper.group_info
768756
val = self.obj._values
@@ -1942,6 +1930,10 @@ def filter(self, func, dropna: bool = True, *args, **kwargs) -> DataFrame:
19421930
dropna : bool
19431931
Drop groups that do not pass the filter. True by default; if False,
19441932
groups that evaluate False are filled with NaNs.
1933+
*args
1934+
Additional positional arguments to pass to `func`.
1935+
**kwargs
1936+
Additional keyword arguments to pass to `func`.
19451937
19461938
Returns
19471939
-------

Diff for: pandas/core/groupby/groupby.py

+58
Original file line numberDiff line numberDiff line change
@@ -4672,6 +4672,14 @@ def cumprod(self, *args, **kwargs) -> NDFrameT:
46724672
"""
46734673
Cumulative product for each group.
46744674
4675+
Parameters
4676+
----------
4677+
*args : tuple
4678+
Positional arguments to be passed to `func`.
4679+
**kwargs : dict
4680+
Additional/specific keyword arguments to be passed to the function,
4681+
such as `numeric_only` and `skipna`.
4682+
46754683
Returns
46764684
-------
46774685
Series or DataFrame
@@ -4722,6 +4730,14 @@ def cumsum(self, *args, **kwargs) -> NDFrameT:
47224730
"""
47234731
Cumulative sum for each group.
47244732
4733+
Parameters
4734+
----------
4735+
*args : tuple
4736+
Positional arguments to be passed to `func`.
4737+
**kwargs : dict
4738+
Additional/specific keyword arguments to be passed to the function,
4739+
such as `numeric_only` and `skipna`.
4740+
47254741
Returns
47264742
-------
47274743
Series or DataFrame
@@ -4776,6 +4792,14 @@ def cummin(
47764792
"""
47774793
Cumulative min for each group.
47784794
4795+
Parameters
4796+
----------
4797+
numeric_only : bool, default False
4798+
Include only `float`, `int` or `boolean` data.
4799+
**kwargs : dict, optional
4800+
Additional keyword arguments to be passed to the function, such as `skipna`,
4801+
to control whether NA/null values are ignored.
4802+
47794803
Returns
47804804
-------
47814805
Series or DataFrame
@@ -4838,6 +4862,14 @@ def cummax(
48384862
"""
48394863
Cumulative max for each group.
48404864
4865+
Parameters
4866+
----------
4867+
numeric_only : bool, default False
4868+
Include only `float`, `int` or `boolean` data.
4869+
**kwargs : dict, optional
4870+
Additional keyword arguments to be passed to the function, such as `skipna`,
4871+
to control whether NA/null values are ignored.
4872+
48414873
Returns
48424874
-------
48434875
Series or DataFrame
@@ -5134,6 +5166,32 @@ def pct_change(
51345166
"""
51355167
Calculate pct_change of each value to previous entry in group.
51365168
5169+
Parameters
5170+
----------
5171+
periods : int, default 1
5172+
Periods to shift for calculating percentage change. Comparing with
5173+
a period of 1 means adjacent elements are compared, whereas a period
5174+
of 2 compares every other element.
5175+
5176+
fill_method : FillnaOptions or None, default None
5177+
Specifies how to handle missing values after the initial shift
5178+
operation necessary for percentage change calculation. Users are
5179+
encouraged to handle missing values manually in future versions.
5180+
Valid options are:
5181+
- A FillnaOptions value ('ffill', 'bfill') for forward or backward filling.
5182+
- None to avoid filling.
5183+
Note: Usage is discouraged due to impending deprecation.
5184+
5185+
limit : int or None, default None
5186+
The maximum number of consecutive NA values to fill, based on the chosen
5187+
`fill_method`. Address NaN values prior to using `pct_change` as this
5188+
parameter is nearing deprecation.
5189+
5190+
freq : str, pandas offset object, or None, default None
5191+
The frequency increment for time series data (e.g., 'M' for month-end).
5192+
If None, the frequency is inferred from the index. Relevant for time
5193+
series data only.
5194+
51375195
Returns
51385196
-------
51395197
Series or DataFrame

Diff for: pandas/core/groupby/grouper.py

+4
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ class Grouper:
6868
6969
Parameters
7070
----------
71+
*args
72+
Currently unused, reserved for future use.
73+
**kwargs
74+
Dictionary of the keyword arguments to pass to Grouper.
7175
key : str, defaults to None
7276
Groupby key, which selects the grouping column of the target.
7377
level : name/number, defaults to None

Diff for: pandas/core/resample.py

+31-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
NDFrame,
6060
_shared_docs,
6161
)
62-
from pandas.core.groupby.generic import SeriesGroupBy
6362
from pandas.core.groupby.groupby import (
6463
BaseGroupBy,
6564
GroupBy,
@@ -1358,8 +1357,38 @@ def ohlc(self):
13581357
return self._downsample("ohlc")
13591358

13601359
@final
1361-
@doc(SeriesGroupBy.nunique)
13621360
def nunique(self):
1361+
"""
1362+
Return number of unique elements in the group.
1363+
1364+
Returns
1365+
-------
1366+
Series
1367+
Number of unique values within each group.
1368+
1369+
See Also
1370+
--------
1371+
core.groupby.SeriesGroupBy.nunique : Method nunique for SeriesGroupBy.
1372+
1373+
Examples
1374+
--------
1375+
>>> ser = pd.Series(
1376+
... [1, 2, 3, 3],
1377+
... index=pd.DatetimeIndex(
1378+
... ["2023-01-01", "2023-01-15", "2023-02-01", "2023-02-15"]
1379+
... ),
1380+
... )
1381+
>>> ser
1382+
2023-01-01 1
1383+
2023-01-15 2
1384+
2023-02-01 3
1385+
2023-02-15 3
1386+
dtype: int64
1387+
>>> ser.resample("MS").nunique()
1388+
2023-01-01 2
1389+
2023-02-01 1
1390+
Freq: MS, dtype: int64
1391+
"""
13631392
return self._downsample("nunique")
13641393

13651394
@final

0 commit comments

Comments
 (0)