Skip to content

add test to check crosstab supports Float64 formats #50459

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

Merged
merged 2 commits into from
Dec 28, 2022

Conversation

natmokval
Copy link
Contributor

A new test is added. The test validates crosstab behavior with Float64. I have checked that the problem occurs when Float64 is used together with margins=True.
The test fails on 1.5.2 and passes on main.

@natmokval natmokval requested a review from phofl December 28, 2022 09:23
df = DataFrame(
{"A": [1, 2, 2, 1], "B": [3, 3, 4, 5], "C": [-1.0, 10.0, 1.0, 10.0]}
)
df = df.astype({"C": "Float64"})
Copy link
Member

Choose a reason for hiding this comment

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

Can you avoid the astype and define this as float immediately?

index=[1, 2, "All"],
dtype="Float64",
)
expected.columns = Index([3, 4, 5, "All"], dtype="object", name="B")
Copy link
Member

Choose a reason for hiding this comment

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

Same here, please define expected in one go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, @phofl, for your comments. I updated my PR as you suggested.

@phofl phofl added the Reshaping Concat, Merge/Join, Stack/Unstack, Explode label Dec 28, 2022
@phofl phofl added this to the 2.0 milestone Dec 28, 2022
@phofl phofl merged commit af9b72a into pandas-dev:main Dec 28, 2022
@phofl
Copy link
Member

phofl commented Dec 28, 2022

thx @natmokval

@natmokval
Copy link
Contributor Author

Thank you, @phofl, for reviewing my PR.

@natmokval natmokval deleted the 50313-Crosstab-Float-formats branch December 28, 2022 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

QST: Pandas Crosstab dos not support Float (with capital F) number formats
2 participants