@@ -459,10 +459,11 @@ def _supports_reduction(self, ser: pd.Series, op_name: str) -> bool:
459
459
pass
460
460
else :
461
461
return False
462
+ elif pa .types .is_binary (pa_dtype ) and op_name == "sum" :
463
+ return False
462
464
elif (
463
465
pa .types .is_string (pa_dtype ) or pa .types .is_binary (pa_dtype )
464
466
) and op_name in [
465
- "sum" ,
466
467
"mean" ,
467
468
"median" ,
468
469
"prod" ,
@@ -553,6 +554,7 @@ def test_reduce_series_boolean(
553
554
return super ().test_reduce_series_boolean (data , all_boolean_reductions , skipna )
554
555
555
556
def _get_expected_reduction_dtype (self , arr , op_name : str , skipna : bool ):
557
+ pa_type = arr ._pa_array .type
556
558
if op_name in ["max" , "min" ]:
557
559
cmp_dtype = arr .dtype
558
560
elif arr .dtype .name == "decimal128(7, 3)[pyarrow]" :
@@ -562,6 +564,8 @@ def _get_expected_reduction_dtype(self, arr, op_name: str, skipna: bool):
562
564
cmp_dtype = "float64[pyarrow]"
563
565
elif op_name in ["median" , "var" , "std" , "mean" , "skew" ]:
564
566
cmp_dtype = "float64[pyarrow]"
567
+ elif op_name == "sum" and pa .types .is_string (pa_type ):
568
+ cmp_dtype = arr .dtype
565
569
else :
566
570
cmp_dtype = {
567
571
"i" : "int64[pyarrow]" ,
@@ -585,26 +589,6 @@ def test_median_not_approximate(self, typ):
585
589
result = pd .Series ([1 , 2 ], dtype = f"{ typ } [pyarrow]" ).median ()
586
590
assert result == 1.5
587
591
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
-
608
592
def test_construct_from_string_own_name (self , dtype , request ):
609
593
pa_dtype = dtype .pyarrow_dtype
610
594
if pa .types .is_decimal (pa_dtype ):
0 commit comments