@@ -202,17 +202,10 @@ def cut(
202202 """
203203 # NOTE: this binning code is changed a bit from histogram for var(x) == 0
204204
205- # for handling the cut for datetime and timedelta objects
206205 original = x
207206 x = _preprocess_for_cut (x )
208207 x , dtype = _coerce_to_type (x )
209208
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-
216209 if not np .iterable (bins ):
217210 if is_scalar (bins ) and bins < 1 :
218211 raise ValueError ("`bins` should be a positive integer." )
@@ -435,7 +428,7 @@ def _bins_to_cuts(
435428
436429def _coerce_to_type (x ):
437430 """
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,
439432 this method converts it to numeric so that cut or qcut method can
440433 handle it
441434 """
@@ -452,6 +445,12 @@ def _coerce_to_type(x):
452445 elif is_bool_dtype (x ):
453446 # GH 20303
454447 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 )
455454
456455 if dtype is not None :
457456 # GH 19768: force NaT to NaN during integer conversion
0 commit comments