@@ -528,6 +528,33 @@ def test_mean_mixed_string_decimal(self):
528
528
expected = Series ([2.7 , 681.6 ], index = ["A" , "C" ])
529
529
tm .assert_series_equal (result , expected )
530
530
531
+ def test_mean_string (self ):
532
+ # https://github.com/pandas-dev/pandas/issues/44008
533
+ # https://github.com/pandas-dev/pandas/issues/34671
534
+ # https://github.com/pandas-dev/pandas/issues/22642
535
+ # https://github.com/pandas-dev/pandas/issues/26927
536
+ # https://github.com/pandas-dev/pandas/issues/13916
537
+ # https://github.com/pandas-dev/pandas/issues/36703
538
+
539
+ df = DataFrame (
540
+ {
541
+ "A" : ["1" , "2" , "3" ],
542
+ "B" : ["a" , "b" , "c" ],
543
+ "C" : [1 , 2 , 3 ],
544
+ "D" : ["0" , "1" , "J" ],
545
+ }
546
+ )
547
+ with tm .assert_produces_warning (FutureWarning , match = "Dropping of nuisance" ):
548
+ result = df .mean ()
549
+ expected = Series ([2.0 ], index = ["C" ])
550
+ tm .assert_series_equal (result , expected )
551
+ msg = "cannot find the mean of type 'str'"
552
+ with pytest .raises (TypeError , match = msg ):
553
+ df .mean (numeric_only = False )
554
+ result = df .sum ()
555
+ expected = Series (["123" , "abc" , 6 , "01J" ], index = ["A" , "B" , "C" , "D" ])
556
+ tm .assert_series_equal (result , expected )
557
+
531
558
def test_var_std (self , datetime_frame ):
532
559
result = datetime_frame .std (ddof = 4 )
533
560
expected = datetime_frame .apply (lambda x : x .std (ddof = 4 ))
0 commit comments