BUG: DataFrame.stack() sometimes changes dtype from float32 to float64 #51059
Labels
Bug
Dtype Conversions
Unexpected or buggy dtype conversions
Reshaping
Concat, Merge/Join, Stack/Unstack, Explode
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
In some cases,
DataFrame.stack
will "change" the dtype of the resulting columns, in my case fromfloat32
tofloat64
.Expected Behavior
I would expect
DataFrame.stack()
to return afloat32
DataFrame if the input DataFrame was alsofloat32
.Installed Versions
INSTALLED VERSIONS
commit : 2e218d1
python : 3.8.9.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-104-generic
Version : #118-Ubuntu SMP Wed Mar 2 19:02:41 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.5.3
numpy : 1.23.3
pytz : 2022.1
dateutil : 2.8.2
setuptools : 67.0.0
pip : 22.3.1
Cython : None
pytest : 7.2.0
hypothesis : None
sphinx : 5.3.0
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.9.3
jinja2 : 3.1.2
IPython : 8.7.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : 2.8.1
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 10.0.1
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.8.1
snappy : None
sqlalchemy : None
tables : 3.7.0
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None
The text was updated successfully, but these errors were encountered: