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.

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

Reproducible Example

>>> pd.DataFrame({"int":[1,2,3,4],"float":[1.0,1.0,1.0,1.0]}).iloc[0].to_dict()
{'int': 1.0, 'float': 1.0}

Issue Description

When using the to_dict() function the dtype is converted to float although it should still be int

Expected Behavior

>>> pd.DataFrame({"int":[1,2,3,4],"float":[1.0,1.0,1.0,1.0]}).iloc[0].to_dict()
{'int': 1, 'float': 1.0}

Installed Versions

INSTALLED VERSIONS ------------------ commit : 8dab54d6573f7186ff0c3b6364d5e4dd635ff3e7 python : 3.10.9.final.0 python-bits : 64 OS : Linux OS-release : 5.15.79.1-microsoft-standard-WSL2 Version : #1 SMP Wed Nov 23 01:01:46 UTC 2022 machine : x86_64 processor : byteorder : little LC_ALL : None LANG : C.UTF-8 LOCALE : en_US.UTF-8 pandas : 1.5.2 numpy : 1.23.5 pytz : 2022.6 dateutil : 2.8.2 setuptools : 65.6.3 pip : 22.3.1 Cython : None pytest : 7.2.0 hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : 4.9.1 html5lib : None pymysql : None psycopg2 : None 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 : 3.6.2 numba : None numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : None pyreadstat : None pyxlsb : None s3fs : None scipy : 1.9.3 snappy : None sqlalchemy : None tables : None tabulate : 0.9.0 xarray : None xlrd : None xlwt : None zstandard : None tzdata : None

Might be related: https://github.com/pandas-dev/pandas/issues/21256 https://github.com/pandas-dev/pandas/issues/20791

Comment From: phofl

Hi, thanks for your report. This is expected and unrelated to to_dict. The iloc call returns a Series which tries to find a common dtype, e.g. float. Hence the conversion happens