-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: fix DataFrame.apply returning wrong result when dealing with dtype (#28773) #30304
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 12 commits
d515b5b
d045aed
85a2af7
7b6e793
dcaf64b
f47b420
a0b89e9
9f24abb
6eb6d08
b45b44d
3755138
fdb2f43
78f0154
1f81b77
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 |
---|---|---|
|
@@ -274,13 +274,16 @@ def apply_standard(self): | |
|
||
# we cannot reduce using non-numpy dtypes, | ||
# as demonstrated in gh-12244 | ||
if ( | ||
can_reduce = ( | ||
self.result_type in ["reduce", None] | ||
and not self.dtypes.apply(is_extension_array_dtype).any() | ||
# Disallow complex_internals since libreduction shortcut | ||
# cannot handle MultiIndex | ||
and not isinstance(self.agg_axis, ABCMultiIndex) | ||
): | ||
) | ||
return_result = None | ||
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. why is this needed? 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 using it to determine if line 314 was run. |
||
|
||
if can_reduce: | ||
|
||
values = self.values | ||
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. @Reksbril the underlying problem here is that this call to |
||
index = self.obj._get_axis(self.axis) | ||
|
@@ -308,11 +311,21 @@ def apply_standard(self): | |
# reached via numexpr; fall back to python implementation | ||
pass | ||
else: | ||
return self.obj._constructor_sliced(result, index=labels) | ||
return_result = self.obj._constructor_sliced(result, index=labels) | ||
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. what are you trying to do here? we have a specific subclass for Series where this could live, but I am not clear what you are trying to catch |
||
if ( | ||
self.axis != 0 and self.axis != "index" | ||
) or self.dtypes.nunique() <= 1: | ||
return return_result | ||
|
||
# compute the result using the series generator | ||
results, res_index = self.apply_series_generator() | ||
|
||
if can_reduce and return_result is not None: | ||
results = np.array(list(results.values())) | ||
return self.obj._constructor_sliced( | ||
results, index=res_index, dtype=return_result.dtype | ||
) | ||
|
||
# wrap results | ||
return self.wrap_results(results, res_index) | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.