From 0c86c86bd3699d5306f97803cfb42c4cb26c3bed Mon Sep 17 00:00:00 2001 From: Jixun Sun <160219251+AnonToky@users.noreply.github.com> Date: Tue, 2 Dec 2025 19:24:57 +0800 Subject: [PATCH 1/5] Add docstrings for correlation and covariance methods Added docstrings for corr, cov, hist, and dtype methods to provide detailed descriptions of parameters and return values. --- pandas/core/groupby/generic.py | 76 ++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 4 deletions(-) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 93e04fe61555e..712a5cf51571a 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -1538,22 +1538,64 @@ def idxmax(self, skipna: bool = True) -> Series: """ return self._idxmax_idxmin("idxmax", skipna=skipna) - @doc(Series.corr.__doc__) def corr( self, other: Series, method: CorrelationMethod = "pearson", min_periods: int | None = None, ) -> Series: + """ + Compute correlation between each group and another Series. + + Parameters + ---------- + other : Series + Series to compute correlation with. + method : {'pearson', 'kendall', 'spearman'}, default 'pearson' + Method of correlation to use. + min_periods : int, optional + Minimum number of observations required per pair of columns to + have a valid result. + + Returns + ------- + Series + Correlation value for each group. + + See Also + -------- + Series.corr : Equivalent method on ``Series``. + """ result = self._op_via_apply( "corr", other=other, method=method, min_periods=min_periods ) return result - @doc(Series.cov.__doc__) def cov( self, other: Series, min_periods: int | None = None, ddof: int | None = 1 ) -> Series: + """ + Compute covariance between each group and another Series. + + Parameters + ---------- + other : Series + Series to compute covariance with. + min_periods : int, optional + Minimum number of observations required per pair of columns to + have a valid result. + ddof : int, optional + Delta degrees of freedom for variance calculation. + + Returns + ------- + Series + Covariance value for each group. + + See Also + -------- + Series.cov : Equivalent method on ``Series``. + """ result = self._op_via_apply( "cov", other=other, min_periods=min_periods, ddof=ddof ) @@ -1607,7 +1649,6 @@ def is_monotonic_decreasing(self) -> Series: """ return self.apply(lambda ser: ser.is_monotonic_decreasing) - @doc(Series.hist.__doc__) def hist( self, by=None, @@ -1623,6 +1664,24 @@ def hist( legend: bool = False, **kwargs, ): + """ + Draw histogram for each group's values using :meth:`Series.hist` API. + + Parameters + ---------- + by, ax, grid, xlabelsize, xrot, ylabelsize, yrot, figsize, bins, backend, + legend, **kwargs + See :meth:`Series.hist` for full parameter descriptions. + + Returns + ------- + matplotlib.axes.Axes or ndarray of Axes + The returned matplotlib axes or array of axes depending on input. + + See Also + -------- + Series.hist : Equivalent histogram plotting method on Series. + """ result = self._op_via_apply( "hist", by=by, @@ -1641,8 +1700,17 @@ def hist( return result @property - @doc(Series.dtype.__doc__) def dtype(self) -> Series: + """ + Return the dtype object of the underlying data for each group. + + Mirrors :meth:`Series.dtype` applied group-wise. + + Returns + ------- + Series + Dtype of each group's values. + """ return self.apply(lambda ser: ser.dtype) def unique(self) -> Series: From 91e55c7e63cf9267b8d742ba8bfc792e3d140fa2 Mon Sep 17 00:00:00 2001 From: Jixun Sun <160219251+AnonToky@users.noreply.github.com> Date: Tue, 2 Dec 2025 20:21:41 +0800 Subject: [PATCH 2/5] Update generic.py --- pandas/core/groupby/generic.py | 50 ++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 712a5cf51571a..d68fb0dccd899 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -1565,6 +1565,14 @@ def corr( See Also -------- Series.corr : Equivalent method on ``Series``. + + + Examples + -------- + >>> import pandas as pd + >>> s = pd.Series([1, 2, 3, 4], index=[0, 0, 1, 1]) + >>> g = s.groupby([0, 0, 1, 1]) + >>> g.corr() # doctest: +SKIP """ result = self._op_via_apply( "corr", other=other, method=method, min_periods=min_periods @@ -1595,6 +1603,13 @@ def cov( See Also -------- Series.cov : Equivalent method on ``Series``. + + Examples + -------- + >>> import pandas as pd + >>> s = pd.Series([1, 2, 3, 4], index=[0, 0, 1, 1]) + >>> g = s.groupby([0, 0, 1, 1]) + >>> g.cov() # doctest: +SKIP """ result = self._op_via_apply( "cov", other=other, min_periods=min_periods, ddof=ddof @@ -1669,9 +1684,31 @@ def hist( Parameters ---------- - by, ax, grid, xlabelsize, xrot, ylabelsize, yrot, figsize, bins, backend, - legend, **kwargs - See :meth:`Series.hist` for full parameter descriptions. + by : object, optional + Grouping key. + ax : matplotlib.axes.Axes, optional + Axis to draw the histogram on. + grid : bool, default True + Show axis grid lines. + xlabelsize : int, default None + X axis label size. + xrot : float, default None + Rotation for x ticks. + ylabelsize : int, default None + Y axis label size. + yrot : float, default None + Rotation for y ticks. + figsize : tuple, optional + Figure size in inches. + bins : int or sequence, default 10 + Number of histogram bins or bin edges. + backend : str or callable or None, optional + Plotting backend to use (e.g. 'matplotlib'). If None, use the default + plotting backend. + legend : bool, default False + Whether to draw the legend. + **kwargs + Additional keyword arguments passed to :meth:`Series.hist`. Returns ------- @@ -1681,6 +1718,13 @@ def hist( See Also -------- Series.hist : Equivalent histogram plotting method on Series. + + Examples + -------- + >>> import pandas as pd + >>> df = pd.DataFrame({"val": [1, 2, 2, 3, 3, 3]}, index=[0, 0, 1, 1, 2, 2]) + >>> g = df["val"].groupby([0, 0, 1, 1, 2, 2]) + >>> g.hist() # doctest: +SKIP """ result = self._op_via_apply( "hist", From dd4394be2b7641e476665b3362fc84b19e64cf5e Mon Sep 17 00:00:00 2001 From: Jixun Sun <160219251+AnonToky@users.noreply.github.com> Date: Tue, 2 Dec 2025 20:27:17 +0800 Subject: [PATCH 3/5] Update generic.py --- pandas/core/groupby/generic.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index d68fb0dccd899..eed00f5d6e4c6 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -1567,12 +1567,12 @@ def corr( Series.corr : Equivalent method on ``Series``. - Examples - -------- - >>> import pandas as pd - >>> s = pd.Series([1, 2, 3, 4], index=[0, 0, 1, 1]) - >>> g = s.groupby([0, 0, 1, 1]) - >>> g.corr() # doctest: +SKIP + Examples + -------- + >>> import pandas as pd + >>> s = pd.Series([1, 2, 3, 4], index=[0, 0, 1, 1]) + >>> g = s.groupby([0, 0, 1, 1]) + >>> g.corr() # doctest: +SKIP """ result = self._op_via_apply( "corr", other=other, method=method, min_periods=min_periods From 445df68c3c6687a42213cad1142e93c81ae87c1e Mon Sep 17 00:00:00 2001 From: Jixun Sun <160219251+AnonToky@users.noreply.github.com> Date: Tue, 2 Dec 2025 21:13:03 +0800 Subject: [PATCH 4/5] Clean up docstring formatting Removed unnecessary blank line in docstring. --- pandas/core/groupby/generic.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index eed00f5d6e4c6..6c22b3413d00d 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -1566,7 +1566,6 @@ def corr( -------- Series.corr : Equivalent method on ``Series``. - Examples -------- >>> import pandas as pd From 7eff767375d56ba257e5d1bcbf677036a3a50800 Mon Sep 17 00:00:00 2001 From: Jixun Sun <160219251+AnonToky@users.noreply.github.com> Date: Tue, 2 Dec 2025 22:46:35 +0800 Subject: [PATCH 5/5] Update generic.py --- pandas/core/groupby/generic.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 6c22b3413d00d..58f6049601fe9 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -1568,7 +1568,6 @@ def corr( Examples -------- - >>> import pandas as pd >>> s = pd.Series([1, 2, 3, 4], index=[0, 0, 1, 1]) >>> g = s.groupby([0, 0, 1, 1]) >>> g.corr() # doctest: +SKIP @@ -1605,7 +1604,6 @@ def cov( Examples -------- - >>> import pandas as pd >>> s = pd.Series([1, 2, 3, 4], index=[0, 0, 1, 1]) >>> g = s.groupby([0, 0, 1, 1]) >>> g.cov() # doctest: +SKIP @@ -1720,7 +1718,6 @@ def hist( Examples -------- - >>> import pandas as pd >>> df = pd.DataFrame({"val": [1, 2, 2, 3, 3, 3]}, index=[0, 0, 1, 1, 2, 2]) >>> g = df["val"].groupby([0, 0, 1, 1, 2, 2]) >>> g.hist() # doctest: +SKIP