8000 BUG: groupby sum, mean, var should always be floats by rhshadrach · Pull Request #41139 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

BUG: groupby sum, mean, var should always be floats #41139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 21, 2021
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
whatsnew
  • Loading branch information
rhshadrach committed May 8, 2021
commit b6de44a4ee3b4d4f2c87ab4df3c89fdac76d4e86
25 changes: 25 additions & 0 deletions doc/source/whatsnew/v1.3.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,31 @@ values as measured by ``np.allclose``. Now no such casting occurs.

df.groupby('key').agg(lambda x: x.sum())

``float`` result for :meth:`.GroupBy.mean`, :meth:`.GroupBy.median`, and :meth:`.GroupBy.var`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Previously, these methods could result in different dtypes depending on the input values.
Now, these methods will always return a float dtype. (:issue:`41137`)

.. ipython:: python

df = pd.DataFrame({'a': [True], 'b': [1], 'c': [1.0]})

*pandas 1.2.x*

.. code-block:: ipython

In [5]: df.groupby(df.index).mean()
Out[5]:
a b c
0 True 1 1.0

*pandas 1.3.0*

.. ipython:: python

df.groupby(df.index).mean()

Try operating inplace when setting values with ``loc`` and ``iloc``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
0