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