Skip to content
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

DOC: improve Index docstrings #50720

Merged
merged 5 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,10 @@ def hasnans(self) -> bool:
Return True if there are any NaNs.

Enables various performance speedups.

Returns
-------
bool
"""
# error: Item "bool" of "Union[bool, ndarray[Any, dtype[bool_]], NDFrame]"
# has no attribute "any"
Expand Down
64 changes: 58 additions & 6 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2084,13 +2084,21 @@ def is_monotonic_increasing(self) -> bool:
"""
Return a boolean if the values are equal or increasing.

Returns
-------
bool

See Also
--------
Index.is_monotonic_decreasing : Check if the values are equal or decreasing.

Examples
--------
>>> Index([1, 2, 3]).is_monotonic_increasing
>>> pd.Index([1, 2, 3]).is_monotonic_increasing
True
>>> Index([1, 2, 2]).is_monotonic_increasing
>>> pd.Index([1, 2, 2]).is_monotonic_increasing
True
>>> Index([1, 3, 2]).is_monotonic_increasing
>>> pd.Index([1, 3, 2]).is_monotonic_increasing
False
"""
return self._engine.is_monotonic_increasing
Expand All @@ -2100,13 +2108,21 @@ def is_monotonic_decreasing(self) -> bool:
"""
Return a boolean if the values are equal or decreasing.

Returns
-------
bool

See Also
--------
Index.is_monotonic_increasing : Check if the values are equal or increasing.

Examples
--------
>>> Index([3, 2, 1]).is_monotonic_decreasing
>>> pd.Index([3, 2, 1]).is_monotonic_decreasing
True
>>> Index([3, 2, 2]).is_monotonic_decreasing
>>> pd.Index([3, 2, 2]).is_monotonic_decreasing
True
>>> Index([3, 1, 2]).is_monotonic_decreasing
>>> pd.Index([3, 1, 2]).is_monotonic_decreasing
False
"""
return self._engine.is_monotonic_decreasing
Expand Down Expand Up @@ -2151,6 +2167,34 @@ def _is_strictly_monotonic_decreasing(self) -> bool:
def is_unique(self) -> bool:
"""
Return if the index has unique values.

Returns
-------
bool

See Also
--------
Index.has_duplicates : Inverse method that checks if it has duplicate values.

Examples
--------
>>> idx = pd.Index([1, 5, 7, 7])
>>> idx.is_unique
False

>>> idx = pd.Index([1, 5, 7])
>>> idx.is_unique
True

>>> idx = pd.Index(["Watermelon", "Orange", "Apple",
... "Watermelon"]).astype("category")
>>> idx.is_unique
False

>>> idx = pd.Index(["Orange", "Apple",
... "Watermelon"]).astype("category")
>>> idx.is_unique
True
"""
return self._engine.is_unique

Expand All @@ -2165,6 +2209,10 @@ def has_duplicates(self) -> bool:
bool
Whether or not the Index has duplicate values.

See Also
--------
Index.is_unique : Inverse method that checks if it has unique values.

Examples
--------
>>> idx = pd.Index([1, 5, 7, 7])
Expand Down Expand Up @@ -2564,6 +2612,10 @@ def hasnans(self) -> bool:
Return True if there are any NaNs.

Enables various performance speedups.

Returns
-------
bool
"""
if self._can_hold_na:
return bool(self._isnan.any())
Expand Down