@@ -702,15 +702,20 @@ def test_keep_nuisance_agg(df, agg_function):
702702 ["sum" , "mean" , "prod" , "std" , "var" , "sem" , "median" ],
703703)
704704@pytest .mark .parametrize ("numeric_only" , [True , False ])
705- def test_omit_nuisance_agg (df , agg_function , numeric_only ):
705+ def test_omit_nuisance_agg (df , agg_function , numeric_only , using_infer_string ):
706706 # GH 38774, GH 38815
707707 grouped = df .groupby ("A" )
708708
709709 no_drop_nuisance = ("var" , "std" , "sem" , "mean" , "prod" , "median" )
710+ if using_infer_string :
711+ no_drop_nuisance += ("sum" ,)
710712 if agg_function in no_drop_nuisance and not numeric_only :
711713 # Added numeric_only as part of GH#46560; these do not drop nuisance
712714 # columns when numeric_only is False
713- if agg_function in ("std" , "sem" ):
715+ if using_infer_string :
716+ msg = f"str dtype does not support { agg_function } operations"
717+ klass = TypeError
718+ elif agg_function in ("std" , "sem" ):
714719 klass = ValueError
715720 msg = "could not convert string to float: 'one'"
716721 else :
@@ -1772,6 +1777,7 @@ def get_categorical_invalid_expected():
17721777 is_per = isinstance (df .dtypes .iloc [0 ], pd .PeriodDtype )
17731778 is_dt64 = df .dtypes .iloc [0 ].kind == "M"
17741779 is_cat = isinstance (values , Categorical )
1780+ is_str = isinstance (df .dtypes .iloc [0 ], pd .StringDtype )
17751781
17761782 if (
17771783 isinstance (values , Categorical )
@@ -1796,13 +1802,15 @@ def get_categorical_invalid_expected():
17961802
17971803 if op in ["prod" , "sum" , "skew" ]:
17981804 # ops that require more than just ordered-ness
1799- if is_dt64 or is_cat or is_per :
1805+ if is_dt64 or is_cat or is_per or is_str :
18001806 # GH#41291
18011807 # datetime64 -> prod and sum are invalid
18021808 if is_dt64 :
18031809 msg = "datetime64 type does not support"
18041810 elif is_per :
18051811 msg = "Period type does not support"
1812+ elif is_str :
1813+ msg = "str dtype does not support"
18061814 else :
18071815 msg = "category type does not support"
18081816 if op == "skew" :
0 commit comments