Skip to content

BUG: stack doesn't preserve lower precision floating dtypes #51602

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
wants to merge 8 commits into from

Conversation

lithomas1
Copy link
Member

@lithomas1 lithomas1 commented Feb 23, 2023

@simonjayhawkins simonjayhawkins added Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode Dtype Conversions Unexpected or buggy dtype conversions labels Feb 24, 2023
@lithomas1 lithomas1 marked this pull request as ready for review February 28, 2023 22:11
@lithomas1 lithomas1 requested a review from phofl March 2, 2023 13:58
if common_type.kind == "f" and not is_extension_array_dtype(common_type):
fill_value = common_type.type(np.nan)
else:
fill_value = np.nan
Copy link
Member

Choose a reason for hiding this comment

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

Any reason for not using common_dtype.na_value?

Right now "Float32" would add np.nan, but this should be pd.NA, Same for Int64 for example

Copy link
Member Author

Choose a reason for hiding this comment

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

The default fill_value is np.nan for reindex, even for EAs. That's probably something to fix elsewhere, though (IIRC, the fill value gets converted somewhere in the EA methods, maybe take? It's been a while since I looked into it though).

Copy link
Member

Choose a reason for hiding this comment

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

But why can't we supply the correct one?

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.

fill_value = np.nan
value_slice = chunk.reindex(
columns=level_vals_used, fill_value=fill_value
).values
Copy link
Member

Choose a reason for hiding this comment

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

This is something we'll have to figure out at some point, right now this coerces EA dtypes to object. But ok for another pr since we had this problem before as well...

@lithomas1 lithomas1 requested a review from phofl March 13, 2023 18:17
@lithomas1 lithomas1 requested review from phofl and removed request for phofl March 22, 2023 18:25
@github-actions
Copy link
Contributor

This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Apr 22, 2023
@mroeschke
Copy link
Member

This looked okay. Could you merge in main once more and add a whatsnew?

@mroeschke
Copy link
Member

Going to mothball for now but feel free to reopen

@mroeschke mroeschke closed this Aug 25, 2023
@mroeschke mroeschke added the Mothballed Temporarily-closed PR the author plans to return to label Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Mothballed Temporarily-closed PR the author plans to return to Reshaping Concat, Merge/Join, Stack/Unstack, Explode Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: DataFrame.stack() sometimes changes dtype from float32 to float64
4 participants