Skip to content

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

Merged
merged 4 commits into from
Jul 9, 2019

Conversation

peterpanmj
Copy link
Contributor

Copy link
Member

@WillAyd WillAyd left a 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!

aggfunc='sum', margins=True)

result = pivot_tab['All']
expected = pivot_tab.iloc[:, :-1].sum(axis=1)
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 just construct this manually? I think generating the result and expected values from the same variable can let bugs pass through undetected


result = pivot_tab['All']
expected = pivot_tab.iloc[:, :-1].sum(axis=1)
tm.assert_series_equal(result, expected, check_dtype=False,
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 remove check_dtype and check_names?

@WillAyd WillAyd added Categorical Categorical Data Type Testing pandas testing functions or related to the test suite labels Jul 5, 2019
@simonjayhawkins simonjayhawkins added the Reshaping Concat, Merge/Join, Stack/Unstack, Explode label Jul 5, 2019
@simonjayhawkins
Copy link
Member

simonjayhawkins commented Jul 6, 2019

see #27233 for details on black code style to resolve the CI failure.

@simonjayhawkins simonjayhawkins added this to the 0.25.0 milestone Jul 8, 2019
Copy link
Member

@simonjayhawkins simonjayhawkins left a 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

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'),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"A": np.arange(4, 0, -1).astype('int32'),
"A": np.arange(4, 0, -1, dtype=np.intp),

)

result = pivot_tab["All"]
expected = pd.Series([3, 7, 10], index=result.index, name="All", dtype="int32")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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",
)

Copy link
Contributor Author

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 ?

Copy link
Member

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)

@jreback jreback merged commit dc5a848 into pandas-dev:master Jul 9, 2019
@peterpanmj peterpanmj deleted the add_pivot_test branch January 31, 2023 05:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Categorical Categorical Data Type Reshaping Concat, Merge/Join, Stack/Unstack, Explode Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

wrong aggregated results when pivot_table index is ordered categorical data
4 participants