|
10 | 10 |
|
11 | 11 | import numpy as np
|
12 | 12 |
|
13 |
| -from pandas._libs import index as libindex |
| 13 | +from pandas._libs import ( |
| 14 | + index as libindex, |
| 15 | + lib, |
| 16 | +) |
14 | 17 | from pandas.util._decorators import (
|
15 | 18 | cache_readonly,
|
16 | 19 | doc,
|
@@ -453,7 +456,10 @@ def _is_comparable_dtype(self, dtype: DtypeObj) -> bool:
|
453 | 456 | return self.categories._is_comparable_dtype(dtype)
|
454 | 457 |
|
455 | 458 | def map(
|
456 |
| - self, mapper, skipna: bool = False, na_action: Literal["ignore"] | None = None |
| 459 | + self, |
| 460 | + mapper, |
| 461 | + skipna: bool = False, |
| 462 | + na_action: Literal["ignore"] | None | lib.NoDefault = lib.no_default, |
457 | 463 | ):
|
458 | 464 | """
|
459 | 465 | Map values using input an input mapping or function.
|
@@ -530,14 +536,20 @@ def map(
|
530 | 536 | >>> idx.map({"a": "first", "b": "second"})
|
531 | 537 | Index(['first', 'second', nan], dtype='object')
|
532 | 538 | """
|
533 |
| - if na_action == "ignore": |
| 539 | + if na_action != lib.no_default: |
534 | 540 | warnings.warn(
|
535 | 541 | "The ``na_action`` parameter has been deprecated and it will be "
|
536 | 542 | "removed in a future version of pandas. Use ``skipna`` instead.",
|
537 | 543 | FutureWarning,
|
538 | 544 | stacklevel=find_stack_level(),
|
539 | 545 | )
|
540 |
| - skipna = True |
| 546 | + if na_action == "ignore": |
| 547 | + skipna = True |
| 548 | + elif na_action not in (None, "ignore"): |
| 549 | + raise ValueError( |
| 550 | + "na_action must either be 'ignore' or None, " |
| 551 | + f"{na_action!r} was passed" |
| 552 | + ) |
541 | 553 |
|
542 | 554 | mapped = self._values.map(mapper, skipna=skipna)
|
543 | 555 | return Index(mapped, name=self.name)
|
|
0 commit comments