|
46 | 46 | is_scalar, |
47 | 47 | pandas_dtype, |
48 | 48 | ) |
49 | | -from pandas.core.dtypes.dtypes import ( |
50 | | - ExtensionDtype, |
51 | | - NumpyEADtype, |
52 | | -) |
| 49 | +from pandas.core.dtypes.dtypes import ExtensionDtype |
53 | 50 | from pandas.core.dtypes.generic import ( |
54 | 51 | ABCDataFrame, |
55 | 52 | ABCIndex, |
@@ -2490,16 +2487,15 @@ def map(self, mapper, na_action: Literal["ignore"] | None = None): |
2490 | 2487 | a MultiIndex will be returned. |
2491 | 2488 | """ |
2492 | 2489 | result = map_array(self, mapper, na_action=na_action) |
2493 | | - if isinstance(result, ExtensionArray): |
2494 | | - if isinstance(self.dtype, NumpyEADtype): |
2495 | | - return pd_array(result, dtype=NumpyEADtype(result.dtype)) |
2496 | | - else: |
2497 | | - return result |
2498 | | - elif isinstance(result, np.ndarray): |
2499 | | - result_types = set(np.array([type(x) for x in result])) |
2500 | | - |
2501 | | - # if internal values types are compatible with self dtype |
2502 | | - if all(issubclass(t, self.dtype.type) for t in result_types): |
| 2490 | + if isinstance(result, np.ndarray): |
| 2491 | + # Get the scalar types |
| 2492 | + scalar_types = set(np.array([type(x) for x in result])) |
| 2493 | + |
| 2494 | + # if scalar values types are compatible with self dtype |
| 2495 | + # we use the self dtype |
| 2496 | + # For example if scalar types are dict and UserDict and self is a JSONArray, |
| 2497 | + # we use self.dtype |
| 2498 | + if all(issubclass(t, self.dtype.type) for t in scalar_types): |
2503 | 2499 | return pd_array(result, self.dtype) |
2504 | 2500 | else: |
2505 | 2501 | return pd_array(result, result.dtype) |
|
0 commit comments