@@ -871,18 +871,55 @@ def right(self) -> Index:
871
871
--------
872
872
>>> iv_idx = pd.IntervalIndex.from_arrays([1, 2, 3], [4, 5, 6], closed="right")
873
873
>>> iv_idx.right
874
- Int64Index ([4, 5, 6], dtype='int64')
874
+ Index ([4, 5, 6], dtype='int64')
875
875
876
876
>>> iv_idx = pd.IntervalIndex.from_tuples(
877
877
... [(1, 4), (2, 5), (3, 6)], closed="left"
878
878
... )
879
879
>>> iv_idx.right
880
- Int64Index ([4, 5, 6], dtype='int64')
880
+ Index ([4, 5, 6], dtype='int64')
881
881
"""
882
882
return Index (self ._data .right , copy = False )
883
883
884
884
@cache_readonly
885
885
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
+ """
886
923
return Index (self ._data .mid , copy = False )
887
924
888
925
@property
0 commit comments