Skip to content

BUG: ExtensionIndex.map doesn't handle na_action correctly #32815

Closed
@dsaxton

Description

@dsaxton

(From master)

import pandas as pd

idx = pd.to_datetime(["2020-01-01", None])
idx.map(lambda x: pd.Timestamp("1999-01-01"), na_action="ignore")
# DatetimeIndex(['1999-01-01', '1999-01-01'], dtype='datetime64[ns]', freq=None)

idx = pd.CategoricalIndex(["a", None], categories=["a"])
idx.map(lambda x: x, na_action="ignore")
# TypeError: map() got an unexpected keyword argument 'na_action'

In the DatetimeIndex case idx.map should propagate the null value instead of returning Timestamp("1999-01-01") since na_action == "ignore", and although it isn't documented I think CategoricalIndex.map should allow na_action since the other map methods do.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugExtensionArrayExtending pandas with custom dtypes or arrays.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions