-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: pd.crosstab fails when passed multiple columns, margins True and normalize True #35150
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
BUG: pd.crosstab fails when passed multiple columns, margins True and normalize True #35150
Conversation
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.
Thanks @CloseChoice for the PR. needs a release note.
@@ -698,3 +698,46 @@ def test_margin_normalize(self): | |||
names=["A", "B"], | |||
) | |||
tm.assert_frame_equal(result, expected) | |||
|
|||
def test_crosstab_multiple_columns_normalize(self): |
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.
is it possible to parametrize the tests added in #27663, would the results be the expected transposed?
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.
Wouldn't that result in a lot of overhead defining the parameters (inputs and results)? I actually see no easy way to refactor these usiing @pytest.mark.parametrize
.
What do you mean by would the results be the expected transposed?
?
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.
thanks for the fix! just a couple nitpicks.
and as @simonjayhawkins said, you need to add a whatsnew note in 1.1.0.rst
78579a2
to
01217bc
Compare
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.
merge master and ping on green
can you merge master and will look again |
doc/source/whatsnew/v1.1.0.rst
Outdated
@@ -1166,6 +1166,7 @@ Reshaping | |||
- Fixed bug in :func:`melt` where melting MultiIndex columns with ``col_level`` > 0 would raise a ``KeyError`` on ``id_vars`` (:issue:`34129`) | |||
- Bug in :meth:`Series.where` with an empty Series and empty ``cond`` having non-bool dtype (:issue:`34592`) | |||
- Fixed regression where :meth:`DataFrame.apply` would raise ``ValueError`` for elements whth ``S`` dtype (:issue:`34529`) | |||
- Bug in func :meth:`crosstab` when using multiple columns with ``margins=True`` and ``normalize=True`` (:issue:`35144`) |
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.
can you move to 1.2
pandas/core/reshape/pivot.py
Outdated
# index/column and save the column and index margin | ||
if (margins_name not in table.iloc[-1, :].name) | ( | ||
if (margins_name not in table.iloc[-1, :].name) & ( |
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.
can you pull out
table_name = table.iloc[-1, :].name
and use that as a comparison
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.
done
…x_normalize_crosstabbing
…x_normalize_crosstabbing
Done. @jreback I'll go on vacation on Friday would be great if we can get this done before that. Otherwise I'll finish this at the beginning of September. |
thanks @CloseChoice lgtm. |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff