File tree 3 files changed +11
-2
lines changed
3 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -214,6 +214,7 @@ def setup(self, bins):
214
214
self .datetime_series = pd .Series (
215
215
np .random .randint (N , size = N ), dtype = "datetime64[ns]"
216
216
)
217
+ self .interval_bins = pd .IntervalIndex .from_breaks (np .linspace (0 , N , bins ))
217
218
218
219
def time_cut_int (self , bins ):
219
220
pd .cut (self .int_series , bins )
@@ -239,6 +240,14 @@ def time_qcut_timedelta(self, bins):
239
240
def time_qcut_datetime (self , bins ):
240
241
pd .qcut (self .datetime_series , bins )
241
242
243
+ def time_cut_interval (self , bins ):
244
+ # GH 27668
245
+ pd .cut (self .int_series , self .interval_bins )
246
+
247
+ def peakmem_cut_interval (self , bins ):
248
+ # GH 27668
249
+ pd .cut (self .int_series , self .interval_bins )
250
+
242
251
243
252
class Explode :
244
253
param_names = ["n_rows" , "max_list_length" ]
Original file line number Diff line number Diff line change @@ -71,6 +71,7 @@ Performance improvements
71
71
72
72
- Performance improvement in indexing with a non-unique :class: `IntervalIndex ` (:issue: `27489 `)
73
73
- Performance improvement in `MultiIndex.is_monotonic ` (:issue: `27495 `)
74
+ - Performance improvement in :func: `cut ` when ``bins `` is an :class: `IntervalIndex ` (:issue: `27668 `)
74
75
75
76
76
77
.. _whatsnew_1000.bug_fixes :
Original file line number Diff line number Diff line change @@ -373,8 +373,7 @@ def _bins_to_cuts(
373
373
if isinstance (bins , IntervalIndex ):
374
374
# we have a fast-path here
375
375
ids = bins .get_indexer (x )
376
- result = algos .take_nd (bins , ids )
377
- result = Categorical (result , categories = bins , ordered = True )
376
+ result = Categorical .from_codes (ids , categories = bins , ordered = True )
378
377
return result , bins
379
378
380
379
unique_bins = algos .unique (bins )
You can’t perform that action at this time.
0 commit comments