Skip to content

BUG: groupby.std() casts to float64 #43330

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

Closed
3 tasks done
debnathshoham opened this issue Aug 31, 2021 · 4 comments · Fixed by #50375
Closed
3 tasks done

BUG: groupby.std() casts to float64 #43330

debnathshoham opened this issue Aug 31, 2021 · 4 comments · Fixed by #50375
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Groupby Reduction Operations sum, mean, min, max, etc.

Comments

@debnathshoham
Copy link
Member

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


This came out of #43213 (comment)

Code Sample, a copy-pastable example

In [1]: import pandas as pd

In [2]: pd.__version__
Out[2]: '1.4.0.dev0+532.g9bf09adcda'

In [3]: df=pd.DataFrame([[1,2]]*3, columns=["a","b"], dtype="Int64")

In [4]: df.groupby("a").std().dtypes
Out[4]: 
b    float64
dtype: object

In [5]: df=pd.DataFrame([[1,2]]*3, columns=["a","b"], dtype="Float64")

In [6]: df.groupby("a").std().dtypes
Out[6]: 
b    float64
dtype: object

Problem description

With Float64 as input, should return Float64 and not float64

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 9bf09ad
python : 3.8.10.final.0
python-bits : 64
OS : Darwin
OS-release : 20.6.0
Version : Darwin Kernel Version 20.6.0: Wed Jun 23 00:26:31 PDT 2021; root:xnu-7195.141.2~5/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8

pandas : 1.4.0.dev0+532.g9bf09adcda
numpy : 1.21.0
pytz : 2021.1
dateutil : 2.8.1
pip : 21.1.3
setuptools : 49.6.0.post20210108
Cython : 0.29.23
pytest : 6.2.4
hypothesis : 6.14.1
sphinx : 3.5.4
blosc : None
feather : None
xlsxwriter : 1.4.4
lxml.etree : 4.6.3
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 3.0.1
IPython : 7.25.0
pandas_datareader: None
bs4 : 4.9.3
bottleneck : 1.3.2
fsspec : 2021.05.0
fastparquet : 0.6.3
gcsfs : 2021.05.0
matplotlib : 3.4.2
numexpr : 2.7.3
odfpy : None
openpyxl : 3.0.7
pandas_gbq : None
pyarrow : 4.0.1
pyxlsb : 1.0.8
s3fs : 0.4.2
scipy : 1.7.0
sqlalchemy : 1.4.20
tables : 3.6.1
tabulate : 0.8.9
xarray : 0.18.2
xlrd : 2.0.1
xlwt : 1.3.0
numba : 0.53.1

@debnathshoham debnathshoham added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 31, 2021
@phofl
Copy link
Member

phofl commented Aug 31, 2021

See #37494

@phofl phofl added Duplicate Report Duplicate issue or pull request Groupby and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 31, 2021
@debnathshoham
Copy link
Member Author

I don't think this behaviour is specific to nullable dtypes. I think it is always cast to float64

In [17]: df=pd.DataFrame([[1,2]]*3, columns=["a","b"], dtype="float32")

In [18]: df.groupby("a").std().dtypes
Out[18]: 
b    float64
dtype: object

@phofl
Copy link
Member

phofl commented Sep 1, 2021

Does this happen also with other functions except var? I think this is on purpose for std and var

@debnathshoham
Copy link
Member Author

var is working as expected..

In [4]: df=pd.DataFrame([[1,2]]*3, columns=["a","b"], dtype="Int64")

In [5]: df.groupby("a").var().dtypes
Out[5]: 
b    Float64
dtype: object

In [6]: df=pd.DataFrame([[1,2]]*3, columns=["a","b"], dtype="float32")

In [7]: df.groupby("a").var().dtypes
Out[7]: 
b    float32
dtype: object

@phofl phofl removed the Duplicate Report Duplicate issue or pull request label Sep 2, 2021
@debnathshoham debnathshoham added the Dtype Conversions Unexpected or buggy dtype conversions label Sep 26, 2021
@mroeschke mroeschke added the Reduction Operations sum, mean, min, max, etc. label Sep 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Groupby Reduction Operations sum, mean, min, max, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants