-
-
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
Changes from 3 commits
c5f4df6
7547903
0c8a66c
c536e78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -286,6 +286,27 @@ def test_pivot_with_interval_index(self, interval_values, dropna): | |||||||||||||
expected = DataFrame({"B": 1}, index=Index(interval_values.unique(), name="A")) | ||||||||||||||
tm.assert_frame_equal(result, expected) | ||||||||||||||
|
||||||||||||||
def test_pivot_with_interval_index_margins(self): | ||||||||||||||
# GH 25815 | ||||||||||||||
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'), | ||||||||||||||
"B": ["a", "b", "a", "b"], | ||||||||||||||
"C": pd.Categorical(ordered_cat, ordered=True).sort_values( | ||||||||||||||
ascending=False | ||||||||||||||
), | ||||||||||||||
} | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
pivot_tab = pd.pivot_table( | ||||||||||||||
df, index="C", columns="B", values="A", aggfunc="sum", margins=True | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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) |
||||||||||||||
tm.assert_series_equal(result, expected) | ||||||||||||||
|
||||||||||||||
def test_pass_array(self): | ||||||||||||||
result = self.data.pivot_table("D", index=self.data.A, columns=self.data.C) | ||||||||||||||
expected = self.data.pivot_table("D", index="A", columns="C") | ||||||||||||||
|
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.