@@ -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." )
@@ -434,7 +427,7 @@ def _bins_to_cuts(
434
427
435
428
def _coerce_to_type (x ):
436
429
"""
437
- if the passed data is of datetime/timedelta or bool type,
430
+ if the passed data is of datetime/timedelta, bool or nullable int type,
438
431
this method converts it to numeric so that cut or qcut method can
439
432
handle it
440
433
"""
@@ -451,6 +444,12 @@ def _coerce_to_type(x):
451
444
elif is_bool_dtype (x ):
452
445
# GH 20303
453
446
x = x .astype (np .int64 )
447
+ # To support cut and qcut for IntegerArray we convert to float dtype.
448
+ # Will properly support in the future.
449
+ # https://github.com/pandas-dev/pandas/pull/31290
450
+ # https://github.com/pandas-dev/pandas/issues/31389
451
+ elif is_extension_array_dtype (x ) and is_integer_dtype (x ):
452
+ x = x .to_numpy (dtype = np .float64 , na_value = np .nan )
454
453
455
454
if dtype is not None :
456
455
# GH 19768: force NaT to NaN during integer conversion
0 commit comments