Open
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
rhshadrach commentedon Jan 22, 2025
Thanks for the report! This is due to #55058, but I don't see much discussion there nor issues that change closes. It does seem surprising to me that one gets
np.nan
here. If we remove the method onBaseMaskedArray
entirely, I see expected behavior (at least in this case). That includes the use ofapply
(which usesmap
internally).cc @WillAyd @mroeschke @phofl
WillAyd commentedon Jan 22, 2025
Agreed this looks strange - the function should be receiving the arguments as integers / pd.NA
KevsterAmp commentedon Mar 13, 2025
take
KevsterAmp commentedon Mar 26, 2025
@rhshadrach - What method are you referring on BaseMaskedArray to be removed? Thanks
rhshadrach commentedon Mar 26, 2025
map
Fix pandas-dev#60766: .map & .apply would convert element type for ex…
Fix pandas-dev#60766:.map,.apply would convert element type for exten…
Fix pandas-dev#60766:.map,.apply would convert element type for exten…
pedromfdiogo commentedon Apr 23, 2025
@KevsterAmp what do you think about my commit? Can i do the PR?