diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 5bbad800b7aa9..9e2adf2daa3ca 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -148,9 +148,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.Index.empty\ pandas.Index.names\ pandas.Index.view\ - pandas.IntervalIndex.left\ - pandas.IntervalIndex.length\ - pandas.IntervalIndex.mid\ pandas.IntervalIndex.right\ pandas.Period.freq\ pandas.Period.ordinal\ diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py index ea3e848356ab5..d831faed61880 100644 --- a/pandas/core/indexes/interval.py +++ b/pandas/core/indexes/interval.py @@ -827,6 +827,25 @@ def _is_comparable_dtype(self, dtype: DtypeObj) -> bool: @cache_readonly def left(self) -> Index: + """ + Return intervals' left value. + + Returns + ------- + Index + + See Also + -------- + IntervalIndex : The structure of IntervalIndex. + + Examples + -------- + >>> pd.interval_range(start=0, end=5) + IntervalIndex([(0, 1], (1, 2], (2, 3], (3, 4], (4, 5]], + dtype='interval[int64, right]') + >>> pd.interval_range(start=0, end=5).left + Index([0, 1, 2, 3, 4], dtype='int64') + """ return Index(self._data.left, copy=False) @cache_readonly @@ -835,10 +854,49 @@ def right(self) -> Index: @cache_readonly def mid(self) -> Index: + """ + Return the midpoint of each interval. + + Returns + ------- + Index + + See Also + -------- + IntervalIndex : The structure of IntervalIndex. + + Examples + -------- + >>> pd.interval_range(start=0, end=10, periods=3) + IntervalIndex([(0.0, 3.3333333333333335], (3.3333333333333335, + 6.666666666666667], (6.666666666666667, 10.0]], + dtype='interval[float64, right]') + >>> pd.interval_range(start=0, end=10, periods=3).mid + Index([1.6666666666666667, 5.0, 8.333333333333334], dtype='float64') + """ return Index(self._data.mid, copy=False) @property def length(self) -> Index: + """ + Return the intervals' length. + + Returns + ------- + Index + + See Also + -------- + IntervalIndex : The structure of IntervalIndex. + + Examples + -------- + >>> pd.interval_range(start=0, end=5) + IntervalIndex([(0, 1], (1, 2], (2, 3], (3, 4], (4, 5]], + dtype='interval[int64, right]') + >>> pd.interval_range(start=0, end=5).length + Index([1, 1, 1, 1, 1], dtype='int64') + """ return Index(self._data.length, copy=False) # --------------------------------------------------------------------