Skip to content

DOC: Enforce Numpy Docstring Validation for pandas.IntervalIndex.length #58671

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 2 commits into from
May 11, 2024
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
1 change: 0 additions & 1 deletion ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.Index PR07" \
-i "pandas.IntervalIndex.is_non_overlapping_monotonic SA01" \
-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
Original file line number Diff line number Diff line change
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
Loading