Skip to content

Commit be053ce

Browse files
committed
Add whatsnew;fix conflict
1 parent 1c81cf6 commit be053ce

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

doc/source/whatsnew/v1.4.0.rst

+33
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,39 @@ second column is instead renamed to ``a.2``.
346346
347347
res
348348
349+
.. _whatsnew_140.notable_bug_fixes.mean_implicit_conversion_to_numeric:
350+
351+
Implicit conversion of string to numeric type in mean
352+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
353+
354+
When computing the ``mean`` of a :class:`Series` or :class:`DataFrame` with a string-type value, the elements are concatenated
355+
to a single string then coerced to a numeric type implicitly before computing the mean. This can lead to unexpected results:
356+
357+
.. code-block:: ipython
358+
359+
In [5]: df = DataFrame({
360+
"A": ["1", "2", "3"],
361+
"B": ["0", "1", "J"],
362+
})
363+
In [6]: df.mean(numeric_only=False)
364+
Out[6]:
365+
A 41.00000+0.00000j
366+
C 0.000000+0.333333j
367+
dtype: complex128
368+
369+
Now, an exception will be raised whenever ``mean`` is called on a string-type column or :class:`Series`.
370+
371+
.. code-block:: ipython
372+
373+
In [7]: df = DataFrame({
374+
"A": ["1", "2", "3"],
375+
"B": ["0", "1", "J"],
376+
})
377+
In [8]: df.mean(numeric_only=False)
378+
Out[8]:
379+
...
380+
TypeError: cannot find the mean of type 'str'
381+
349382
.. _whatsnew_140.notable_bug_fixes.notable_bug_fix3:
350383

351384
notable_bug_fix3

0 commit comments

Comments
 (0)