@@ -459,10 +459,11 @@ def _supports_reduction(self, ser: pd.Series, op_name: str) -> bool:
459459 pass
460460 else :
461461 return False
462+ elif pa .types .is_binary (pa_dtype ) and op_name == "sum" :
463+ return False
462464 elif (
463465 pa .types .is_string (pa_dtype ) or pa .types .is_binary (pa_dtype )
464466 ) and op_name in [
465- "sum" ,
466467 "mean" ,
467468 "median" ,
468469 "prod" ,
@@ -553,6 +554,7 @@ def test_reduce_series_boolean(
553554 return super ().test_reduce_series_boolean (data , all_boolean_reductions , skipna )
554555
555556 def _get_expected_reduction_dtype (self , arr , op_name : str , skipna : bool ):
557+ pa_type = arr ._pa_array .type
556558 if op_name in ["max" , "min" ]:
557559 cmp_dtype = arr .dtype
558560 elif arr .dtype .name == "decimal128(7, 3)[pyarrow]" :
@@ -562,6 +564,8 @@ def _get_expected_reduction_dtype(self, arr, op_name: str, skipna: bool):
562564 cmp_dtype = "float64[pyarrow]"
563565 elif op_name in ["median" , "var" , "std" , "mean" , "skew" ]:
564566 cmp_dtype = "float64[pyarrow]"
567+ elif op_name == "sum" and pa .types .is_string (pa_type ):
568+ cmp_dtype = arr .dtype
565569 else :
566570 cmp_dtype = {
567571 "i" : "int64[pyarrow]" ,
@@ -585,26 +589,6 @@ def test_median_not_approximate(self, typ):
585589 result = pd .Series ([1 , 2 ], dtype = f"{ typ } [pyarrow]" ).median ()
586590 assert result == 1.5
587591
588- def test_in_numeric_groupby (self , data_for_grouping ):
589- dtype = data_for_grouping .dtype
590- if is_string_dtype (dtype ):
591- df = pd .DataFrame (
592- {
593- "A" : [1 , 1 , 2 , 2 , 3 , 3 , 1 , 4 ],
594- "B" : data_for_grouping ,
595- "C" : [1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ],
596- }
597- )
598-
599- expected = pd .Index (["C" ])
600- msg = re .escape (f"agg function failed [how->sum,dtype->{ dtype } " )
601- with pytest .raises (TypeError , match = msg ):
602- df .groupby ("A" ).sum ()
603- result = df .groupby ("A" ).sum (numeric_only = True ).columns
604- tm .assert_index_equal (result , expected )
605- else :
606- super ().test_in_numeric_groupby (data_for_grouping )
607-
608592 def test_construct_from_string_own_name (self , dtype , request ):
609593 pa_dtype = dtype .pyarrow_dtype
610594 if pa .types .is_decimal (pa_dtype ):
0 commit comments