Skip to content

Commit 38df377

Browse files
committed
Add whatsnew entry for mean
1 parent 34e91fc commit 38df377

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

doc/source/whatsnew/v1.4.0.rst

+31-3
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,38 @@ Now the float-dtype is respected. Since the common dtype for these DataFrames is
240240
241241
res
242242
243-
.. _whatsnew_140.notable_bug_fixes.notable_bug_fix3:
243+
.. _whatsnew_140.notable_bug_fixes.string_to_numeric_in_mean:
244244

245-
notable_bug_fix3
246-
^^^^^^^^^^^^^^^^
245+
Implicit conversion of string to numeric type in mean
246+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
247+
248+
When computing the ``mean`` of a :class:`Series` or :class:`DataFrame` with a string-type value, the elements are concatenated
249+
to a single string then coerced to a numeric type implicitly before computing the mean. This can lead to unexpected results:
250+
251+
.. code-block:: ipython
252+
253+
In [5]: df = DataFrame({
254+
"A": ["1", "2", "3"],
255+
"B": ["0", "1", "J"],
256+
})
257+
In [6]: df.mean(numeric_only=False)
258+
Out[6]:
259+
A 41.00000+0.00000j
260+
C 0.000000+0.333333j
261+
dtype: complex128
262+
263+
Now, an exception will be raised whenever ``mean`` is called on string-type columns or :class:`Series`.
264+
265+
.. code-block:: ipython
266+
267+
In [7]: df = DataFrame({
268+
"A": ["1", "2", "3"],
269+
"B": ["0", "1", "J"],
270+
})
271+
In [8]: df.mean(numeric_only=False)
272+
Out[8]:
273+
...
274+
TypeError: cannot find the mean of type 'str'
247275
248276
.. ---------------------------------------------------------------------------
249277

0 commit comments

Comments
 (0)