-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TST: add tests to validate margin results for pivot (#25815) #27245
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
Conversation
532860e
to
afe8ab8
Compare
afe8ab8
to
c5f4df6
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.
I think this was fixed as part of #27071 - didn't see a specific test for this at first glance but if can double check would be great!
pandas/tests/reshape/test_pivot.py
Outdated
aggfunc='sum', margins=True) | ||
|
||
result = pivot_tab['All'] | ||
expected = pivot_tab.iloc[:, :-1].sum(axis=1) |
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 just construct this manually? I think generating the result
and expected
values from the same variable can let bugs pass through undetected
pandas/tests/reshape/test_pivot.py
Outdated
|
||
result = pivot_tab['All'] | ||
expected = pivot_tab.iloc[:, :-1].sum(axis=1) | ||
tm.assert_series_equal(result, expected, check_dtype=False, |
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 remove check_dtype
and check_names
?
see #27233 for details on black code style to resolve the CI failure. |
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.
@peterpanmj changes look good. just a couple more and I think we're done. @WillAyd
pandas/tests/reshape/test_pivot.py
Outdated
ordered_cat = pd.IntervalIndex.from_arrays([0, 0, 1, 1], [1, 1, 2, 2]) | ||
df = pd.DataFrame( | ||
{ | ||
"A": np.arange(4, 0, -1).astype('int32'), |
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.
"A": np.arange(4, 0, -1).astype('int32'), | |
"A": np.arange(4, 0, -1, dtype=np.intp), |
pandas/tests/reshape/test_pivot.py
Outdated
) | ||
|
||
result = pivot_tab["All"] | ||
expected = pd.Series([3, 7, 10], index=result.index, name="All", dtype="int32") |
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.
expected = pd.Series([3, 7, 10], index=result.index, name="All", dtype="int32") | |
expected = Series( | |
[3, 7, 10], | |
index=Index([pd.Interval(0, 1), pd.Interval(1, 2), "All"], name="C"), | |
name="All", | |
) |
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.
Why not using index from result , seems easier ?
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.
I'm not sure that would be in the spirit of constructing the expected result explicitly as suggested in #27245 (comment)
git diff upstream/master -u -- "*.py" | flake8 --diff