Skip to content

Commit 0c86c86

Browse files
authored
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.
1 parent 945385d commit 0c86c86

File tree

1 file changed

+72
-4
lines changed

1 file changed

+72
-4
lines changed

pandas/core/groupby/generic.py

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,22 +1538,64 @@ def idxmax(self, skipna: bool = True) -> Series:
15381538
"""
15391539
return self._idxmax_idxmin("idxmax", skipna=skipna)
15401540

1541-
@doc(Series.corr.__doc__)
15421541
def corr(
15431542
self,
15441543
other: Series,
15451544
method: CorrelationMethod = "pearson",
15461545
min_periods: int | None = None,
15471546
) -> Series:
1547+
"""
1548+
Compute correlation between each group and another Series.
1549+
1550+
Parameters
1551+
----------
1552+
other : Series
1553+
Series to compute correlation with.
1554+
method : {'pearson', 'kendall', 'spearman'}, default 'pearson'
1555+
Method of correlation to use.
1556+
min_periods : int, optional
1557+
Minimum number of observations required per pair of columns to
1558+
have a valid result.
1559+
1560+
Returns
1561+
-------
1562+
Series
1563+
Correlation value for each group.
1564+
1565+
See Also
1566+
--------
1567+
Series.corr : Equivalent method on ``Series``.
1568+
"""
15481569
result = self._op_via_apply(
15491570
"corr", other=other, method=method, min_periods=min_periods
15501571
)
15511572
return result
15521573

1553-
@doc(Series.cov.__doc__)
15541574
def cov(
15551575
self, other: Series, min_periods: int | None = None, ddof: int | None = 1
15561576
) -> Series:
1577+
"""
1578+
Compute covariance between each group and another Series.
1579+
1580+
Parameters
1581+
----------
1582+
other : Series
1583+
Series to compute covariance with.
1584+
min_periods : int, optional
1585+
Minimum number of observations required per pair of columns to
1586+
have a valid result.
1587+
ddof : int, optional
1588+
Delta degrees of freedom for variance calculation.
1589+
1590+
Returns
1591+
-------
1592+
Series
1593+
Covariance value for each group.
1594+
1595+
See Also
1596+
--------
1597+
Series.cov : Equivalent method on ``Series``.
1598+
"""
15571599
result = self._op_via_apply(
15581600
"cov", other=other, min_periods=min_periods, ddof=ddof
15591601
)
@@ -1607,7 +1649,6 @@ def is_monotonic_decreasing(self) -> Series:
16071649
"""
16081650
return self.apply(lambda ser: ser.is_monotonic_decreasing)
16091651

1610-
@doc(Series.hist.__doc__)
16111652
def hist(
16121653
self,
16131654
by=None,
@@ -1623,6 +1664,24 @@ def hist(
16231664
legend: bool = False,
16241665
**kwargs,
16251666
):
1667+
"""
1668+
Draw histogram for each group's values using :meth:`Series.hist` API.
1669+
1670+
Parameters
1671+
----------
1672+
by, ax, grid, xlabelsize, xrot, ylabelsize, yrot, figsize, bins, backend,
1673+
legend, **kwargs
1674+
See :meth:`Series.hist` for full parameter descriptions.
1675+
1676+
Returns
1677+
-------
1678+
matplotlib.axes.Axes or ndarray of Axes
1679+
The returned matplotlib axes or array of axes depending on input.
1680+
1681+
See Also
1682+
--------
1683+
Series.hist : Equivalent histogram plotting method on Series.
1684+
"""
16261685
result = self._op_via_apply(
16271686
"hist",
16281687
by=by,
@@ -1641,8 +1700,17 @@ def hist(
16411700
return result
16421701

16431702
@property
1644-
@doc(Series.dtype.__doc__)
16451703
def dtype(self) -> Series:
1704+
"""
1705+
Return the dtype object of the underlying data for each group.
1706+
1707+
Mirrors :meth:`Series.dtype` applied group-wise.
1708+
1709+
Returns
1710+
-------
1711+
Series
1712+
Dtype of each group's values.
1713+
"""
16461714
return self.apply(lambda ser: ser.dtype)
16471715

16481716
def unique(self) -> Series:

0 commit comments

Comments
 (0)