diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 3927b91fe05c0..d614b8229ef12 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -118,13 +118,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.io.stata.StataReader.value_labels \ pandas.io.stata.StataReader.variable_labels \ pandas.io.stata.StataWriter.write_file \ - pandas.core.resample.Resampler.asfreq \ - pandas.core.resample.Resampler.count \ - pandas.core.resample.Resampler.nunique \ - pandas.core.resample.Resampler.max \ - pandas.core.resample.Resampler.mean \ - pandas.core.resample.Resampler.median \ - pandas.core.resample.Resampler.min \ pandas.core.resample.Resampler.ohlc \ pandas.core.resample.Resampler.prod \ pandas.core.resample.Resampler.size \ diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 78f8448cc7cb3..e3aa97b448fe1 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -633,6 +633,7 @@ def nunique(self, dropna: bool = True) -> Series | DataFrame: Examples -------- + For SeriesGroupby: >>> lst = ['a', 'a', 'b', 'b'] >>> ser = pd.Series([1, 2, 3, 3], index=lst) @@ -646,6 +647,21 @@ 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, _, _ = self.grouper.group_info diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 30f5f21f03658..40507f756a3d9 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -2167,6 +2167,21 @@ def count(self) -> NDFrameT: a 1 0 2 7 1 1 + + For Resampler: + + >>> ser = pd.Series([1, 2, 3, 4], 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 4 + dtype: int64 + >>> ser.resample('MS').count() + 2023-01-01 2 + 2023-02-01 2 + Freq: MS, dtype: int64 """ data = self._get_data_to_aggregate() ids, _, ngroups = self.grouper.group_info @@ -2350,6 +2365,20 @@ def median(self, numeric_only: bool = False): a b dog 3.0 4.0 mouse 7.0 3.0 + + For Resampler: + + >>> ser = pd.Series([1, 2, 3, 3, 4, 5], + ... index=pd.DatetimeIndex(['2023-01-01', + ... '2023-01-10', + ... '2023-01-15', + ... '2023-02-01', + ... '2023-02-10', + ... '2023-02-15'])) + >>> ser.resample('MS').median() + 2023-01-01 2.0 + 2023-02-01 4.0 + Freq: MS, dtype: float64 """ result = self._cython_agg_general( "median", diff --git a/pandas/core/resample.py b/pandas/core/resample.py index 9c8a9a0d63a14..f11b5dd9e7805 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -1083,6 +1083,22 @@ def asfreq(self, fill_value=None): -------- Series.asfreq: Convert TimeSeries to specified frequency. DataFrame.asfreq: Convert TimeSeries to specified frequency. + + Examples + -------- + + >>> ser = pd.Series([1, 2, 3, 4], index=pd.DatetimeIndex( + ... ['2023-01-01', '2023-01-31', '2023-02-01', '2023-02-28'])) + >>> ser + 2023-01-01 1 + 2023-01-31 2 + 2023-02-01 3 + 2023-02-28 4 + dtype: int64 + >>> ser.resample('MS').asfreq() + 2023-01-01 1 + 2023-02-01 3 + Freq: MS, dtype: int64 """ return self._upsample("asfreq", fill_value=fill_value) @@ -1116,6 +1132,29 @@ def min( *args, **kwargs, ): + """ + Compute min value of group. + + Returns + ------- + Series or DataFrame + + Examples + -------- + >>> ser = pd.Series([1, 2, 3, 4], 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 4 + dtype: int64 + >>> ser.resample('MS').min() + 2023-01-01 1 + 2023-02-01 3 + Freq: MS, dtype: int64 + """ + maybe_warn_args_and_kwargs(type(self), "min", args, kwargs) nv.validate_resampler_func("min", args, kwargs) return self._downsample("min", numeric_only=numeric_only, min_count=min_count) @@ -1127,6 +1166,28 @@ def max( *args, **kwargs, ): + """ + Compute max value of group. + + Returns + ------- + Series or DataFrame + + Examples + -------- + >>> ser = pd.Series([1, 2, 3, 4], 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 4 + dtype: int64 + >>> ser.resample('MS').max() + 2023-01-01 2 + 2023-02-01 4 + Freq: MS, dtype: int64 + """ maybe_warn_args_and_kwargs(type(self), "max", args, kwargs) nv.validate_resampler_func("max", args, kwargs) return self._downsample("max", numeric_only=numeric_only, min_count=min_count) @@ -1183,6 +1244,22 @@ def mean( ------- DataFrame or Series Mean of values within each group. + + Examples + -------- + + >>> ser = pd.Series([1, 2, 3, 4], 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 4 + dtype: int64 + >>> ser.resample('MS').mean() + 2023-01-01 1.5 + 2023-02-01 3.5 + Freq: MS, dtype: float64 """ maybe_warn_args_and_kwargs(type(self), "mean", args, kwargs) nv.validate_resampler_func("mean", args, kwargs)