Skip to content

Commit 1b45448

Browse files
authored
PERF: use fast version of 1d-only checks (#45852)
1 parent ab6901c commit 1b45448

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

pandas/core/frame.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@
107107
ensure_platform_int,
108108
infer_dtype_from_object,
109109
is_1d_only_ea_dtype,
110-
is_1d_only_ea_obj,
111110
is_bool_dtype,
112111
is_dataclass,
113112
is_datetime64_any_dtype,
@@ -913,7 +912,7 @@ def _values( # type: ignore[override]
913912
mgr = self._mgr
914913

915914
if isinstance(mgr, ArrayManager):
916-
if len(mgr.arrays) == 1 and not is_1d_only_ea_obj(mgr.arrays[0]):
915+
if len(mgr.arrays) == 1 and not is_1d_only_ea_dtype(mgr.arrays[0].dtype):
917916
# error: Item "ExtensionArray" of "Union[ndarray, ExtensionArray]"
918917
# has no attribute "reshape"
919918
return mgr.arrays[0].reshape(-1, 1) # type: ignore[union-attr]
@@ -10050,7 +10049,7 @@ def func(values: np.ndarray):
1005010049

1005110050
def blk_func(values, axis=1):
1005210051
if isinstance(values, ExtensionArray):
10053-
if not is_1d_only_ea_obj(values) and not isinstance(
10052+
if not is_1d_only_ea_dtype(values.dtype) and not isinstance(
1005410053
self._mgr, ArrayManager
1005510054
):
1005610055
return values._reduce(name, axis=1, skipna=skipna, **kwds)

pandas/core/groupby/ops.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
ensure_float64,
4646
ensure_int64,
4747
ensure_platform_int,
48-
is_1d_only_ea_obj,
48+
is_1d_only_ea_dtype,
4949
is_bool_dtype,
5050
is_categorical_dtype,
5151
is_complex_dtype,
@@ -601,7 +601,7 @@ def cython_operation(
601601
raise NotImplementedError("number of dimensions is currently limited to 2")
602602
elif values.ndim == 2:
603603
assert axis == 1, axis
604-
elif not is_1d_only_ea_obj(values):
604+
elif not is_1d_only_ea_dtype(values.dtype):
605605
# Note: it is *not* the case that axis is always 0 for 1-dim values,
606606
# as we can have 1D ExtensionArrays that we need to treat as 2D
607607
assert axis == 0

pandas/core/internals/concat.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
)
2828
from pandas.core.dtypes.common import (
2929
is_1d_only_ea_dtype,
30-
is_1d_only_ea_obj,
3130
is_datetime64tz_dtype,
3231
is_dtype_equal,
3332
)
@@ -478,7 +477,7 @@ def _concatenate_join_units(join_units: list[JoinUnit], copy: bool) -> ArrayLike
478477
else:
479478
concat_values = concat_values.copy()
480479

481-
elif any(is_1d_only_ea_obj(t) for t in to_concat):
480+
elif any(is_1d_only_ea_dtype(t.dtype) for t in to_concat):
482481
# TODO(EA2D): special case not needed if all EAs used HybridBlocks
483482
# NB: we are still assuming here that Hybrid blocks have shape (1, N)
484483
# concatting with at least one EA means we are concatting a single column
@@ -487,7 +486,9 @@ def _concatenate_join_units(join_units: list[JoinUnit], copy: bool) -> ArrayLike
487486
# error: No overload variant of "__getitem__" of "ExtensionArray" matches
488487
# argument type "Tuple[int, slice]"
489488
to_concat = [
490-
t if is_1d_only_ea_obj(t) else t[0, :] # type: ignore[call-overload]
489+
t
490+
if is_1d_only_ea_dtype(t.dtype)
491+
else t[0, :] # type: ignore[call-overload]
491492
for t in to_concat
492493
]
493494
concat_values = concat_compat(to_concat, axis=0, ea_compat_axis=True)

0 commit comments

Comments
 (0)