Skip to content

DOC Fixing EX01 - added examples #53181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 15, 2023
9 changes: 0 additions & 9 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then

MSG='Partially validate docstrings (EX01)' ; echo $MSG
$BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX01 --ignore_functions \
pandas.Series.item \
pandas.Series.pipe \
pandas.Series.mode \
pandas.Series.is_unique \
pandas.Series.is_monotonic_increasing \
pandas.Series.is_monotonic_decreasing \
pandas.Series.backfill \
pandas.Series.bfill \
pandas.Series.ffill \
Expand Down Expand Up @@ -324,7 +318,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
pandas.Index.fillna \
pandas.Index.dropna \
pandas.Index.astype \
pandas.Index.item \
pandas.Index.map \
pandas.Index.ravel \
pandas.Index.to_list \
Expand Down Expand Up @@ -467,8 +460,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
pandas.core.groupby.SeriesGroupBy.cumsum \
pandas.core.groupby.SeriesGroupBy.diff \
pandas.core.groupby.SeriesGroupBy.ffill \
pandas.core.groupby.SeriesGroupBy.is_monotonic_increasing \
pandas.core.groupby.SeriesGroupBy.is_monotonic_decreasing \
pandas.core.groupby.SeriesGroupBy.max \
pandas.core.groupby.SeriesGroupBy.median \
pandas.core.groupby.SeriesGroupBy.min \
Expand Down
34 changes: 32 additions & 2 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,24 @@ def item(self):
Returns
-------
scalar
The first element of Series.
The first element of Series or Index.

Raises
------
ValueError
If the data is not length-1.
If the data is not length = 1.

Examples
--------
>>> s = pd.Series([1])
>>> s.item()
1

For an index:

>>> s = pd.Series([1], index=['a'])
>>> s.index.item()
'a'
"""
if len(self) == 1:
return next(iter(self))
Expand Down Expand Up @@ -965,6 +977,12 @@ def is_unique(self) -> bool:
Returns
-------
bool

Examples
--------
>>> s = pd.Series([1, 2, 3, 1])
>>> s.is_unique
False
Comment on lines +988 to +989
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one also returns bool ;) rest looks good though!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have seen it :) .. thanks

"""
return self.nunique(dropna=False) == len(self)

Expand All @@ -976,6 +994,12 @@ def is_monotonic_increasing(self) -> bool:
Returns
-------
bool

Examples
--------
>>> s = pd.Series([1, 2, 2])
>>> s.is_monotonic_increasing
True
"""
from pandas import Index

Expand All @@ -989,6 +1013,12 @@ def is_monotonic_decreasing(self) -> bool:
Returns
-------
bool

Examples
--------
>>> s = pd.Series([3, 2, 2, 1])
>>> s.is_monotonic_decreasing
Comment on lines +1027 to +1028
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for this and the above, could we add an example for when the return value is False?

In general, for functions which return -> bool, it's probably good to have a simple example of both cases (something quick and simple is fine)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks for the instructions.

True
"""
from pandas import Index

Expand Down
34 changes: 32 additions & 2 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1170,13 +1170,43 @@ def cov(
return result

@property
@doc(Series.is_monotonic_increasing.__doc__)
def is_monotonic_increasing(self) -> Series:
# GH13
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we don't need this (and below)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'll remove them.

"""
Return boolean if values in the group are monotonically increasing.

Returns
-------
bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


Examples
--------
>>> s = pd.Series([2, 1, 3, 4], index=['Falcon', 'Falcon', 'Parrot', 'Parrot'])
>>> s.groupby(level=0).is_monotonic_increasing
Falcon False
Parrot True
dtype: bool
"""
return self.apply(lambda ser: ser.is_monotonic_increasing)

@property
@doc(Series.is_monotonic_decreasing.__doc__)
def is_monotonic_decreasing(self) -> Series:
# GH13
"""
Return boolean if values in the group are monotonically decreasing.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so sorry, I missed this the first time round

it doesn't return a boolean, but a Series of booleans

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My fault 🫣


Returns
-------
bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Series

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed


Examples
--------
>>> s = pd.Series([2, 1, 3, 4], index=['Falcon', 'Falcon', 'Parrot', 'Parrot'])
>>> s.groupby(level=0).is_monotonic_decreasing
Falcon True
Parrot False
dtype: bool
"""
return self.apply(lambda ser: ser.is_monotonic_decreasing)

@doc(Series.hist.__doc__)
Expand Down
26 changes: 26 additions & 0 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2081,6 +2081,32 @@ def mode(self, dropna: bool = True) -> Series:
-------
Series
Modes of the Series in sorted order.

Examples
--------
>>> s = pd.Series([2, 4, 2, 2, 4, None])
>>> s.mode()
0 2.0
dtype: float64

More than one mode:

>>> s = pd.Series([2, 4, 8, 2, 4, None])
>>> s.mode()
0 2.0
1 4.0
dtype: float64

With and without considering null value:

>>> s = pd.Series([2, 4, None, None, 4, None])
>>> s.mode(dropna=False)
0 NaN
dtype: float64
>>> s = pd.Series([2, 4, None, None, 4, None])
>>> s.mode()
0 4.0
dtype: float64
"""
# TODO: Add option for bins like value_counts()
values = self._values
Expand Down