@@ -2510,7 +2510,9 @@ def __array_ufunc__(self, ufunc: np.ufunc, method: str, *inputs, **kwargs):
25102510
25112511 return arraylike .default_array_ufunc (self , ufunc , method , * inputs , ** kwargs )
25122512
2513- def map (self , mapper , na_action : Literal ["ignore" ] | None = None ):
2513+ def map (self , mapper ,
2514+ na_action : Literal ["ignore" ] | None = None ,
2515+ preserve_dtype : bool = False ):
25142516 """
25152517 Map values using an input mapping or function.
25162518
@@ -2522,6 +2524,12 @@ def map(self, mapper, na_action: Literal["ignore"] | None = None):
25222524 If 'ignore', propagate NA values, without passing them to the
25232525 mapping correspondence. If 'ignore' is not supported, a
25242526 ``NotImplementedError`` should be raised.
2527+ preserve_dtype : bool, default False
2528+ If True, attempt to cast the elementwise result back to the
2529+ original ExtensionArray type (and dtype) when possible. This is
2530+ primarily intended for identity or dtype-preserving mappings.
2531+ If False, the result of the mapping is returned as produced by
2532+ the underlying implementation (typically a NumPy ndarray).
25252533
25262534 Returns
25272535 -------
@@ -2531,7 +2539,9 @@ def map(self, mapper, na_action: Literal["ignore"] | None = None):
25312539 a MultiIndex will be returned.
25322540 """
25332541 results = map_array (self , mapper , na_action = na_action )
2534- return self ._cast_pointwise_result (results )
2542+ if preserve_dtype :
2543+ results = self ._cast_pointwise_result (results )
2544+ return results
25352545
25362546 # ------------------------------------------------------------------------
25372547 # GroupBy Methods
0 commit comments