Skip to content

Commit b2fcf9d

Browse files
committed
temp-fix-58933
1 parent 629ffeb commit b2fcf9d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pandas/core/reshape/tile.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ def qcut(
278278
retbins: bool = False,
279279
precision: int = 3,
280280
duplicates: str = "raise",
281+
right: bool = True,
281282
):
282283
"""
283284
Quantile-based discretization function.
@@ -304,6 +305,8 @@ def qcut(
304305
The precision at which to store and display the bins labels.
305306
duplicates : {default 'raise', 'drop'}, optional
306307
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.
307310
308311
Returns
309312
-------
@@ -346,13 +349,29 @@ def qcut(
346349

347350
bins = x_idx.to_series().dropna().quantile(quantiles)
348351

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+
349367
fac, bins = _bins_to_cuts(
350368
x_idx,
351369
Index(bins),
352370
labels=labels,
353371
precision=precision,
354372
include_lowest=True,
355373
duplicates=duplicates,
374+
right=right,
356375
)
357376

358377
return _postprocess_for_cut(fac, bins, retbins, original)

0 commit comments

Comments
 (0)