Pandas version checks

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

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

  • [X] I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd

d = {'col1': [1, None]}
df = pd.DataFrame(data=d).astype(int, errors='ignore')
print(df.iloc[0].dtypes)
# Output: float64

# Replace NaN with a float
df.fillna(value={"col1": 9999.0}, inplace=True)
df = df.astype(int, errors='ignore')
print(df.iloc[0].dtypes)
# Output: int64

Issue Description

astype(int, errors ='ignore') should ignore NaNs and convert other values, but that is not what happens, instead, all values are left unchanged If NaNs are converted to any given float, and astype(int, errors ='ignore') applied again, it works. But that's not the expected behavior.

Expected Behavior

astype(int, errors ='ignore') should ignore NaNs and convert other values.

Installed Versions

INSTALLED VERSIONS ------------------ commit : 2e218d10984e9919f0296931d92ea851c6a6faf5 python : 3.8.13.final.0 python-bits : 64 OS : Darwin OS-release : 21.6.0 Version : Darwin Kernel Version 21.6.0: Mon Aug 22 20:17:10 PDT 2022; root:xnu-8020.140.49~2/RELEASE_X86_64 machine : x86_64 processor : i386 byteorder : little LC_ALL : None LANG : None LOCALE : en_US.UTF-8 pandas : 1.5.3 numpy : 1.23.0 pytz : 2022.7 dateutil : 2.8.2 setuptools : 56.0.0 pip : 22.0.4 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : None IPython : None pandas_datareader: None bs4 : None bottleneck : None brotli : None fastparquet : None fsspec : None gcsfs : 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 tzdata : None None

Comment From: phofl

Hi, thanks for your report.

A dtype is always column based. As soon as you have one float, all values will be float. If you want nullable values in a int column you'll have to use our nullable dtypes, e.g. Int64 in this case