@@ -278,6 +278,7 @@ def qcut(
278
278
retbins : bool = False ,
279
279
precision : int = 3 ,
280
280
duplicates : str = "raise" ,
281
+ right : bool = True ,
281
282
):
282
283
"""
283
284
Quantile-based discretization function.
@@ -304,6 +305,8 @@ def qcut(
304
305
The precision at which to store and display the bins labels.
305
306
duplicates : {default 'raise', 'drop'}, optional
306
307
If bin edges are not unique, raise ValueError or drop non-uniques.
308
+ right : bool, default True
309
+ Indicates whether bins includes the rightmost edge or not.
307
310
308
311
Returns
309
312
-------
@@ -346,13 +349,29 @@ def qcut(
346
349
347
350
bins = x_idx .to_series ().dropna ().quantile (quantiles )
348
351
352
+ if isinstance (bins [0 ], (np .datetime64 , Timestamp )):
353
+ time_delta = np .timedelta64 (1 , 's' )
354
+ bins = np .array (bins , dtype = 'datetime64[s]' )
355
+ if not right :
356
+ bins [- 1 ] = bins [- 1 ] + 4 * time_delta
357
+ else :
358
+ bins [1 :] = bins [1 :] + 4 * time_delta
359
+ else :
360
+ eps = np .finfo (bins .dtype ).eps
361
+ bins = np .array (bins )
362
+ if not right :
363
+ bins [- 1 ] = bins [- 1 ] + 4 * eps
364
+ else :
365
+ bins [1 :] = bins [1 :] + 4 * eps
366
+
349
367
fac , bins = _bins_to_cuts (
350
368
x_idx ,
351
369
Index (bins ),
352
370
labels = labels ,
353
371
precision = precision ,
354
372
include_lowest = True ,
355
373
duplicates = duplicates ,
374
+ right = right ,
356
375
)
357
376
358
377
return _postprocess_for_cut (fac , bins , retbins , original )
0 commit comments