Skip to content

Commit bae7965

Browse files
DOC: Enforce Numpy Docstring Validation for pandas.IntervalIndex.mid (#58657)
* DOC: add GL08 for pandas.IntervalIndex.mid * DOC: remove GL08 for pandas.IntervalIndex.mid * ENH: fix return type in examples section
1 parent 1df457f commit bae7965

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

ci/code_checks.sh

-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
8080
-i "pandas.IntervalIndex.is_non_overlapping_monotonic SA01" \
8181
-i "pandas.IntervalIndex.left GL08" \
8282
-i "pandas.IntervalIndex.length GL08" \
83-
-i "pandas.IntervalIndex.mid GL08" \
8483
-i "pandas.IntervalIndex.set_closed RT03,SA01" \
8584
-i "pandas.IntervalIndex.to_tuples RT03,SA01" \
8685
-i "pandas.MultiIndex PR01" \

pandas/core/indexes/interval.py

+39-2
Original file line numberDiff line numberDiff line change
@@ -871,18 +871,55 @@ def right(self) -> Index:
871871
--------
872872
>>> iv_idx = pd.IntervalIndex.from_arrays([1, 2, 3], [4, 5, 6], closed="right")
873873
>>> iv_idx.right
874-
Int64Index([4, 5, 6], dtype='int64')
874+
Index([4, 5, 6], dtype='int64')
875875
876876
>>> iv_idx = pd.IntervalIndex.from_tuples(
877877
... [(1, 4), (2, 5), (3, 6)], closed="left"
878878
... )
879879
>>> iv_idx.right
880-
Int64Index([4, 5, 6], dtype='int64')
880+
Index([4, 5, 6], dtype='int64')
881881
"""
882882
return Index(self._data.right, copy=False)
883883

884884
@cache_readonly
885885
def mid(self) -> Index:
886+
"""
887+
Return the midpoint of each interval in the IntervalIndex as an Index.
888+
889+
Each midpoint is calculated as the average of the left and right bounds
890+
of each interval. The midpoints are returned as a pandas Index object.
891+
892+
Returns
893+
-------
894+
pandas.Index
895+
An Index containing the midpoints of each interval.
896+
897+
See Also
898+
--------
899+
IntervalIndex.left : Return the left bounds of the intervals
900+
in the IntervalIndex.
901+
IntervalIndex.right : Return the right bounds of the intervals
902+
in the IntervalIndex.
903+
IntervalIndex.length : Return the length of the intervals in
904+
the IntervalIndex.
905+
906+
Notes
907+
-----
908+
The midpoint is the average of the interval bounds, potentially resulting
909+
in a floating-point number even if bounds are integers. The returned Index
910+
will have a dtype that accurately holds the midpoints. This computation is
911+
the same regardless of whether intervals are open or closed.
912+
913+
Examples
914+
--------
915+
>>> iv_idx = pd.IntervalIndex.from_arrays([1, 2, 3], [4, 5, 6])
916+
>>> iv_idx.mid
917+
Index([2.5, 3.5, 4.5], dtype='float64')
918+
919+
>>> iv_idx = pd.IntervalIndex.from_tuples([(1, 4), (2, 5), (3, 6)])
920+
>>> iv_idx.mid
921+
Index([2.5, 3.5, 4.5], dtype='float64')
922+
"""
886923
return Index(self._data.mid, copy=False)
887924

888925
@property

0 commit comments

Comments
 (0)