|
99 | 99 | ensure_platform_int,
|
100 | 100 | infer_dtype_from_object,
|
101 | 101 | is_1d_only_ea_dtype,
|
102 |
| - is_1d_only_ea_obj, |
103 | 102 | is_bool_dtype,
|
104 | 103 | is_dataclass,
|
105 | 104 | is_datetime64_any_dtype,
|
|
138 | 137 | )
|
139 | 138 | from pandas.core.array_algos.take import take_2d_multi
|
140 | 139 | from pandas.core.arraylike import OpsMixin
|
141 |
| -from pandas.core.arrays import ( |
142 |
| - DatetimeArray, |
143 |
| - ExtensionArray, |
144 |
| - TimedeltaArray, |
145 |
| -) |
| 140 | +from pandas.core.arrays import ExtensionArray |
146 | 141 | from pandas.core.arrays.sparse import SparseFrameAccessor
|
147 | 142 | from pandas.core.construction import (
|
148 | 143 | extract_array,
|
@@ -855,28 +850,6 @@ def _can_fast_transpose(self) -> bool:
|
855 | 850 | # TODO(EA2D) special case would be unnecessary with 2D EAs
|
856 | 851 | return not is_1d_only_ea_dtype(dtype)
|
857 | 852 |
|
858 |
| - @property |
859 |
| - def _values_compat(self) -> np.ndarray | DatetimeArray | TimedeltaArray: |
860 |
| - """ |
861 |
| - Analogue to ._values that may return a 2D ExtensionArray. |
862 |
| - """ |
863 |
| - mgr = self._mgr |
864 |
| - if isinstance(mgr, ArrayManager): |
865 |
| - return self._values |
866 |
| - |
867 |
| - blocks = mgr.blocks |
868 |
| - if len(blocks) != 1: |
869 |
| - return self._values |
870 |
| - |
871 |
| - arr = blocks[0].values |
872 |
| - if arr.ndim == 1: |
873 |
| - # non-2D ExtensionArray |
874 |
| - return self._values |
875 |
| - |
876 |
| - # more generally, whatever we allow in NDArrayBackedExtensionBlock |
877 |
| - arr = cast("DatetimeArray | TimedeltaArray", arr) |
878 |
| - return arr.T |
879 |
| - |
880 | 853 | # ----------------------------------------------------------------------
|
881 | 854 | # Rendering Methods
|
882 | 855 |
|
@@ -3317,18 +3290,7 @@ def transpose(self, *args, copy: bool = False) -> DataFrame:
|
3317 | 3290 | # construct the args
|
3318 | 3291 |
|
3319 | 3292 | dtypes = list(self.dtypes)
|
3320 |
| - |
3321 |
| - if self._can_fast_transpose: |
3322 |
| - # Note: tests pass without this, but this improves perf quite a bit. |
3323 |
| - new_vals = self._values_compat.T |
3324 |
| - if copy: |
3325 |
| - new_vals = new_vals.copy() |
3326 |
| - |
3327 |
| - result = self._constructor(new_vals, index=self.columns, columns=self.index) |
3328 |
| - |
3329 |
| - elif ( |
3330 |
| - self._is_homogeneous_type and dtypes and is_extension_array_dtype(dtypes[0]) |
3331 |
| - ): |
| 3293 | + if self._is_homogeneous_type and dtypes and is_extension_array_dtype(dtypes[0]): |
3332 | 3294 | # We have EAs with the same dtype. We can preserve that dtype in transpose.
|
3333 | 3295 | dtype = dtypes[0]
|
3334 | 3296 | arr_type = dtype.construct_array_type()
|
@@ -9765,9 +9727,8 @@ def func(values: np.ndarray):
|
9765 | 9727 |
|
9766 | 9728 | def blk_func(values, axis=1):
|
9767 | 9729 | if isinstance(values, ExtensionArray):
|
9768 |
| - if not is_1d_only_ea_obj(values) and not isinstance( |
9769 |
| - self._mgr, ArrayManager |
9770 |
| - ): |
| 9730 | + if values.ndim == 2: |
| 9731 | + # i.e. DatetimeArray, TimedeltaArray |
9771 | 9732 | return values._reduce(name, axis=1, skipna=skipna, **kwds)
|
9772 | 9733 | return values._reduce(name, skipna=skipna, **kwds)
|
9773 | 9734 | else:
|
|
0 commit comments