Skip to content

ensure_int_or_float Surprising Behavior with Int64 / ExtensionArrays #27506

Closed
@WillAyd

Description

@WillAyd

Unearthed as part of #27424

>>> import pandas as pd
>>> from pandas.core.dtypes.common import ensure_int_or_float

>>> ensure_int_or_float(pd.Series(range(3), dtype='Int64'))
0    0
1    1
2    2
dtype: int64

# Directly against PandasArray now
>>> ensure_int_or_float(pd.Series(range(3), dtype='Int64').array)
array([0., 1., 2.])  # returns float

When the underlying array gets passed to ensure_int_or_float they don't return integer as expected. The issue here is due to the fact that the astype signature doesn't have casting as a parameter like other types going through ensure_int_or_float do

Metadata

Metadata

Assignees

No one assigned

    Labels

    ExtensionArrayExtending pandas with custom dtypes or arrays.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions