Skip to content

Commit 1c81cf6

Browse files
committed
Add tests for mean with strings
1 parent adb58ce commit 1c81cf6

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

pandas/tests/frame/test_reductions.py

+27
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,33 @@ def test_mean_mixed_string_decimal(self):
524524
expected = Series([2.7, 681.6], index=["A", "C"])
525525
tm.assert_series_equal(result, expected)
526526

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+
527554
def test_var_std(self, datetime_frame):
528555
result = datetime_frame.std(ddof=4)
529556
expected = datetime_frame.apply(lambda x: x.std(ddof=4))

0 commit comments

Comments
 (0)