REF: Add ExtensionArray.map by topper-123 · Pull Request #51809 · pandas-dev/pandas (original) (raw)

Working with the .map method is very uncomfortable in main, because of issues with ExtensionArray:

This PR solves this by:

  1. moving the functionality in IndexOpsMixin._map_values to a function map_array in algorithms.
  2. adding a .map method to ExtensionArray that calls the new map_array function. Subclasses will override this method where needed.
  3. Call the new map_array function inside IndexOpsMixin._map_values.
  4. Ensuring a common signature for the .map method for ExtensionArray, i.e. always two method parameters (mapper and na_action), so we can reliably call the .map method on any ExtensionArray subclass.

Note that this PR doesn't really add new functionality, because we're mostly just moving code around, though it is now possible to call the map method on any Extensionarray directly, instead of going through e.g. Series.map.

In the main branch, there are currently several ExtensionArray subclasses where na_action='ignore' doesn't work. I'm working on making it work with all of the ExtensionArray subclasses and there is already #51645, which handles Categorical/CategoricalIndex and more will follow.