@@ -240,13 +240,13 @@ def test_pivot_with_non_observable_dropna(self, dropna):
240
240
categories = ["low" , "high" ],
241
241
ordered = True ,
242
242
),
243
- "B" : range ( 5 ) ,
243
+ "B" : [ 0.0 , 1.0 , 2.0 , 3.0 , 4.0 ] ,
244
244
}
245
245
)
246
246
247
247
result = df .pivot_table (index = "A" , values = "B" , dropna = dropna )
248
248
expected = DataFrame (
249
- {"B" : [2 , 3 ]},
249
+ {"B" : [2.0 , 3.0 ]},
250
250
index = Index (
251
251
Categorical .from_codes (
252
252
[0 , 1 ], categories = ["low" , "high" ], ordered = True
@@ -279,6 +279,8 @@ def test_pivot_with_non_observable_dropna(self, dropna):
279
279
name = "A" ,
280
280
),
281
281
)
282
+ if not dropna :
283
+ expected ["B" ] = expected ["B" ].astype (float )
282
284
283
285
tm .assert_frame_equal (result , expected )
284
286
@@ -287,6 +289,8 @@ def test_pivot_with_interval_index(self, interval_values, dropna):
287
289
df = DataFrame ({"A" : interval_values , "B" : 1 })
288
290
result = df .pivot_table (index = "A" , values = "B" , dropna = dropna )
289
291
expected = DataFrame ({"B" : 1 }, index = Index (interval_values .unique (), name = "A" ))
292
+ if not dropna :
293
+ expected = expected .astype (float )
290
294
tm .assert_frame_equal (result , expected )
291
295
292
296
def test_pivot_with_interval_index_margins (self ):
@@ -388,10 +392,7 @@ def test_pivot_preserve_dtypes(self, columns, values):
388
392
)
389
393
390
394
result = dict (df_res .dtypes )
391
- expected = {
392
- col : np .dtype ("O" ) if col [0 ].startswith ("b" ) else np .dtype ("float64" )
393
- for col in df_res
394
- }
395
+ expected = {col : np .dtype ("float64" ) for col in df_res }
395
396
assert result == expected
396
397
397
398
def test_pivot_no_values (self ):
@@ -1711,8 +1712,13 @@ def test_pivot_table_margins_name_with_aggfunc_list(self):
1711
1712
expected = DataFrame (table .values , index = ix , columns = cols )
1712
1713
tm .assert_frame_equal (table , expected )
1713
1714
1714
- @pytest .mark .xfail (reason = "GH#17035 (np.mean of ints is casted back to ints)" )
1715
- def test_categorical_margins (self , observed ):
1715
+ def test_categorical_margins (self , observed , request ):
1716
+ if observed :
1717
+ request .node .add_marker (
1718
+ pytest .mark .xfail (
1719
+ reason = "GH#17035 (np.mean of ints is casted back to ints)"
1720
+ )
1721
+ )
1716
1722
# GH 10989
1717
1723
df = DataFrame (
1718
1724
{"x" : np .arange (8 ), "y" : np .arange (8 ) // 4 , "z" : np .arange (8 ) % 2 }
@@ -1725,8 +1731,13 @@ def test_categorical_margins(self, observed):
1725
1731
table = df .pivot_table ("x" , "y" , "z" , dropna = observed , margins = True )
1726
1732
tm .assert_frame_equal (table , expected )
1727
1733
1728
- @pytest .mark .xfail (reason = "GH#17035 (np.mean of ints is casted back to ints)" )
1729
- def test_categorical_margins_category (self , observed ):
1734
+ def test_categorical_margins_category (self , observed , request ):
1735
+ if observed :
1736
+ request .node .add_marker (
1737
+ pytest .mark .xfail (
1738
+ reason = "GH#17035 (np.mean of ints is casted back to ints)"
1739
+ )
1740
+ )
1730
1741
df = DataFrame (
1731
1742
{"x" : np .arange (8 ), "y" : np .arange (8 ) // 4 , "z" : np .arange (8 ) % 2 }
1732
1743
)
0 commit comments