Skip to content

Commit f676c5f

Browse files
DOC Fixing EX01 - added examples (#53181)
* DOC Fixing EX01 - added examples * Removed Index.item from code_checks * Removed #GH13 * Added case for return value=False * Added False case for is_unique * Correct docstring * really minor clarification (there may be multiple groups, so "the group" isnt defined) --------- Co-authored-by: MarcoGorelli <[email protected]>
1 parent 935244a commit f676c5f

File tree

4 files changed

+100
-13
lines changed

4 files changed

+100
-13
lines changed

ci/code_checks.sh

-9
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
8080

8181
MSG='Partially validate docstrings (EX01)' ; echo $MSG
8282
$BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX01 --ignore_functions \
83-
pandas.Series.item \
84-
pandas.Series.pipe \
85-
pandas.Series.mode \
86-
pandas.Series.is_unique \
87-
pandas.Series.is_monotonic_increasing \
88-
pandas.Series.is_monotonic_decreasing \
8983
pandas.Series.backfill \
9084
pandas.Series.bfill \
9185
pandas.Series.ffill \
@@ -319,7 +313,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
319313
pandas.Index.fillna \
320314
pandas.Index.dropna \
321315
pandas.Index.astype \
322-
pandas.Index.item \
323316
pandas.Index.map \
324317
pandas.Index.ravel \
325318
pandas.Index.to_list \
@@ -462,8 +455,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
462455
pandas.core.groupby.SeriesGroupBy.cumsum \
463456
pandas.core.groupby.SeriesGroupBy.diff \
464457
pandas.core.groupby.SeriesGroupBy.ffill \
465-
pandas.core.groupby.SeriesGroupBy.is_monotonic_increasing \
466-
pandas.core.groupby.SeriesGroupBy.is_monotonic_decreasing \
467458
pandas.core.groupby.SeriesGroupBy.max \
468459
pandas.core.groupby.SeriesGroupBy.median \
469460
pandas.core.groupby.SeriesGroupBy.min \

pandas/core/base.py

+44-2
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,24 @@ def item(self):
357357
Returns
358358
-------
359359
scalar
360-
The first element of Series.
360+
The first element of Series or Index.
361361
362362
Raises
363363
------
364364
ValueError
365-
If the data is not length-1.
365+
If the data is not length = 1.
366+
367+
Examples
368+
--------
369+
>>> s = pd.Series([1])
370+
>>> s.item()
371+
1
372+
373+
For an index:
374+
375+
>>> s = pd.Series([1], index=['a'])
376+
>>> s.index.item()
377+
'a'
366378
"""
367379
if len(self) == 1:
368380
return next(iter(self))
@@ -965,6 +977,16 @@ def is_unique(self) -> bool:
965977
Returns
966978
-------
967979
bool
980+
981+
Examples
982+
--------
983+
>>> s = pd.Series([1, 2, 3])
984+
>>> s.is_unique
985+
True
986+
987+
>>> s = pd.Series([1, 2, 3, 1])
988+
>>> s.is_unique
989+
False
968990
"""
969991
return self.nunique(dropna=False) == len(self)
970992

@@ -976,6 +998,16 @@ def is_monotonic_increasing(self) -> bool:
976998
Returns
977999
-------
9781000
bool
1001+
1002+
Examples
1003+
--------
1004+
>>> s = pd.Series([1, 2, 2])
1005+
>>> s.is_monotonic_increasing
1006+
True
1007+
1008+
>>> s = pd.Series([3, 2, 1])
1009+
>>> s.is_monotonic_increasing
1010+
False
9791011
"""
9801012
from pandas import Index
9811013

@@ -989,6 +1021,16 @@ def is_monotonic_decreasing(self) -> bool:
9891021
Returns
9901022
-------
9911023
bool
1024+
1025+
Examples
1026+
--------
1027+
>>> s = pd.Series([3, 2, 2, 1])
1028+
>>> s.is_monotonic_decreasing
1029+
True
1030+
1031+
>>> s = pd.Series([1, 2, 3])
1032+
>>> s.is_monotonic_decreasing
1033+
False
9921034
"""
9931035
from pandas import Index
9941036

pandas/core/groupby/generic.py

+30-2
Original file line numberDiff line numberDiff line change
@@ -1170,13 +1170,41 @@ def cov(
11701170
return result
11711171

11721172
@property
1173-
@doc(Series.is_monotonic_increasing.__doc__)
11741173
def is_monotonic_increasing(self) -> Series:
1174+
"""
1175+
Return whether each group's values are monotonically increasing.
1176+
1177+
Returns
1178+
-------
1179+
Series
1180+
1181+
Examples
1182+
--------
1183+
>>> s = pd.Series([2, 1, 3, 4], index=['Falcon', 'Falcon', 'Parrot', 'Parrot'])
1184+
>>> s.groupby(level=0).is_monotonic_increasing
1185+
Falcon False
1186+
Parrot True
1187+
dtype: bool
1188+
"""
11751189
return self.apply(lambda ser: ser.is_monotonic_increasing)
11761190

11771191
@property
1178-
@doc(Series.is_monotonic_decreasing.__doc__)
11791192
def is_monotonic_decreasing(self) -> Series:
1193+
"""
1194+
Return whether each group's values are monotonically decreasing.
1195+
1196+
Returns
1197+
-------
1198+
Series
1199+
1200+
Examples
1201+
--------
1202+
>>> s = pd.Series([2, 1, 3, 4], index=['Falcon', 'Falcon', 'Parrot', 'Parrot'])
1203+
>>> s.groupby(level=0).is_monotonic_decreasing
1204+
Falcon True
1205+
Parrot False
1206+
dtype: bool
1207+
"""
11801208
return self.apply(lambda ser: ser.is_monotonic_decreasing)
11811209

11821210
@doc(Series.hist.__doc__)

pandas/core/series.py

+26
Original file line numberDiff line numberDiff line change
@@ -2085,6 +2085,32 @@ def mode(self, dropna: bool = True) -> Series:
20852085
-------
20862086
Series
20872087
Modes of the Series in sorted order.
2088+
2089+
Examples
2090+
--------
2091+
>>> s = pd.Series([2, 4, 2, 2, 4, None])
2092+
>>> s.mode()
2093+
0 2.0
2094+
dtype: float64
2095+
2096+
More than one mode:
2097+
2098+
>>> s = pd.Series([2, 4, 8, 2, 4, None])
2099+
>>> s.mode()
2100+
0 2.0
2101+
1 4.0
2102+
dtype: float64
2103+
2104+
With and without considering null value:
2105+
2106+
>>> s = pd.Series([2, 4, None, None, 4, None])
2107+
>>> s.mode(dropna=False)
2108+
0 NaN
2109+
dtype: float64
2110+
>>> s = pd.Series([2, 4, None, None, 4, None])
2111+
>>> s.mode()
2112+
0 4.0
2113+
dtype: float64
20882114
"""
20892115
# TODO: Add option for bins like value_counts()
20902116
values = self._values

0 commit comments

Comments
 (0)