@@ -1601,53 +1601,33 @@ 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
-
1604
+ @ pytest . mark . xfail ( reason = "GH#17035 (np.mean of ints is casted back to ints)" )
1605
1605
def test_categorical_margins (self , observed ):
1606
1606
# GH 10989
1607
1607
df = pd .DataFrame (
1608
1608
{"x" : np .arange (8 ), "y" : np .arange (8 ) // 4 , "z" : np .arange (8 ) % 2 }
1609
1609
)
1610
1610
1611
- expected = pd .DataFrame ([[1 , 2 , 1.5 ], [5 , 6 , 5.5 ], [3 , 4 , 3.5 ]])
1611
+ expected = pd .DataFrame ([[1.0 , 2.0 , 1.5 ], [5 , 6 , 5.5 ], [3 , 4 , 3.5 ]])
1612
1612
expected .index = Index ([0 , 1 , "All" ], name = "y" )
1613
1613
expected .columns = Index ([0 , 1 , "All" ], name = "z" )
1614
1614
1615
1615
table = df .pivot_table ("x" , "y" , "z" , dropna = observed , margins = True )
1616
1616
tm .assert_frame_equal (table , expected )
1617
1617
1618
-
1619
- def test_margins_casted_to_float (self , observed ):
1620
- # GH #24893
1621
- df = pd .DataFrame (
1622
- {
1623
- "A" : [2 , 4 , 6 , 8 ],
1624
- "B" : [1 , 4 , 5 , 8 ],
1625
- "C" : [1 , 3 , 4 , 6 ],
1626
- "D" : ["X" , "X" , "Y" , "Y" ],
1627
- }
1628
- )
1629
-
1630
- result = pd .pivot_table (df , index = "D" , margins = True )
1631
- expected = pd .DataFrame (
1632
- {"A" : [3 , 7 , 5 ], "B" : [2.5 , 6.5 , 4.5 ], "C" : [2 , 5 , 3.5 ]},
1633
- index = pd .Index (["X" , "Y" , "All" ], name = "D" ),
1634
- )
1635
- table = result
1636
- tm .assert_frame_equal (result , expected )
1637
-
1618
+ @pytest .mark .xfail (reason = "GH#17035 (np.mean of ints is casted back to ints)" )
1638
1619
def test_categorical_margins_category (self , observed ):
1639
1620
df = pd .DataFrame (
1640
1621
{"x" : np .arange (8 ), "y" : np .arange (8 ) // 4 , "z" : np .arange (8 ) % 2 }
1641
1622
)
1642
1623
1643
- expected = pd .DataFrame ([[1 , 2 , 1.5 ], [5 , 6 , 5.5 ], [3 , 4 , 3.5 ]])
1624
+ expected = pd .DataFrame ([[1.0 , 2.0 , 1.5 ], [5 , 6 , 5.5 ], [3 , 4 , 3.5 ]])
1644
1625
expected .index = Index ([0 , 1 , "All" ], name = "y" )
1645
1626
expected .columns = Index ([0 , 1 , "All" ], name = "z" )
1646
1627
1647
1628
df .y = df .y .astype ("category" )
1648
1629
df .z = df .z .astype ("category" )
1649
1630
table = df .pivot_table ("x" , "y" , "z" , dropna = observed , margins = True )
1650
-
1651
1631
tm .assert_frame_equal (table , expected )
1652
1632
1653
1633
def test_categorical_aggfunc (self , observed ):
@@ -2547,4 +2527,4 @@ def test_margin_normalize(self):
2547
2527
codes = [[1 , 1 , 2 , 2 , 0 ], [1 , 2 , 1 , 2 , 0 ]],
2548
2528
names = ["A" , "B" ],
2549
2529
)
2550
- tm .assert_frame_equal (result , expected )
2530
+ tm .assert_frame_equal (result , expected )
0 commit comments