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
It used to be possible to modify a columns dtype using some thing like: df.loc[:, col] = df.loc[:, col].astype(int)
Since version 2.0 it seems that the RHS is now cast to the LHS dtype when using this sort of assignment (if possible). Therefore the dtype of the Series associated with col maybe silently unchanged.
Perhaps this is by design and not a bug. Should column modification not use this syntax and instead use df[col]=?
Expected Behavior
Expected the second print statement to return int64 not float64
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
It used to be possible to modify a columns dtype using some thing like:
df.loc[:, col] = df.loc[:, col].astype(int)
Since version 2.0 it seems that the RHS is now cast to the LHS dtype when using this sort of assignment (if possible). Therefore the dtype of the Series associated with
col
maybe silently unchanged.Perhaps this is by design and not a bug. Should column modification not use this syntax and instead use
df[col]=
?Expected Behavior
Expected the second print statement to return
int64
notfloat64
Installed Versions
INSTALLED VERSIONS
commit : 478d340
python : 3.11.3.final.0
python-bits : 64
OS : Darwin
OS-release : 22.4.0
Version : Darwin Kernel Version 22.4.0: Mon Mar 6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : None
LOCALE : en_NZ.UTF-8
pandas : 2.0.0
numpy : 1.24.2
pytz : 2023.3
dateutil : 2.8.2
setuptools : 67.6.1
pip : 23.0.1
Cython : None
pytest : 7.3.0
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.12.0
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.7.1
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: