@@ -202,17 +202,10 @@ def cut(
202
202
"""
203
203
# NOTE: this binning code is changed a bit from histogram for var(x) == 0
204
204
205
- # for handling the cut for datetime and timedelta objects
206
205
original = x
207
206
x = _preprocess_for_cut (x )
208
207
x , dtype = _coerce_to_type (x )
209
208
210
- # To support cut(IntegerArray), we convert to object dtype with NaN
211
- # Will properly support in the future.
212
- # https://github.com/pandas-dev/pandas/pull/31290
213
- if is_extension_array_dtype (x .dtype ) and is_integer_dtype (x .dtype ):
214
- x = x .to_numpy (dtype = object , na_value = np .nan )
215
-
216
209
if not np .iterable (bins ):
217
210
if is_scalar (bins ) and bins < 1 :
218
211
raise ValueError ("`bins` should be a positive integer." )
@@ -435,7 +428,7 @@ def _bins_to_cuts(
435
428
436
429
def _coerce_to_type (x ):
437
430
"""
438
- if the passed data is of datetime/timedelta or bool type,
431
+ if the passed data is of datetime/timedelta, bool or nullable int type,
439
432
this method converts it to numeric so that cut or qcut method can
440
433
handle it
441
434
"""
@@ -452,6 +445,12 @@ def _coerce_to_type(x):
452
445
elif is_bool_dtype (x ):
453
446
# GH 20303
454
447
x = x .astype (np .int64 )
448
+ # To support cut and qcut for IntegerArray we convert to float dtype.
449
+ # Will properly support in the future.
450
+ # https://github.com/pandas-dev/pandas/pull/31290
451
+ # https://github.com/pandas-dev/pandas/issues/31389
452
+ elif is_extension_array_dtype (x ) and is_integer_dtype (x ):
453
+ x = x .to_numpy (dtype = np .float64 , na_value = np .nan )
455
454
456
455
if dtype is not None :
457
456
# GH 19768: force NaT to NaN during integer conversion
0 commit comments