Skip to content

Commit 190aed6

Browse files
authored
DOC: replace @doc in pandas/core/groupby/generic.py (#63251)
1 parent 7f91ec4 commit 190aed6

File tree

1 file changed

+112
-4
lines changed

1 file changed

+112
-4
lines changed

pandas/core/groupby/generic.py

Lines changed: 112 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,22 +1538,76 @@ 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+
1569+
Examples
1570+
--------
1571+
>>> s = pd.Series([1, 2, 3, 4], index=[0, 0, 1, 1])
1572+
>>> g = s.groupby([0, 0, 1, 1])
1573+
>>> g.corr() # doctest: +SKIP
1574+
"""
15481575
result = self._op_via_apply(
15491576
"corr", other=other, method=method, min_periods=min_periods
15501577
)
15511578
return result
15521579

1553-
@doc(Series.cov.__doc__)
15541580
def cov(
15551581
self, other: Series, min_periods: int | None = None, ddof: int | None = 1
15561582
) -> Series:
1583+
"""
1584+
Compute covariance between each group and another Series.
1585+
1586+
Parameters
1587+
----------
1588+
other : Series
1589+
Series to compute covariance with.
1590+
min_periods : int, optional
1591+
Minimum number of observations required per pair of columns to
1592+
have a valid result.
1593+
ddof : int, optional
1594+
Delta degrees of freedom for variance calculation.
1595+
1596+
Returns
1597+
-------
1598+
Series
1599+
Covariance value for each group.
1600+
1601+
See Also
1602+
--------
1603+
Series.cov : Equivalent method on ``Series``.
1604+
1605+
Examples
1606+
--------
1607+
>>> s = pd.Series([1, 2, 3, 4], index=[0, 0, 1, 1])
1608+
>>> g = s.groupby([0, 0, 1, 1])
1609+
>>> g.cov() # doctest: +SKIP
1610+
"""
15571611
result = self._op_via_apply(
15581612
"cov", other=other, min_periods=min_periods, ddof=ddof
15591613
)
@@ -1607,7 +1661,6 @@ def is_monotonic_decreasing(self) -> Series:
16071661
"""
16081662
return self.apply(lambda ser: ser.is_monotonic_decreasing)
16091663

1610-
@doc(Series.hist.__doc__)
16111664
def hist(
16121665
self,
16131666
by=None,
@@ -1623,6 +1676,52 @@ def hist(
16231676
legend: bool = False,
16241677
**kwargs,
16251678
):
1679+
"""
1680+
Draw histogram for each group's values using :meth:`Series.hist` API.
1681+
1682+
Parameters
1683+
----------
1684+
by : object, optional
1685+
Grouping key.
1686+
ax : matplotlib.axes.Axes, optional
1687+
Axis to draw the histogram on.
1688+
grid : bool, default True
1689+
Show axis grid lines.
1690+
xlabelsize : int, default None
1691+
X axis label size.
1692+
xrot : float, default None
1693+
Rotation for x ticks.
1694+
ylabelsize : int, default None
1695+
Y axis label size.
1696+
yrot : float, default None
1697+
Rotation for y ticks.
1698+
figsize : tuple, optional
1699+
Figure size in inches.
1700+
bins : int or sequence, default 10
1701+
Number of histogram bins or bin edges.
1702+
backend : str or callable or None, optional
1703+
Plotting backend to use (e.g. 'matplotlib'). If None, use the default
1704+
plotting backend.
1705+
legend : bool, default False
1706+
Whether to draw the legend.
1707+
**kwargs
1708+
Additional keyword arguments passed to :meth:`Series.hist`.
1709+
1710+
Returns
1711+
-------
1712+
matplotlib.axes.Axes or ndarray of Axes
1713+
The returned matplotlib axes or array of axes depending on input.
1714+
1715+
See Also
1716+
--------
1717+
Series.hist : Equivalent histogram plotting method on Series.
1718+
1719+
Examples
1720+
--------
1721+
>>> df = pd.DataFrame({"val": [1, 2, 2, 3, 3, 3]}, index=[0, 0, 1, 1, 2, 2])
1722+
>>> g = df["val"].groupby([0, 0, 1, 1, 2, 2])
1723+
>>> g.hist() # doctest: +SKIP
1724+
"""
16261725
result = self._op_via_apply(
16271726
"hist",
16281727
by=by,
@@ -1641,8 +1740,17 @@ def hist(
16411740
return result
16421741

16431742
@property
1644-
@doc(Series.dtype.__doc__)
16451743
def dtype(self) -> Series:
1744+
"""
1745+
Return the dtype object of the underlying data for each group.
1746+
1747+
Mirrors :meth:`Series.dtype` applied group-wise.
1748+
1749+
Returns
1750+
-------
1751+
Series
1752+
Dtype of each group's values.
1753+
"""
16461754
return self.apply(lambda ser: ser.dtype)
16471755

16481756
def unique(self) -> Series:

0 commit comments

Comments
 (0)