Skip to content

Commit d95ff3e

Browse files
authored
DOC: improve Index docstrings (#50720)
* DOC: improve Index docstrings * fix example * update Series.hanans docstring
1 parent 13f5395 commit d95ff3e

File tree

2 files changed

+62
-6
lines changed

2 files changed

+62
-6
lines changed

pandas/core/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,10 @@ def hasnans(self) -> bool:
784784
Return True if there are any NaNs.
785785
786786
Enables various performance speedups.
787+
788+
Returns
789+
-------
790+
bool
787791
"""
788792
# error: Item "bool" of "Union[bool, ndarray[Any, dtype[bool_]], NDFrame]"
789793
# has no attribute "any"

pandas/core/indexes/base.py

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,13 +2041,21 @@ def is_monotonic_increasing(self) -> bool:
20412041
"""
20422042
Return a boolean if the values are equal or increasing.
20432043
2044+
Returns
2045+
-------
2046+
bool
2047+
2048+
See Also
2049+
--------
2050+
Index.is_monotonic_decreasing : Check if the values are equal or decreasing.
2051+
20442052
Examples
20452053
--------
2046-
>>> Index([1, 2, 3]).is_monotonic_increasing
2054+
>>> pd.Index([1, 2, 3]).is_monotonic_increasing
20472055
True
2048-
>>> Index([1, 2, 2]).is_monotonic_increasing
2056+
>>> pd.Index([1, 2, 2]).is_monotonic_increasing
20492057
True
2050-
>>> Index([1, 3, 2]).is_monotonic_increasing
2058+
>>> pd.Index([1, 3, 2]).is_monotonic_increasing
20512059
False
20522060
"""
20532061
return self._engine.is_monotonic_increasing
@@ -2057,13 +2065,21 @@ def is_monotonic_decreasing(self) -> bool:
20572065
"""
20582066
Return a boolean if the values are equal or decreasing.
20592067
2068+
Returns
2069+
-------
2070+
bool
2071+
2072+
See Also
2073+
--------
2074+
Index.is_monotonic_increasing : Check if the values are equal or increasing.
2075+
20602076
Examples
20612077
--------
2062-
>>> Index([3, 2, 1]).is_monotonic_decreasing
2078+
>>> pd.Index([3, 2, 1]).is_monotonic_decreasing
20632079
True
2064-
>>> Index([3, 2, 2]).is_monotonic_decreasing
2080+
>>> pd.Index([3, 2, 2]).is_monotonic_decreasing
20652081
True
2066-
>>> Index([3, 1, 2]).is_monotonic_decreasing
2082+
>>> pd.Index([3, 1, 2]).is_monotonic_decreasing
20672083
False
20682084
"""
20692085
return self._engine.is_monotonic_decreasing
@@ -2108,6 +2124,34 @@ def _is_strictly_monotonic_decreasing(self) -> bool:
21082124
def is_unique(self) -> bool:
21092125
"""
21102126
Return if the index has unique values.
2127+
2128+
Returns
2129+
-------
2130+
bool
2131+
2132+
See Also
2133+
--------
2134+
Index.has_duplicates : Inverse method that checks if it has duplicate values.
2135+
2136+
Examples
2137+
--------
2138+
>>> idx = pd.Index([1, 5, 7, 7])
2139+
>>> idx.is_unique
2140+
False
2141+
2142+
>>> idx = pd.Index([1, 5, 7])
2143+
>>> idx.is_unique
2144+
True
2145+
2146+
>>> idx = pd.Index(["Watermelon", "Orange", "Apple",
2147+
... "Watermelon"]).astype("category")
2148+
>>> idx.is_unique
2149+
False
2150+
2151+
>>> idx = pd.Index(["Orange", "Apple",
2152+
... "Watermelon"]).astype("category")
2153+
>>> idx.is_unique
2154+
True
21112155
"""
21122156
return self._engine.is_unique
21132157

@@ -2122,6 +2166,10 @@ def has_duplicates(self) -> bool:
21222166
bool
21232167
Whether or not the Index has duplicate values.
21242168
2169+
See Also
2170+
--------
2171+
Index.is_unique : Inverse method that checks if it has unique values.
2172+
21252173
Examples
21262174
--------
21272175
>>> idx = pd.Index([1, 5, 7, 7])
@@ -2547,6 +2595,10 @@ def hasnans(self) -> bool:
25472595
Return True if there are any NaNs.
25482596
25492597
Enables various performance speedups.
2598+
2599+
Returns
2600+
-------
2601+
bool
25502602
"""
25512603
if self._can_hold_na:
25522604
return bool(self._isnan.any())

0 commit comments

Comments
 (0)