Skip to content

Commit 81c68dd

Browse files
DOC: Enforce Numpy Docstring Validation for pandas.IntervalIndex.length (#58671)
* DOC: add GL08 for pandas.IntervalIndex.length * DOC: remove GL08 for pandas.IntervalIndex.length
1 parent 647d68c commit 81c68dd

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

ci/code_checks.sh

-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
7878
-i "pandas.Grouper PR02" \
7979
-i "pandas.Index PR07" \
8080
-i "pandas.IntervalIndex.left GL08" \
81-
-i "pandas.IntervalIndex.length GL08" \
8281
-i "pandas.IntervalIndex.set_closed RT03,SA01" \
8382
-i "pandas.IntervalIndex.to_tuples RT03,SA01" \
8483
-i "pandas.MultiIndex PR01" \

pandas/core/indexes/interval.py

+28
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,34 @@ def mid(self) -> Index:
924924

925925
@property
926926
def length(self) -> Index:
927+
"""
928+
Calculate the length of each interval in the IntervalIndex.
929+
930+
This method returns a new Index containing the lengths of each interval
931+
in the IntervalIndex. The length of an interval is defined as the difference
932+
between its end and its start.
933+
934+
Returns
935+
-------
936+
Index
937+
An Index containing the lengths of each interval.
938+
939+
See Also
940+
--------
941+
Interval.length : Return the length of the Interval.
942+
943+
Examples
944+
--------
945+
>>> intervals = pd.IntervalIndex.from_arrays(
946+
... [1, 2, 3], [4, 5, 6], closed="right"
947+
... )
948+
>>> intervals.length
949+
Index([3, 3, 3], dtype='int64')
950+
951+
>>> intervals = pd.IntervalIndex.from_tuples([(1, 5), (6, 10), (11, 15)])
952+
>>> intervals.length
953+
Index([4, 4, 4], dtype='int64')
954+
"""
927955
return Index(self._data.length, copy=False)
928956

929957
# --------------------------------------------------------------------

0 commit comments

Comments
 (0)