9
9
import numpy as np
10
10
import pytest
11
11
12
+ from pandas ._config import using_pyarrow_string_dtype
13
+
12
14
from pandas .errors import PerformanceWarning
13
15
14
16
import pandas as pd
@@ -781,7 +783,8 @@ def test_pivot_with_list_like_values(self, values, method):
781
783
codes = [[0 , 0 , 0 , 1 , 1 , 1 ], [0 , 1 , 2 , 0 , 1 , 2 ]],
782
784
names = [None , "bar" ],
783
785
)
784
- expected = DataFrame (data = data , index = index , columns = columns , dtype = "object" )
786
+ expected = DataFrame (data = data , index = index , columns = columns )
787
+ expected ["baz" ] = expected ["baz" ].astype (object )
785
788
tm .assert_frame_equal (result , expected )
786
789
787
790
@pytest .mark .parametrize (
@@ -824,7 +827,8 @@ def test_pivot_with_list_like_values_nans(self, values, method):
824
827
codes = [[0 , 0 , 1 , 1 ], [0 , 1 , 0 , 1 ]],
825
828
names = [None , "foo" ],
826
829
)
827
- expected = DataFrame (data = data , index = index , columns = columns , dtype = "object" )
830
+ expected = DataFrame (data = data , index = index , columns = columns )
831
+ expected ["baz" ] = expected ["baz" ].astype (object )
828
832
tm .assert_frame_equal (result , expected )
829
833
830
834
def test_pivot_columns_none_raise_error (self ):
@@ -949,7 +953,7 @@ def test_no_col(self, data):
949
953
950
954
# to help with a buglet
951
955
data .columns = [k * 2 for k in data .columns ]
952
- msg = re .escape ("agg function failed [how->mean,dtype->object] " )
956
+ msg = re .escape ("agg function failed [how->mean,dtype->" )
953
957
with pytest .raises (TypeError , match = msg ):
954
958
data .pivot_table (index = ["AA" , "BB" ], margins = True , aggfunc = "mean" )
955
959
table = data .drop (columns = "CC" ).pivot_table (
@@ -1022,7 +1026,7 @@ def test_margin_with_only_columns_defined(
1022
1026
}
1023
1027
)
1024
1028
if aggfunc != "sum" :
1025
- msg = re .escape ("agg function failed [how->mean,dtype->object] " )
1029
+ msg = re .escape ("agg function failed [how->mean,dtype->" )
1026
1030
with pytest .raises (TypeError , match = msg ):
1027
1031
df .pivot_table (columns = columns , margins = True , aggfunc = aggfunc )
1028
1032
if "B" not in columns :
@@ -1086,7 +1090,7 @@ def test_pivot_table_multiindex_only(self, cols):
1086
1090
expected = DataFrame (
1087
1091
[[4.0 , 5.0 , 6.0 ]],
1088
1092
columns = MultiIndex .from_tuples ([(1 , 1 ), (2 , 2 ), (3 , 3 )], names = cols ),
1089
- index = Index (["v" ]),
1093
+ index = Index (["v" ], dtype = object ),
1090
1094
)
1091
1095
1092
1096
tm .assert_frame_equal (result , expected )
@@ -1803,7 +1807,7 @@ def test_pivot_table_margins_name_with_aggfunc_list(self):
1803
1807
margins_name = margins_name ,
1804
1808
aggfunc = ["mean" , "max" ],
1805
1809
)
1806
- ix = Index (["bacon" , "cheese" , margins_name ], dtype = "object" , name = "item" )
1810
+ ix = Index (["bacon" , "cheese" , margins_name ], name = "item" )
1807
1811
tups = [
1808
1812
("mean" , "cost" , "ME" ),
1809
1813
("mean" , "cost" , "T" ),
@@ -1995,7 +1999,7 @@ def test_pivot_table_not_series(self):
1995
1999
def test_pivot_margins_name_unicode (self ):
1996
2000
# issue #13292
1997
2001
greek = "\u0394 \u03bf \u03ba \u03b9 \u03bc \u03ae "
1998
- frame = DataFrame ({"foo" : [1 , 2 , 3 ]})
2002
+ frame = DataFrame ({"foo" : [1 , 2 , 3 ]}, columns = Index ([ "foo" ], dtype = object ) )
1999
2003
table = pivot_table (
2000
2004
frame , index = ["foo" ], aggfunc = len , margins = True , margins_name = greek
2001
2005
)
@@ -2607,6 +2611,7 @@ def test_pivot_columns_not_given(self):
2607
2611
with pytest .raises (TypeError , match = "missing 1 required keyword-only argument" ):
2608
2612
df .pivot () # pylint: disable=missing-kwoa
2609
2613
2614
+ @pytest .mark .xfail (using_pyarrow_string_dtype (), reason = "None is cast to NaN" )
2610
2615
def test_pivot_columns_is_none (self ):
2611
2616
# GH#48293
2612
2617
df = DataFrame ({None : [1 ], "b" : 2 , "c" : 3 })
@@ -2622,6 +2627,7 @@ def test_pivot_columns_is_none(self):
2622
2627
expected = DataFrame ({1 : 3 }, index = Index ([2 ], name = "b" ))
2623
2628
tm .assert_frame_equal (result , expected )
2624
2629
2630
+ @pytest .mark .xfail (using_pyarrow_string_dtype (), reason = "None is cast to NaN" )
2625
2631
def test_pivot_index_is_none (self ):
2626
2632
# GH#48293
2627
2633
df = DataFrame ({None : [1 ], "b" : 2 , "c" : 3 })
@@ -2635,6 +2641,7 @@ def test_pivot_index_is_none(self):
2635
2641
expected = DataFrame (3 , index = [1 ], columns = Index ([2 ], name = "b" ))
2636
2642
tm .assert_frame_equal (result , expected )
2637
2643
2644
+ @pytest .mark .xfail (using_pyarrow_string_dtype (), reason = "None is cast to NaN" )
2638
2645
def test_pivot_values_is_none (self ):
2639
2646
# GH#48293
2640
2647
df = DataFrame ({None : [1 ], "b" : 2 , "c" : 3 })
0 commit comments