-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: Coercing bool types to int in qcut #28802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
1ffdf50
aabbd95
7ecaf79
311106a
33c889c
412f2d9
b397804
9043bcb
1cc400c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
from pandas.core.dtypes.common import ( | ||
_NS_DTYPE, | ||
ensure_int64, | ||
is_bool_dtype, | ||
is_categorical_dtype, | ||
is_datetime64_dtype, | ||
is_datetime64tz_dtype, | ||
|
@@ -423,8 +424,8 @@ def _bins_to_cuts( | |
|
||
def _coerce_to_type(x): | ||
""" | ||
if the passed data is of datetime/timedelta type, | ||
this method converts it to numeric so that cut method can | ||
if the passed data is of datetime/timedelta or bool type, | ||
this method converts it to numeric so that cut or qcut method can | ||
handle it | ||
""" | ||
dtype = None | ||
|
@@ -437,10 +438,15 @@ def _coerce_to_type(x): | |
elif is_timedelta64_dtype(x): | ||
x = to_timedelta(x) | ||
dtype = np.dtype("timedelta64[ns]") | ||
elif is_bool_dtype(x): | ||
dtype = x.dtype | ||
ryankarlos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if dtype is not None: | ||
# GH 19768: force NaT to NaN during integer conversion | ||
x = np.where(x.notna(), x.view(np.int64), np.nan) | ||
if is_bool_dtype(x): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jreback Not entirely sure where this should go - Adding It passes if adding i There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so don't use
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've gone with doing the integer conversion in the |
||
x = np.where(~np.isnan(x), x.astype(int), np.nan) | ||
else: | ||
x = np.where(x.notna(), x.view(np.int64), np.nan) | ||
|
||
return x, dtype | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.