Skip to content

BUG: DataFrame reductions with object dtype and axis=1 #49619

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

Closed

Conversation

rhshadrach
Copy link
Member

@rhshadrach rhshadrach commented Nov 10, 2022

In #49616 I attempted to only remove the errant cast to float, but this lead to the issue that, e.g. for axis=1 the sum of boolean columns becomes object. Unconditionally taking the block manager reduce path solves this problem, but then we run into the issue of taking a transpose of a frame with no columns (see the comments in the diff here). This PR resolves that issue, but is a bit of a hack (I can't seem to find any other resolution).

In the test here, there are some reductions (e.g. mean) that one may have expected float back instead - I've opened #49618 for this.

@rhshadrach rhshadrach added Dtype Conversions Unexpected or buggy dtype conversions DataFrame DataFrame data structure Reduction Operations sum, mean, min, max, etc. labels Nov 10, 2022
@rhshadrach rhshadrach marked this pull request as draft November 10, 2022 17:53
Comment on lines +989 to +991
dtype = arr.dtype if res is NaT else None
result_arrays.append(
sanitize_array([res], None) # type: ignore[arg-type]
sanitize_array([res], None, dtype=dtype) # type: ignore[arg-type]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect this approach to work for L984-985 above; is this a preferred method?

@rhshadrach rhshadrach closed this Dec 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DataFrame DataFrame data structure Dtype Conversions Unexpected or buggy dtype conversions Reduction Operations sum, mean, min, max, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: DataFrame reductions with object dtype and axis=1
1 participant