Skip to content

Commit 8f8dfd8

Browse files
committed
BUG: make .mean() raise an exception for strings
1 parent f3f90c3 commit 8f8dfd8

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pandas/core/nanops.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
is_numeric_dtype,
4444
is_object_dtype,
4545
is_scalar,
46+
is_string_dtype,
4647
is_timedelta64_dtype,
4748
needs_i8_conversion,
4849
pandas_dtype,
@@ -691,7 +692,11 @@ def nanmean(
691692
dtype_count = dtype
692693

693694
count = _get_counts(values.shape, mask, axis, dtype=dtype_count)
694-
the_sum = _ensure_numeric(values.sum(axis, dtype=dtype_sum))
695+
the_sum = values.sum(axis, dtype=dtype_sum)
696+
if isinstance(the_sum, str) or is_string_dtype(the_sum):
697+
raise TypeError("cannot find the mean of type 'str'")
698+
else:
699+
_ensure_numeric(the_sum)
695700

696701
if axis is not None and getattr(the_sum, "ndim", False):
697702
count = cast(np.ndarray, count)

0 commit comments

Comments
 (0)