Skip to content

Commit c5948d1

Browse files
jschendelTomAugspurger
authored andcommitted
CLN: Simplify logic in _format_labels function for cut/qcut (#30768)
1 parent 8b39347 commit c5948d1

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

pandas/core/reshape/tile.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import numpy as np
55

66
from pandas._libs import Timedelta, Timestamp
7-
from pandas._libs.interval import Interval
87
from pandas._libs.lib import infer_dtype
98

109
from pandas.core.dtypes.common import (
@@ -516,17 +515,11 @@ def _format_labels(
516515
adjust = lambda x: x - 10 ** (-precision)
517516

518517
breaks = [formatter(b) for b in bins]
519-
labels = IntervalIndex.from_breaks(breaks, closed=closed)
520-
521518
if right and include_lowest:
522-
# we will adjust the left hand side by precision to
523-
# account that we are all right closed
524-
v = adjust(labels[0].left)
525-
526-
i = IntervalIndex([Interval(v, labels[0].right, closed="right")])
527-
labels = i.append(labels[1:])
519+
# adjust lhs of first interval by precision to account for being right closed
520+
breaks[0] = adjust(breaks[0])
528521

529-
return labels
522+
return IntervalIndex.from_breaks(breaks, closed=closed)
530523

531524

532525
def _preprocess_for_cut(x):

0 commit comments

Comments
 (0)