You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Mueller2-Patrick
changed the title
BUG: Groupby: Int-Datatype always casted to int64
BUG: Groupby: Int-Datatype (of group-by-columns) always casted to int64
Jun 8, 2020
Thanks for reporting this - it seems to me this is expected, datatypes may need to change to hold the correct result. For example, taking the mean of a Boolean/integer should result in float. Taking the count of a column with say 10k rows with dtype int8, changing the datatype to int64 so that the correct result can be stored seems preferable.
Even when using as_index=False, internally the unique values for the groupby are stored as an Index. I think that makes this a duplicate of #16404. Perhaps a conversion could be done after the operation is computed in this case. But then, with 16404 open, we would have two different results when using as_index=True/False.
Code Sample, a copy-pastable example
Problem description
Before the groupby: The dtype of col1 is np.int8:
Output of
After the groupby the dtype of col1 is np.int64
Output of
Expected Output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.7.1.final.0
python-bits : 64
OS : Windows
OS-release : 10
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 9, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None
pandas : 1.0.4
numpy : 1.17.4
pytz : 2019.3
dateutil : 2.8.1
pip : 10.0.1
setuptools : 45.2.0
Cython : None
pytest : 5.4.1
hypothesis : None
sphinx : 2.3.0
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10.3
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 3.0.3
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 0.12.0
pytables : None
pytest : 5.4.1
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : 1.3.12
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None
The text was updated successfully, but these errors were encountered: