@@ -1601,21 +1601,22 @@ 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)" )
1604
+
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.0 , 2.0 , 1.5 ], [5 , 6 , 5.5 ], [3 , 4 , 3.5 ]])
1611
+ expected = pd .DataFrame ([[1 , 2 , 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
- def test_margins_casted_to_float (self ):
1618
+
1619
+ def test_margins_casted_to_float (self , observed ):
1619
1620
# GH #24893
1620
1621
df = pd .DataFrame (
1621
1622
{
@@ -1631,21 +1632,22 @@ def test_margins_casted_to_float(self):
1631
1632
{"A" : [3 , 7 , 5 ], "B" : [2.5 , 6.5 , 4.5 ], "C" : [2 , 5 , 3.5 ]},
1632
1633
index = pd .Index (["X" , "Y" , "All" ], name = "D" ),
1633
1634
)
1635
+ table = result
1634
1636
tm .assert_frame_equal (result , expected )
1635
1637
1636
- @pytest .mark .xfail (reason = "GH#17035 (np.mean of ints is casted back to ints)" )
1637
1638
def test_categorical_margins_category (self , observed ):
1638
1639
df = pd .DataFrame (
1639
1640
{"x" : np .arange (8 ), "y" : np .arange (8 ) // 4 , "z" : np .arange (8 ) % 2 }
1640
1641
)
1641
1642
1642
- expected = pd .DataFrame ([[1.0 , 2.0 , 1.5 ], [5 , 6 , 5.5 ], [3 , 4 , 3.5 ]])
1643
+ expected = pd .DataFrame ([[1 , 2 , 1.5 ], [5 , 6 , 5.5 ], [3 , 4 , 3.5 ]])
1643
1644
expected .index = Index ([0 , 1 , "All" ], name = "y" )
1644
1645
expected .columns = Index ([0 , 1 , "All" ], name = "z" )
1645
1646
1646
1647
df .y = df .y .astype ("category" )
1647
1648
df .z = df .z .astype ("category" )
1648
1649
table = df .pivot_table ("x" , "y" , "z" , dropna = observed , margins = True )
1650
+
1649
1651
tm .assert_frame_equal (table , expected )
1650
1652
1651
1653
def test_categorical_aggfunc (self , observed ):
0 commit comments