5
5
from pandas ._config import using_string_dtype
6
6
7
7
from pandas ._libs import lib
8
+ from pandas .compat import HAS_PYARROW
8
9
9
10
from pandas .core .dtypes .common import ensure_platform_int
10
11
@@ -499,8 +500,7 @@ def test_transform_select_columns(df):
499
500
tm .assert_frame_equal (result , expected )
500
501
501
502
502
- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" )
503
- def test_transform_nuisance_raises (df ):
503
+ def test_transform_nuisance_raises (df , using_infer_string ):
504
504
# case that goes through _transform_item_by_item
505
505
506
506
df .columns = ["A" , "B" , "B" , "D" ]
@@ -510,10 +510,16 @@ def test_transform_nuisance_raises(df):
510
510
grouped = df .groupby ("A" )
511
511
512
512
gbc = grouped ["B" ]
513
- with pytest .raises (TypeError , match = "Could not convert" ):
513
+ msg = "Could not convert"
514
+ if using_infer_string :
515
+ if df .columns .dtype .storage == "pyarrow" :
516
+ msg = "with dtype str does not support operation 'mean'"
517
+ else :
518
+ msg = "Cannot perform reduction 'mean' with string dtype"
519
+ with pytest .raises (TypeError , match = msg ):
514
520
gbc .transform (lambda x : np .mean (x ))
515
521
516
- with pytest .raises (TypeError , match = "Could not convert" ):
522
+ with pytest .raises (TypeError , match = msg ):
517
523
df .groupby ("A" ).transform (lambda x : np .mean (x ))
518
524
519
525
@@ -582,8 +588,7 @@ def test_transform_coercion():
582
588
tm .assert_frame_equal (result , expected )
583
589
584
590
585
- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" )
586
- def test_groupby_transform_with_int ():
591
+ def test_groupby_transform_with_int (using_infer_string ):
587
592
# GH 3740, make sure that we might upcast on item-by-item transform
588
593
589
594
# floats
@@ -613,8 +618,14 @@ def test_groupby_transform_with_int():
613
618
"D" : "foo" ,
614
619
}
615
620
)
621
+ msg = "Could not convert"
622
+ if using_infer_string :
623
+ if HAS_PYARROW :
624
+ msg = "with dtype str does not support operation 'mean'"
625
+ else :
626
+ msg = "Cannot perform reduction 'mean' with string dtype"
616
627
with np .errstate (all = "ignore" ):
617
- with pytest .raises (TypeError , match = "Could not convert" ):
628
+ with pytest .raises (TypeError , match = msg ):
618
629
df .groupby ("A" ).transform (lambda x : (x - x .mean ()) / x .std ())
619
630
result = df .groupby ("A" )[["B" , "C" ]].transform (
620
631
lambda x : (x - x .mean ()) / x .std ()
@@ -626,7 +637,7 @@ def test_groupby_transform_with_int():
626
637
s = Series ([2 , 3 , 4 , 10 , 5 , - 1 ])
627
638
df = DataFrame ({"A" : [1 , 1 , 1 , 2 , 2 , 2 ], "B" : 1 , "C" : s , "D" : "foo" })
628
639
with np .errstate (all = "ignore" ):
629
- with pytest .raises (TypeError , match = "Could not convert" ):
640
+ with pytest .raises (TypeError , match = msg ):
630
641
df .groupby ("A" ).transform (lambda x : (x - x .mean ()) / x .std ())
631
642
result = df .groupby ("A" )[["B" , "C" ]].transform (
632
643
lambda x : (x - x .mean ()) / x .std ()
@@ -850,7 +861,6 @@ def test_cython_transform_frame(request, op, args, targop, df_fix, gb_target):
850
861
tm .assert_frame_equal (result , expected )
851
862
852
863
853
- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" , strict = False )
854
864
@pytest .mark .slow
855
865
@pytest .mark .parametrize (
856
866
"op, args, targop" ,
@@ -901,6 +911,7 @@ def test_cython_transform_frame_column(
901
911
"does not support .* operations" ,
902
912
".* is not supported for object dtype" ,
903
913
"is not implemented for this dtype" ,
914
+ ".* is not supported for str dtype" ,
904
915
]
905
916
)
906
917
with pytest .raises (TypeError , match = msg ):
0 commit comments