Skip to content

ENH: make DataFrame.applymap uses the .map method of ExtensionArrays #52219

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

Merged

Conversation

topper-123
Copy link
Contributor

@topper-123 topper-123 commented Mar 26, 2023

Currently DataFrame.applymap ignores the .mapmethod of ExtensionArrays. This fixes that.

Example:

>>> import pandas as pd
>>>
>>> arr = pd.array(["a", np.nan, "b"], dtype=object)
>>> sparse_arr = pd.array(arr.tolist(), dtype=pd.SparseDtype(object))
>>> df = pd.DataFrame(data={'a': arr, "b": sparse_arr})
>>> df.applymap(str.upper, na_action="ignore").dtypes  # main
a    object
b    object
dtype: object
>>> df.applymap(str.upper, na_action="ignore").dtypes  # this PR
a                 object
b    Sparse[object, nan]
dtype: object

@topper-123 topper-123 force-pushed the DataFrame.applymap_uses_map_values branch from 58ccae6 to 149fc68 Compare March 26, 2023 09:57
@topper-123 topper-123 changed the title ENH: DataFrame.map uses .map method of ExtensionArrays ENH: make DataFrame.applymap uses the .map method of ExtensionArrays Mar 26, 2023
@mroeschke mroeschke added Apply Apply, Aggregate, Transform, Map ExtensionArray Extending pandas with custom dtypes or arrays. labels Mar 27, 2023
@mroeschke mroeschke added this to the 2.1 milestone Mar 27, 2023
@mroeschke mroeschke merged commit 5269aef into pandas-dev:main Mar 27, 2023
@mroeschke
Copy link
Member

Thanks @topper-123

@topper-123 topper-123 deleted the DataFrame.applymap_uses_map_values branch March 27, 2023 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Apply Apply, Aggregate, Transform, Map ExtensionArray Extending pandas with custom dtypes or arrays.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants