Skip to content

BUG: .map & .apply would convert element type for extension array. #60766

Open
@colinfang

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

s = pd.Series([1, 2, None], dtype="Int32")
s.apply(lambda x: print(x))
s.map(lambda x: print(x))
# print 1.0 2.0 nan instead of 1 2 <NA>

Issue Description

s has dtype Int32Dtype which can encode nullable integers

However, when we use .apply(f) or .map(f), the element passed to f becomes float, and pd.NA becomes np.nan

Expected Behavior

f should receive unconverted value, as if we are doing f(s.iloc[0]), f(s.iloc[1]), ...

Installed Versions

tested with Pandas 2.2.3

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    ApplyApply, Aggregate, Transform, MapBugNA - MaskedArraysRelated to pd.NA and nullable extension arrays

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions