-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Don't cast nullable Boolean to float in groupby #33089
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 all commits
5f8477f
359231c
5311de9
0aa91f6
8546e29
cf29e31
62de835
89505ac
a426f9d
85fe250
d55a74f
c7e38b0
58b2ba4
a4e10b6
fc25876
db4fb5e
34cb8d6
e55a0d4
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 |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
ensure_str, | ||
is_bool, | ||
is_bool_dtype, | ||
is_categorical_dtype, | ||
is_complex, | ||
is_complex_dtype, | ||
is_datetime64_dtype, | ||
|
@@ -279,12 +280,15 @@ def maybe_cast_result(result, obj: "Series", numeric_only: bool = False, how: st | |
dtype = maybe_cast_result_dtype(dtype, how) | ||
|
||
if not is_scalar(result): | ||
if is_extension_array_dtype(dtype) and dtype.kind != "M": | ||
# The result may be of any type, cast back to original | ||
# type if it's compatible. | ||
if len(result) and isinstance(result[0], dtype.type): | ||
cls = dtype.construct_array_type() | ||
result = maybe_cast_to_extension_array(cls, result, dtype=dtype) | ||
if ( | ||
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. again instead of expanding this check, i would completely remove it; it be encompassed in maybe_cast_result_type, which is the point of that function 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'm not sure if we can completely move this logic into The datetime check seems to be another issue with not being able to introspect a user-provided function like 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. this is tagged as 1.0.4 at the moment just in case we do another patch release. If so, the changes in this PR should be kept to a minimum? |
||
is_extension_array_dtype(dtype) | ||
and not is_categorical_dtype(dtype) | ||
and dtype.kind != "M" | ||
): | ||
# We have to special case categorical so as not to upcast | ||
# things like counts back to categorical | ||
cls = dtype.construct_array_type() | ||
result = maybe_cast_to_extension_array(cls, result, dtype=dtype) | ||
|
||
elif numeric_only and is_numeric_dtype(dtype) or not numeric_only: | ||
result = maybe_downcast_to_dtype(result, dtype) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check also blocks things like the conversion of float array to nullable integer which was a problem here as well: #32914