@@ -1601,7 +1601,6 @@ def test_pivot_table_margins_name_with_aggfunc_list(self):
1601
1601
expected = pd .DataFrame (table .values , index = ix , columns = cols )
1602
1602
tm .assert_frame_equal (table , expected )
1603
1603
1604
- @pytest .mark .xfail (reason = "GH#17035 (np.mean of ints is casted back to ints)" )
1605
1604
def test_categorical_margins (self , observed ):
1606
1605
# GH 10989
1607
1606
df = pd .DataFrame (
@@ -1615,6 +1614,24 @@ def test_categorical_margins(self, observed):
1615
1614
table = df .pivot_table ("x" , "y" , "z" , dropna = observed , margins = True )
1616
1615
tm .assert_frame_equal (table , expected )
1617
1616
1617
+ def test_margins_casted_to_float (self ):
1618
+ # GH #24893
1619
+ df = pd .DataFrame (
1620
+ {
1621
+ "A" : [2 , 4 , 6 , 8 ],
1622
+ "B" : [1 , 4 , 5 , 8 ],
1623
+ "C" : [1 , 3 , 4 , 6 ],
1624
+ "D" : ["X" , "X" , "Y" , "Y" ],
1625
+ }
1626
+ )
1627
+
1628
+ result = pd .pivot_table (df , index = "D" , margins = True )
1629
+ expected = pd .DataFrame (
1630
+ {"A" : [3 , 7 , 5 ], "B" : [2.5 , 6.5 , 4.5 ], "C" : [2 , 5 , 3.5 ]},
1631
+ index = pd .Index (["X" , "Y" , "All" ], name = "D" ),
1632
+ )
1633
+ tm .assert_frame_equal (result , expected )
1634
+
1618
1635
@pytest .mark .xfail (reason = "GH#17035 (np.mean of ints is casted back to ints)" )
1619
1636
def test_categorical_margins_category (self , observed ):
1620
1637
df = pd .DataFrame (
0 commit comments