Skip to content

Commit

Permalink
DOC: Enforce Numpy Docstring Validation for pandas.IntervalIndex.leng…
Browse files Browse the repository at this point in the history
…th (#58671)

* DOC: add GL08 for pandas.IntervalIndex.length

* DOC: remove GL08 for pandas.IntervalIndex.length
  • Loading branch information
tuhinsharma121 committed May 11, 2024
1 parent 647d68c commit 81c68dd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
1 change: 0 additions & 1 deletion ci/code_checks.sh
Expand Up @@ -78,7 +78,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.Grouper PR02" \
-i "pandas.Index PR07" \
-i "pandas.IntervalIndex.left GL08" \
-i "pandas.IntervalIndex.length GL08" \
-i "pandas.IntervalIndex.set_closed RT03,SA01" \
-i "pandas.IntervalIndex.to_tuples RT03,SA01" \
-i "pandas.MultiIndex PR01" \
Expand Down
28 changes: 28 additions & 0 deletions pandas/core/indexes/interval.py
Expand Up @@ -924,6 +924,34 @@ def mid(self) -> Index:

@property
def length(self) -> Index:
"""
Calculate the length of each interval in the IntervalIndex.
This method returns a new Index containing the lengths of each interval
in the IntervalIndex. The length of an interval is defined as the difference
between its end and its start.
Returns
-------
Index
An Index containing the lengths of each interval.
See Also
--------
Interval.length : Return the length of the Interval.
Examples
--------
>>> intervals = pd.IntervalIndex.from_arrays(
... [1, 2, 3], [4, 5, 6], closed="right"
... )
>>> intervals.length
Index([3, 3, 3], dtype='int64')
>>> intervals = pd.IntervalIndex.from_tuples([(1, 5), (6, 10), (11, 15)])
>>> intervals.length
Index([4, 4, 4], dtype='int64')
"""
return Index(self._data.length, copy=False)

# --------------------------------------------------------------------
Expand Down

0 comments on commit 81c68dd

Please sign in to comment.