diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 11798db746cc9..12b11372746ef 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -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" \ diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py index 98c8739039d69..4b9d055382c48 100644 --- a/pandas/core/indexes/interval.py +++ b/pandas/core/indexes/interval.py @@ -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) # --------------------------------------------------------------------