Skip to content

Commit

Permalink
Fixes pandas-dev#24893: re-added test
Browse files Browse the repository at this point in the history
  • Loading branch information
mabelvj committed Sep 5, 2019
1 parent d0a04f8 commit 45ffc77
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion pandas/tests/reshape/test_pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,25 @@ def test_categorical_margins_category(self, observed):
table = df.pivot_table("x", "y", "z", dropna=observed, margins=True)
tm.assert_frame_equal(table, expected)

def test_margins_casted_to_float(self, observed):
# GH #24893
df = pd.DataFrame(
{
"A": [2, 4, 6, 8],
"B": [1, 4, 5, 8],
"C": [1, 3, 4, 6],
"D": ["X", "X", "Y", "Y"],
}
)

result = pd.pivot_table(df, index="D", margins=True)
expected = pd.DataFrame(
{"A": [3, 7, 5], "B": [2.5, 6.5, 4.5], "C": [2, 5, 3.5]},
index=pd.Index(["X", "Y", "All"], name="D"),
)
table = result
tm.assert_frame_equal(result, expected)

def test_categorical_aggfunc(self, observed):
# GH 9534
df = pd.DataFrame(
Expand Down Expand Up @@ -2527,4 +2546,4 @@ def test_margin_normalize(self):
codes=[[1, 1, 2, 2, 0], [1, 2, 1, 2, 0]],
names=["A", "B"],
)
tm.assert_frame_equal(result, expected)
tm.assert_frame_equal(result, expected)

0 comments on commit 45ffc77

Please sign in to comment.