|
79 | 79 |
|
80 | 80 | from pandas.core.dtypes.cast import (
|
81 | 81 | cast_scalar_to_array,
|
82 |
| - coerce_to_dtypes, |
83 | 82 | construct_1d_arraylike_from_scalar,
|
84 | 83 | find_common_type,
|
85 | 84 | infer_dtype_from_scalar,
|
@@ -8817,11 +8816,9 @@ def _reduce(
|
8817 | 8816 | labels = self._get_agg_axis(axis)
|
8818 | 8817 | assert axis in [0, 1]
|
8819 | 8818 |
|
8820 |
| - def func(values): |
8821 |
| - if is_extension_array_dtype(values.dtype): |
8822 |
| - return extract_array(values)._reduce(name, skipna=skipna, **kwds) |
8823 |
| - else: |
8824 |
| - return op(values, axis=axis, skipna=skipna, **kwds) |
| 8819 | + def func(values: np.ndarray): |
| 8820 | + # We only use this in the case that operates on self.values |
| 8821 | + return op(values, axis=axis, skipna=skipna, **kwds) |
8825 | 8822 |
|
8826 | 8823 | def blk_func(values):
|
8827 | 8824 | if isinstance(values, ExtensionArray):
|
@@ -8859,10 +8856,6 @@ def _get_data() -> DataFrame:
|
8859 | 8856 | out = df._constructor(res).iloc[0]
|
8860 | 8857 | if out_dtype is not None:
|
8861 | 8858 | out = out.astype(out_dtype)
|
8862 |
| - if axis == 0 and is_object_dtype(out.dtype): |
8863 |
| - # GH#35865 careful to cast explicitly to object |
8864 |
| - nvs = coerce_to_dtypes(out.values, df.dtypes.iloc[np.sort(indexer)]) |
8865 |
| - out[:] = np.array(nvs, dtype=object) |
8866 | 8859 | if axis == 0 and len(self) == 0 and name in ["sum", "prod"]:
|
8867 | 8860 | # Even if we are object dtype, follow numpy and return
|
8868 | 8861 | # float64, see test_apply_funcs_over_empty
|
@@ -8894,8 +8887,7 @@ def _get_data() -> DataFrame:
|
8894 | 8887 | result = result.astype(np.float64)
|
8895 | 8888 | except (ValueError, TypeError):
|
8896 | 8889 | # try to coerce to the original dtypes item by item if we can
|
8897 |
| - if axis == 0: |
8898 |
| - result = coerce_to_dtypes(result, data.dtypes) |
| 8890 | + pass |
8899 | 8891 |
|
8900 | 8892 | result = self._constructor_sliced(result, index=labels)
|
8901 | 8893 | return result
|
|
0 commit comments