Skip to content

Commit e3011b0

Browse files
committed
REF: trimmed-diff version of pandas-dev#40149
1 parent 40ca9d1 commit e3011b0

File tree

3 files changed

+7
-64
lines changed

3 files changed

+7
-64
lines changed

pandas/core/array_algos/take.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
from pandas._typing import ArrayLike
1717

1818
from pandas.core.dtypes.cast import maybe_promote
19-
from pandas.core.dtypes.common import (
20-
ensure_platform_int,
21-
is_1d_only_ea_obj,
22-
)
19+
from pandas.core.dtypes.common import ensure_platform_int
2320
from pandas.core.dtypes.missing import na_value_for_dtype
2421

2522
from pandas.core.construction import ensure_wrapped_if_datetimelike
@@ -94,14 +91,12 @@ def take_nd(
9491

9592
if not isinstance(arr, np.ndarray):
9693
# i.e. ExtensionArray,
97-
# includes for EA to catch DatetimeArray, TimedeltaArray
98-
if not is_1d_only_ea_obj(arr):
99-
# i.e. DatetimeArray, TimedeltaArray
94+
if arr.ndim == 2:
95+
# e.g. DatetimeArray, TimedeltArray
10096
arr = cast("NDArrayBackedExtensionArray", arr)
10197
return arr.take(
10298
indexer, fill_value=fill_value, allow_fill=allow_fill, axis=axis
10399
)
104-
105100
return arr.take(indexer, fill_value=fill_value, allow_fill=allow_fill)
106101

107102
arr = np.asarray(arr)

pandas/core/frame.py

+4-43
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@
9999
ensure_platform_int,
100100
infer_dtype_from_object,
101101
is_1d_only_ea_dtype,
102-
is_1d_only_ea_obj,
103102
is_bool_dtype,
104103
is_dataclass,
105104
is_datetime64_any_dtype,
@@ -138,11 +137,7 @@
138137
)
139138
from pandas.core.array_algos.take import take_2d_multi
140139
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
146141
from pandas.core.arrays.sparse import SparseFrameAccessor
147142
from pandas.core.construction import (
148143
extract_array,
@@ -855,28 +850,6 @@ def _can_fast_transpose(self) -> bool:
855850
# TODO(EA2D) special case would be unnecessary with 2D EAs
856851
return not is_1d_only_ea_dtype(dtype)
857852

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-
880853
# ----------------------------------------------------------------------
881854
# Rendering Methods
882855

@@ -3317,18 +3290,7 @@ def transpose(self, *args, copy: bool = False) -> DataFrame:
33173290
# construct the args
33183291

33193292
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]):
33323294
# We have EAs with the same dtype. We can preserve that dtype in transpose.
33333295
dtype = dtypes[0]
33343296
arr_type = dtype.construct_array_type()
@@ -9765,9 +9727,8 @@ def func(values: np.ndarray):
97659727

97669728
def blk_func(values, axis=1):
97679729
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
97719732
return values._reduce(name, axis=1, skipna=skipna, **kwds)
97729733
return values._reduce(name, skipna=skipna, **kwds)
97739734
else:

pandas/tests/frame/methods/test_transpose.py

-13
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,3 @@ def test_transpose_get_view(self, float_frame):
9090
dft.values[:, 5:10] = 5
9191

9292
assert (float_frame.values[5:10] == 5).all()
93-
94-
@td.skip_array_manager_invalid_test
95-
def test_transpose_get_view_dt64tzget_view(self):
96-
dti = date_range("2016-01-01", periods=6, tz="US/Pacific")
97-
arr = dti._data.reshape(3, 2)
98-
df = DataFrame(arr)
99-
assert df._mgr.nblocks == 1
100-
101-
result = df.T
102-
assert result._mgr.nblocks == 1
103-
104-
rtrip = result._mgr.blocks[0].values
105-
assert np.shares_memory(arr._data, rtrip._data)

0 commit comments

Comments
 (0)