Skip to content

BUG/API: DTI/TDI/PI.map na_action="ignore" #51936

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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/source/whatsnew/v2.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,17 @@ Categorical
Datetimelike
^^^^^^^^^^^^
- Bug in :meth:`Timestamp.round` with values close to the implementation bounds returning incorrect results instead of raising ``OutOfBoundsDatetime`` (:issue:`51494`)
- :meth:`arrays.DatetimeArray.map` can now take a ``na_action`` argument. :meth:`DatetimeIndex.map` with ``na_action="ignore"`` now works as expected. (:issue:`51644`)
- Bug in :meth:`arrays.DatetimeArray.map` and :meth:`DatetimeIndex.map`, where the supplied callable operated array-wise instead of element-wise (:issue:`51977`)
-

Timedelta
^^^^^^^^^
- Bug in :meth:`Timedelta.round` with values close to the implementation bounds returning incorrect results instead of raising ``OutOfBoundsTimedelta`` (:issue:`51494`)
- Bug in :class:`TimedeltaIndex` division or multiplication leading to ``.freq`` of "0 Days" instead of ``None`` (:issue:`51575`)
- :meth:`arrays.TimedeltaArray.map` can now take a ``na_action`` argument. :meth:`TimedeltaIndex.map` with ``na_action="ignore"`` now works as expected. (:issue:`51644`)
- Bug in :meth:`arrays.TimedeltaArray.map` and :meth:`TimedeltaIndex.map`, where the supplied callable operated array-wise instead of element-wise (:issue:`51977`)
-

Timezones
^^^^^^^^^
Expand Down Expand Up @@ -196,6 +200,7 @@ I/O
Period
^^^^^^
- Bug in :class:`PeriodDtype` constructor failing to raise ``TypeError`` when no argument is passed or when ``None`` is passed (:issue:`27388`)
- :meth:`arrays.PeriodArray.map` can now take a ``na_action`` argument. :meth:`PeriodIndex.map` with ``na_action="ignore"`` now works as expected. (:issue:`51644`)
- Bug in :class:`PeriodDtype` constructor raising ``ValueError`` instead of ``TypeError`` when an invalid type is passed (:issue:`51790`)
- Bug in :meth:`arrays.PeriodArray.map` and :meth:`PeriodIndex.map`, where the supplied callable operated array-wise instead of element-wise (:issue:`51977`)
-
Expand Down
5 changes: 1 addition & 4 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,12 +747,9 @@ def _unbox(self, other) -> np.int64 | np.datetime64 | np.timedelta64 | np.ndarra

@ravel_compat
def map(self, mapper, na_action=None):
if na_action is not None:
raise NotImplementedError

from pandas import Index

result = map_array(self, mapper)
result = map_array(self, mapper, na_action=na_action)
result = Index(result)

if isinstance(result, ABCMultiIndex):
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,8 +895,8 @@ def _map_values(self, mapper, na_action=None, convert: bool = True):
return arr.map(mapper, na_action=na_action)

# Argument 1 to "map_array" has incompatible type
# "Union[IndexOpsMixin, ExtensionArray, ndarray[Any, Any]]";
# expected "Union[ExtensionArray, ndarray[Any, Any]]"
# "Union[IndexOpsMixin, ndarray[Any, Any]]";
# expected "Union[ExtensionArray, ndarray[Any, Any]]
return algorithms.map_array(
arr, mapper, na_action=na_action, convert=convert # type: ignore[arg-type]
)
Expand Down
7 changes: 0 additions & 7 deletions pandas/tests/apply/test_invalid_arg.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,6 @@ def test_map_categorical_na_action():
s.map(lambda x: x, na_action="ignore")


def test_map_datetimetz_na_action():
values = date_range("2011-01-01", "2011-01-02", freq="H").tz_localize("Asia/Tokyo")
s = Series(values, name="XX")
with pytest.raises(NotImplementedError, match=tm.EMPTY_STRING_PATTERN):
s.map(lambda x: x, na_action="ignore")


@pytest.mark.parametrize("method", ["apply", "agg", "transform"])
@pytest.mark.parametrize("func", [{"A": {"B": "sum"}}, {"A": {"B": ["sum"]}}])
def test_nested_renamer(frame_or_series, method, func):
Expand Down
8 changes: 2 additions & 6 deletions pandas/tests/extension/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,8 @@ def test_combine_add(self, data_repeated):

@pytest.mark.parametrize("na_action", [None, "ignore"])
def test_map(self, data, na_action):
if na_action is not None:
with pytest.raises(NotImplementedError, match=""):
data.map(lambda x: x, na_action=na_action)
else:
result = data.map(lambda x: x, na_action=na_action)
self.assert_extension_array_equal(result, data)
result = data.map(lambda x: x, na_action=na_action)
self.assert_extension_array_equal(result, data)


class TestInterface(BaseDatetimeTests, base.BaseInterfaceTests):
Expand Down
8 changes: 2 additions & 6 deletions pandas/tests/extension/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,8 @@ def test_diff(self, data, periods):

@pytest.mark.parametrize("na_action", [None, "ignore"])
def test_map(self, data, na_action):
if na_action is not None:
with pytest.raises(NotImplementedError, match=""):
data.map(lambda x: x, na_action=na_action)
else:
result = data.map(lambda x: x, na_action=na_action)
self.assert_extension_array_equal(result, data)
result = data.map(lambda x: x, na_action=na_action)
self.assert_extension_array_equal(result, data)


class TestInterface(BasePeriodTests, base.BaseInterfaceTests):
Expand Down