@@ -702,15 +702,20 @@ def test_keep_nuisance_agg(df, agg_function):
702
702
["sum" , "mean" , "prod" , "std" , "var" , "sem" , "median" ],
703
703
)
704
704
@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 ):
706
706
# GH 38774, GH 38815
707
707
grouped = df .groupby ("A" )
708
708
709
709
no_drop_nuisance = ("var" , "std" , "sem" , "mean" , "prod" , "median" )
710
+ if using_infer_string :
711
+ no_drop_nuisance += ("sum" ,)
710
712
if agg_function in no_drop_nuisance and not numeric_only :
711
713
# Added numeric_only as part of GH#46560; these do not drop nuisance
712
714
# 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" ):
714
719
klass = ValueError
715
720
msg = "could not convert string to float: 'one'"
716
721
else :
@@ -1772,6 +1777,7 @@ def get_categorical_invalid_expected():
1772
1777
is_per = isinstance (df .dtypes .iloc [0 ], pd .PeriodDtype )
1773
1778
is_dt64 = df .dtypes .iloc [0 ].kind == "M"
1774
1779
is_cat = isinstance (values , Categorical )
1780
+ is_str = isinstance (df .dtypes .iloc [0 ], pd .StringDtype )
1775
1781
1776
1782
if (
1777
1783
isinstance (values , Categorical )
@@ -1796,13 +1802,15 @@ def get_categorical_invalid_expected():
1796
1802
1797
1803
if op in ["prod" , "sum" , "skew" ]:
1798
1804
# 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 :
1800
1806
# GH#41291
1801
1807
# datetime64 -> prod and sum are invalid
1802
1808
if is_dt64 :
1803
1809
msg = "datetime64 type does not support"
1804
1810
elif is_per :
1805
1811
msg = "Period type does not support"
1812
+ elif is_str :
1813
+ msg = "str dtype does not support"
1806
1814
else :
1807
1815
msg = "category type does not support"
1808
1816
if op == "skew" :
0 commit comments