Skip to content

Commit dd105a6

Browse files
committed
DOC: Fix remaining validation errors RT01 (pandas-dev#25356)
1 parent e1ae56c commit dd105a6

File tree

13 files changed

+248
-11
lines changed

13 files changed

+248
-11
lines changed

pandas/core/accessor.py

+5
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ def decorator(accessor):
206206
Name under which the accessor should be registered. A warning is issued
207207
if this name conflicts with a preexisting attribute.
208208
209+
Returns
210+
-------
211+
callable
212+
A class decorator.
213+
209214
See Also
210215
--------
211216
%(others)s

pandas/core/arrays/categorical.py

+10
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,11 @@ def as_ordered(self, inplace=False):
760760
inplace : bool, default False
761761
Whether or not to set the ordered attribute in-place or return
762762
a copy of this categorical with ordered set to True.
763+
764+
Returns
765+
-------
766+
Categorical
767+
Ordered Categorical.
763768
"""
764769
inplace = validate_bool_kwarg(inplace, 'inplace')
765770
return self.set_ordered(True, inplace=inplace)
@@ -768,6 +773,11 @@ def as_unordered(self, inplace=False):
768773
"""
769774
Set the Categorical to be unordered.
770775
776+
Returns
777+
-------
778+
Categorical
779+
Unordered Categorical.
780+
771781
Parameters
772782
----------
773783
inplace : bool, default False

pandas/core/arrays/interval.py

+8
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ def _from_factorized(cls, values, original):
239239
240240
.. versionadded:: 0.23.0
241241
242+
Returns
243+
-------
244+
%(klass)s
245+
242246
See Also
243247
--------
244248
interval_range : Function to create a fixed frequency IntervalIndex.
@@ -383,6 +387,10 @@ def from_arrays(cls, left, right, closed='right', copy=False, dtype=None):
383387
384388
..versionadded:: 0.23.0
385389
390+
Returns
391+
-------
392+
%(klass)s
393+
386394
See Also
387395
--------
388396
interval_range : Function to create a fixed frequency IntervalIndex.

pandas/core/groupby/generic.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,11 @@ def true_and_notna(x, *args, **kwargs):
999999
def nunique(self, dropna=True):
10001000
"""
10011001
Return number of unique elements in the group.
1002+
1003+
Returns
1004+
-------
1005+
Series
1006+
Numver of unique values within each group.
10021007
"""
10031008
ids, _, _ = self.grouper.group_info
10041009

@@ -1181,7 +1186,14 @@ def value_counts(self, normalize=False, sort=True, ascending=False,
11811186
return Series(out, index=mi, name=self._selection_name)
11821187

11831188
def count(self):
1184-
""" Compute count of group, excluding missing values """
1189+
"""
1190+
Compute count of group, excluding missing values.
1191+
1192+
Returns
1193+
-------
1194+
Series
1195+
Count of values within each group.
1196+
"""
11851197
ids, _, ngroups = self.grouper.group_info
11861198
val = self.obj.get_values()
11871199

@@ -1479,7 +1491,14 @@ def _fill(self, direction, limit=None):
14791491
return concat((self._wrap_transformed_output(output), res), axis=1)
14801492

14811493
def count(self):
1482-
""" Compute count of group, excluding missing values """
1494+
"""
1495+
Compute count of group, excluding missing values
1496+
1497+
Returns
1498+
-------
1499+
DataFrame
1500+
Count of values within each group.
1501+
"""
14831502
from pandas.core.dtypes.missing import _isna_ndarraylike as _isna
14841503

14851504
data, _ = self._get_data_to_aggregate()

pandas/core/groupby/groupby.py

+110-1
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,10 @@ def any(self, skipna=True):
10711071
----------
10721072
skipna : bool, default True
10731073
Flag to ignore nan values during truth testing
1074+
1075+
Returns
1076+
-------
1077+
boolean
10741078
"""
10751079
return self._bool_agg('any', skipna)
10761080

@@ -1084,6 +1088,10 @@ def all(self, skipna=True):
10841088
----------
10851089
skipna : bool, default True
10861090
Flag to ignore nan values during truth testing
1091+
1092+
Returns
1093+
-------
1094+
boolean
10871095
"""
10881096
return self._bool_agg('all', skipna)
10891097

@@ -1092,6 +1100,11 @@ def all(self, skipna=True):
10921100
def count(self):
10931101
"""
10941102
Compute count of group, excluding missing values.
1103+
1104+
Returns
1105+
-------
1106+
Series or DataFrame
1107+
Count of values within each group.
10951108
"""
10961109

10971110
# defined here for API doc
@@ -1161,6 +1174,11 @@ def median(self, **kwargs):
11611174
Compute median of groups, excluding missing values.
11621175
11631176
For multiple groupings, the result index will be a MultiIndex
1177+
1178+
Returns
1179+
-------
1180+
Series or DataFrame
1181+
Median of values within each group.
11641182
"""
11651183
try:
11661184
return self._cython_agg_general('median', **kwargs)
@@ -1187,6 +1205,11 @@ def std(self, ddof=1, *args, **kwargs):
11871205
----------
11881206
ddof : integer, default 1
11891207
degrees of freedom
1208+
1209+
Returns
1210+
-------
1211+
Series or DataFrame
1212+
Standard deviation of values within each group.
11901213
"""
11911214

11921215
# TODO: implement at Cython level?
@@ -1205,6 +1228,11 @@ def var(self, ddof=1, *args, **kwargs):
12051228
----------
12061229
ddof : integer, default 1
12071230
degrees of freedom
1231+
1232+
Returns
1233+
-------
1234+
Series or DataFrame
1235+
Variance of values within each group.
12081236
"""
12091237
nv.validate_groupby_func('var', args, kwargs)
12101238
if ddof == 1:
@@ -1231,6 +1259,11 @@ def sem(self, ddof=1):
12311259
----------
12321260
ddof : integer, default 1
12331261
degrees of freedom
1262+
1263+
Returns
1264+
-------
1265+
Series or DataFrame
1266+
Standard error of the mean of values within each group.
12341267
"""
12351268

12361269
return self.std(ddof=ddof) / np.sqrt(self.count())
@@ -1240,6 +1273,11 @@ def sem(self, ddof=1):
12401273
def size(self):
12411274
"""
12421275
Compute group sizes.
1276+
1277+
Returns
1278+
-------
1279+
Series
1280+
Number of rows in each group.
12431281
"""
12441282
result = self.grouper.size()
12451283

@@ -1257,7 +1295,14 @@ def groupby_function(name, alias, npfunc,
12571295
numeric_only=True, _convert=False,
12581296
min_count=-1):
12591297

1260-
_local_template = "Compute %(f)s of group values"
1298+
_local_template = """
1299+
Compute %(f)s of group values
1300+
1301+
Returns
1302+
-------
1303+
Series or DataFrame
1304+
%(f)s of values within each group.
1305+
"""
12611306

12621307
@Substitution(name='groupby', f=name)
12631308
@Appender(_common_see_also)
@@ -1330,6 +1375,11 @@ def ohlc(self):
13301375
Compute sum of values, excluding missing values.
13311376
13321377
For multiple groupings, the result index will be a MultiIndex
1378+
1379+
Returns
1380+
-------
1381+
DataFrame
1382+
Open, high, low and close values within each group.
13331383
"""
13341384

13351385
return self._apply_to_column_groupbys(
@@ -1514,6 +1564,11 @@ def pad(self, limit=None):
15141564
limit : integer, optional
15151565
limit of how many values to fill
15161566
1567+
Returns
1568+
-------
1569+
Series or DataFrame
1570+
Object with missing values filled.
1571+
15171572
See Also
15181573
--------
15191574
Series.pad
@@ -1534,6 +1589,11 @@ def backfill(self, limit=None):
15341589
limit : integer, optional
15351590
limit of how many values to fill
15361591
1592+
Returns
1593+
-------
1594+
Series or DataFrame
1595+
Object with missing values filled.
1596+
15371597
See Also
15381598
--------
15391599
Series.backfill
@@ -1563,6 +1623,11 @@ def nth(self, n, dropna=None):
15631623
dropna : None or str, optional
15641624
apply the specified dropna operation before counting which row is
15651625
the nth row. Needs to be None, 'any' or 'all'
1626+
1627+
Returns
1628+
-------
1629+
Series or DataFrame
1630+
Nth value within each group.
15661631
%(see_also)s
15671632
Examples
15681633
--------
@@ -1793,6 +1858,11 @@ def ngroup(self, ascending=True):
17931858
ascending : bool, default True
17941859
If False, number in reverse, from number of group - 1 to 0.
17951860
1861+
Returns
1862+
-------
1863+
Series
1864+
Unique numbers for each group.
1865+
17961866
See Also
17971867
--------
17981868
.cumcount : Number the rows in each group.
@@ -1856,6 +1926,11 @@ def cumcount(self, ascending=True):
18561926
ascending : bool, default True
18571927
If False, number in reverse, from length of group - 1 to 0.
18581928
1929+
Returns
1930+
-------
1931+
Series
1932+
Sequence number of each element within each group.
1933+
18591934
See Also
18601935
--------
18611936
.ngroup : Number the groups themselves.
@@ -1938,6 +2013,10 @@ def rank(self, method='average', ascending=True, na_option='keep',
19382013
def cumprod(self, axis=0, *args, **kwargs):
19392014
"""
19402015
Cumulative product for each group.
2016+
2017+
Returns
2018+
-------
2019+
Series or DataFrame
19412020
"""
19422021
nv.validate_groupby_func('cumprod', args, kwargs,
19432022
['numeric_only', 'skipna'])
@@ -1951,6 +2030,10 @@ def cumprod(self, axis=0, *args, **kwargs):
19512030
def cumsum(self, axis=0, *args, **kwargs):
19522031
"""
19532032
Cumulative sum for each group.
2033+
2034+
Returns
2035+
-------
2036+
Series or DataFrame
19542037
"""
19552038
nv.validate_groupby_func('cumsum', args, kwargs,
19562039
['numeric_only', 'skipna'])
@@ -1964,6 +2047,10 @@ def cumsum(self, axis=0, *args, **kwargs):
19642047
def cummin(self, axis=0, **kwargs):
19652048
"""
19662049
Cumulative min for each group.
2050+
2051+
Returns
2052+
-------
2053+
Series or DataFrame
19672054
"""
19682055
if axis != 0:
19692056
return self.apply(lambda x: np.minimum.accumulate(x, axis))
@@ -1975,6 +2062,10 @@ def cummin(self, axis=0, **kwargs):
19752062
def cummax(self, axis=0, **kwargs):
19762063
"""
19772064
Cumulative max for each group.
2065+
2066+
Returns
2067+
-------
2068+
Series or DataFrame
19782069
"""
19792070
if axis != 0:
19802071
return self.apply(lambda x: np.maximum.accumulate(x, axis))
@@ -2102,6 +2193,11 @@ def shift(self, periods=1, freq=None, axis=0, fill_value=None):
21022193
fill_value : optional
21032194
21042195
.. versionadded:: 0.24.0
2196+
2197+
Returns
2198+
-------
2199+
Series or DataFrame
2200+
Object shifted within each group.
21052201
"""
21062202

21072203
if freq is not None or axis != 0 or not isna(fill_value):
@@ -2120,6 +2216,11 @@ def pct_change(self, periods=1, fill_method='pad', limit=None, freq=None,
21202216
axis=0):
21212217
"""
21222218
Calculate pct_change of each value to previous entry in group.
2219+
2220+
Returns
2221+
-------
2222+
Series or DataFrame
2223+
Percentage changes within each group.
21232224
"""
21242225
if freq is not None or axis != 0:
21252226
return self.apply(lambda x: x.pct_change(periods=periods,
@@ -2140,6 +2241,10 @@ def head(self, n=5):
21402241
21412242
Essentially equivalent to ``.apply(lambda x: x.head(n))``,
21422243
except ignores as_index flag.
2244+
2245+
Returns
2246+
-------
2247+
Series or DataFrame
21432248
%(see_also)s
21442249
Examples
21452250
--------
@@ -2167,6 +2272,10 @@ def tail(self, n=5):
21672272
21682273
Essentially equivalent to ``.apply(lambda x: x.tail(n))``,
21692274
except ignores as_index flag.
2275+
2276+
Returns
2277+
-------
2278+
Series or DataFrame
21702279
%(see_also)s
21712280
Examples
21722281
--------

0 commit comments

Comments
 (0)