55from pandas ._config import using_string_dtype
66
77from pandas ._libs import lib
8+ from pandas .compat import HAS_PYARROW
89
910from pandas .core .dtypes .common import ensure_platform_int
1011
@@ -499,8 +500,7 @@ def test_transform_select_columns(df):
499500 tm .assert_frame_equal (result , expected )
500501
501502
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 ):
504504 # case that goes through _transform_item_by_item
505505
506506 df .columns = ["A" , "B" , "B" , "D" ]
@@ -510,10 +510,16 @@ def test_transform_nuisance_raises(df):
510510 grouped = df .groupby ("A" )
511511
512512 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 ):
514520 gbc .transform (lambda x : np .mean (x ))
515521
516- with pytest .raises (TypeError , match = "Could not convert" ):
522+ with pytest .raises (TypeError , match = msg ):
517523 df .groupby ("A" ).transform (lambda x : np .mean (x ))
518524
519525
@@ -582,8 +588,7 @@ def test_transform_coercion():
582588 tm .assert_frame_equal (result , expected )
583589
584590
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 ):
587592 # GH 3740, make sure that we might upcast on item-by-item transform
588593
589594 # floats
@@ -613,8 +618,14 @@ def test_groupby_transform_with_int():
613618 "D" : "foo" ,
614619 }
615620 )
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"
616627 with np .errstate (all = "ignore" ):
617- with pytest .raises (TypeError , match = "Could not convert" ):
628+ with pytest .raises (TypeError , match = msg ):
618629 df .groupby ("A" ).transform (lambda x : (x - x .mean ()) / x .std ())
619630 result = df .groupby ("A" )[["B" , "C" ]].transform (
620631 lambda x : (x - x .mean ()) / x .std ()
@@ -626,7 +637,7 @@ def test_groupby_transform_with_int():
626637 s = Series ([2 , 3 , 4 , 10 , 5 , - 1 ])
627638 df = DataFrame ({"A" : [1 , 1 , 1 , 2 , 2 , 2 ], "B" : 1 , "C" : s , "D" : "foo" })
628639 with np .errstate (all = "ignore" ):
629- with pytest .raises (TypeError , match = "Could not convert" ):
640+ with pytest .raises (TypeError , match = msg ):
630641 df .groupby ("A" ).transform (lambda x : (x - x .mean ()) / x .std ())
631642 result = df .groupby ("A" )[["B" , "C" ]].transform (
632643 lambda x : (x - x .mean ()) / x .std ()
@@ -850,7 +861,6 @@ def test_cython_transform_frame(request, op, args, targop, df_fix, gb_target):
850861 tm .assert_frame_equal (result , expected )
851862
852863
853- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" , strict = False )
854864@pytest .mark .slow
855865@pytest .mark .parametrize (
856866 "op, args, targop" ,
@@ -901,6 +911,7 @@ def test_cython_transform_frame_column(
901911 "does not support .* operations" ,
902912 ".* is not supported for object dtype" ,
903913 "is not implemented for this dtype" ,
914+ ".* is not supported for str dtype" ,
904915 ]
905916 )
906917 with pytest .raises (TypeError , match = msg ):
0 commit comments