Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pandas/core/nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,10 @@ def nanmean(
>>> nanops.nanmean(s.values)
np.float64(1.5)
"""
if values.dtype == object and len(values) > 1_000 and mask is None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just not infer_dtype(values) for object dtype to raise early if the inferred type are strings?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. infer_dtype is a pattern im trying to move us away from, 2) that would still require a full pass through the data, 3) that would for strings but not hypothetical other cases

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK sure thing. Should the 5 below then match the 1000 above then for consistency?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, will update

# GH#54754 if we are going to fail, try to fail-fast
nanmean(values[:1000], axis=axis, skipna=skipna)

dtype = values.dtype
values, mask = _get_values(values, skipna, fill_value=0, mask=mask)
dtype_sum = _get_dtype_max(dtype)
Expand Down
Loading