Description
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
import pandas as pd
df1 = pd.DataFrame({
'id': [0, 1, 2],
'null_ints': pd.Series([pd.NA] * 3, dtype="Int64"),
})
df2 = pd.DataFrame({
'id': [0, 1, 2],
'null_ints': pd.Series([pd.NA] * 3),
})
df1['null_ints'] = df['null_ints'].astype("float64")
df2['null_ints'] = df['null_ints'].astype("float64")
Issue Description
Pandas inconsistently casts pd.NA
values to NaN
when casting from Int64
vs object
. The latter causes an TypeError
, but the former successfully converts pd.NA
values to NaN
.
Expected Behavior
Either these both fail, or they both succeed
Installed Versions
INSTALLED VERSIONS
commit : 04e01a1
python : 3.8.12.final.0
python-bits : 64
OS : Darwin
OS-release : 21.0.1
Version : Darwin Kernel Version 21.0.1: Tue Sep 14 20:56:24 PDT 2021; root:xnu-8019.30.61~4/RELEASE_ARM64_T6000
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8
pandas : 1.5.0.dev0+769.g04e01a1de0
numpy : 1.22.3
pytz : 2022.1
dateutil : 2.8.2
pip : 21.1.1
setuptools : 56.0.0
Cython : 0.29.28
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 8.3.0
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
markupsafe : None
matplotlib : None
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
xlwt : None
zstandard : None