|
20 | 20 | is_categorical_dtype,
|
21 | 21 | _possibly_cast_to_datetime,
|
22 | 22 | _possibly_castable, _possibly_convert_platform,
|
23 |
| - _try_sort, is_internal_type, is_datetimetz, |
| 23 | + _try_sort, is_extension_type, is_datetimetz, |
24 | 24 | _maybe_match_name, ABCSparseArray,
|
25 | 25 | _coerce_to_dtype, SettingWithCopyError,
|
26 | 26 | _maybe_box_datetimelike, ABCDataFrame,
|
@@ -2063,28 +2063,33 @@ def map(self, arg, na_action=None):
|
2063 | 2063 | y : Series
|
2064 | 2064 | same index as caller
|
2065 | 2065 | """
|
2066 |
| - values = self.asobject |
2067 | 2066 |
|
2068 |
| - if na_action == 'ignore': |
2069 |
| - mask = isnull(values) |
2070 |
| - |
2071 |
| - def map_f(values, f): |
2072 |
| - return lib.map_infer_mask(values, f, mask.view(np.uint8)) |
| 2067 | + if is_extension_type(self.dtype): |
| 2068 | + values = self._values |
| 2069 | + if na_action is not None: |
| 2070 | + raise NotImplementedError |
| 2071 | + map_f = lambda values, f: values.map(f) |
2073 | 2072 | else:
|
2074 |
| - map_f = lib.map_infer |
| 2073 | + values = self.asobject |
| 2074 | + |
| 2075 | + if na_action == 'ignore': |
| 2076 | + def map_f(values, f): |
| 2077 | + return lib.map_infer_mask(values, f, |
| 2078 | + isnull(values).view(np.uint8)) |
| 2079 | + else: |
| 2080 | + map_f = lib.map_infer |
2075 | 2081 |
|
2076 | 2082 | if isinstance(arg, (dict, Series)):
|
2077 | 2083 | if isinstance(arg, dict):
|
2078 | 2084 | arg = self._constructor(arg, index=arg.keys())
|
2079 | 2085 |
|
2080 | 2086 | indexer = arg.index.get_indexer(values)
|
2081 | 2087 | new_values = algos.take_1d(arg._values, indexer)
|
2082 |
| - return self._constructor(new_values, |
2083 |
| - index=self.index).__finalize__(self) |
2084 | 2088 | else:
|
2085 |
| - mapped = map_f(values, arg) |
2086 |
| - return self._constructor(mapped, |
2087 |
| - index=self.index).__finalize__(self) |
| 2089 | + new_values = map_f(values, arg) |
| 2090 | + |
| 2091 | + return self._constructor(new_values, |
| 2092 | + index=self.index).__finalize__(self) |
2088 | 2093 |
|
2089 | 2094 | def apply(self, func, convert_dtype=True, args=(), **kwds):
|
2090 | 2095 | """
|
@@ -2193,7 +2198,12 @@ def apply(self, func, convert_dtype=True, args=(), **kwds):
|
2193 | 2198 | if isinstance(f, np.ufunc):
|
2194 | 2199 | return f(self)
|
2195 | 2200 |
|
2196 |
| - mapped = lib.map_infer(self.asobject, f, convert=convert_dtype) |
| 2201 | + if is_extension_type(self.dtype): |
| 2202 | + mapped = self._values.map(f) |
| 2203 | + else: |
| 2204 | + values = self.asobject |
| 2205 | + mapped = lib.map_infer(values, f, convert=convert_dtype) |
| 2206 | + |
2197 | 2207 | if len(mapped) and isinstance(mapped[0], Series):
|
2198 | 2208 | from pandas.core.frame import DataFrame
|
2199 | 2209 | return DataFrame(mapped.tolist(), index=self.index)
|
@@ -2779,7 +2789,7 @@ def _try_cast(arr, take_fast_path):
|
2779 | 2789 |
|
2780 | 2790 | try:
|
2781 | 2791 | subarr = _possibly_cast_to_datetime(arr, dtype)
|
2782 |
| - if not is_internal_type(subarr): |
| 2792 | + if not is_extension_type(subarr): |
2783 | 2793 | subarr = np.array(subarr, dtype=dtype, copy=copy)
|
2784 | 2794 | except (ValueError, TypeError):
|
2785 | 2795 | if is_categorical_dtype(dtype):
|
|
0 commit comments