Skip to content

BUG: infer_dtype result for float with embedded pd.NA #61621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
2 of 3 tasks
MarkusZimmerDLR opened this issue Jun 10, 2025 · 4 comments · May be fixed by #61624
Open
2 of 3 tasks

BUG: infer_dtype result for float with embedded pd.NA #61621

MarkusZimmerDLR opened this issue Jun 10, 2025 · 4 comments · May be fixed by #61624
Assignees
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions

Comments

@MarkusZimmerDLR
Copy link

MarkusZimmerDLR commented Jun 10, 2025

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

from pandas.api.types import infer_dtype
assert infer_dtype(pd.Series([1.,2.,.3,pd.NA], dtype=object)) ==  infer_dtype(pd.Series([1.,2.,.3,np.nan], dtype=object))

Issue Description

Dear pandas-folks,

This was checked for pandas V 2.3.0 and 2.2.X

When using pandas' infer_dtype on an object array consisting out of floats with embedded pd.NA, the result will be mixed-integer-float tough skipna is True as a default.

The same test for embedded np.nan returns floating.

    >>> from pandas.api.types import infer_dtype
    >>> infer_dtype(pd.Series([1,2,3,pd.NA], dtype=object))
    'integer'
    >>> infer_dtype(pd.Series([1,2,3,np.nan], dtype=object))
    'integer'
    >>> infer_dtype(pd.Series([1.,2.,.3,pd.NA], dtype=object))
    'mixed-integer-float' v <<< should be `floating`
    >>> infer_dtype(pd.Series([1.,2.,.3,np.nan], dtype=object))
    'floating'
    >>> infer_dtype(pd.Series(['1.0', np.nan],dtype=object))
    'string'
    >>> infer_dtype(pd.Series(['1.0', pd.NA],dtype=object))
    'string'

In case of other types, like integer or strings, the function does not produce a false / different output w.r.t. the na-type.

Context, I am maintaining a small project which assures integers in columns to stay integers - a common known issue. I you know of a well established extension for this purpose, feel free to point me towards it.

Expected Behavior

>>> infer_dtype(pd.Series([1.,2.,.3,pd.NA], dtype=object)) should return floating

Installed Versions

INSTALLED VERSIONS

commit : 2cc3762
python : 3.13.3
python-bits : 64
OS : Linux
OS-release : 4.18.0-553.51.1.el8_10.x86_64
Version : #1 SMP Fri Apr 25 00:55:37 EDT 2025
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.3.0
numpy : 2.2.6
pytz : 2025.2
dateutil : 2.9.0.post0
pip : 25.1.1
Cython : None
sphinx : None
IPython : 9.2.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : 20.0.0
pyreadstat : None
pytest : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : 0.9.0
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2025.2
qtpy : None
pyqt5 : None

@MarkusZimmerDLR MarkusZimmerDLR added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 10, 2025
@arthurlw
Copy link
Member

Confirmed on main! Investigations and PRs are welcome.

Thanks for raising this!

@arthurlw arthurlw added Dtype Conversions Unexpected or buggy dtype conversions and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 10, 2025
@heoh
Copy link

heoh commented Jun 10, 2025

I want to contribute to this. Thank you for explaining the issue.

@heoh
Copy link

heoh commented Jun 10, 2025

take

@MarkusZimmerDLR
Copy link
Author

Since this seems to be a very simple and minor fix, is it possible to not wait for the 3.0 release? Or is the release imminent?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants