Skip to content

PERF: use fast version of 1d-only checks #45852

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@
ensure_platform_int,
infer_dtype_from_object,
is_1d_only_ea_dtype,
is_1d_only_ea_obj,
is_bool_dtype,
is_dataclass,
is_datetime64_any_dtype,
Expand Down Expand Up @@ -913,7 +912,7 @@ def _values( # type: ignore[override]
mgr = self._mgr

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

def blk_func(values, axis=1):
if isinstance(values, ExtensionArray):
if not is_1d_only_ea_obj(values) and not isinstance(
if not is_1d_only_ea_dtype(values.dtype) and not isinstance(
self._mgr, ArrayManager
):
return values._reduce(name, axis=1, skipna=skipna, **kwds)
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/groupby/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
ensure_float64,
ensure_int64,
ensure_platform_int,
is_1d_only_ea_obj,
is_1d_only_ea_dtype,
is_bool_dtype,
is_categorical_dtype,
is_complex_dtype,
Expand Down Expand Up @@ -601,7 +601,7 @@ def cython_operation(
raise NotImplementedError("number of dimensions is currently limited to 2")
elif values.ndim == 2:
assert axis == 1, axis
elif not is_1d_only_ea_obj(values):
elif not is_1d_only_ea_dtype(values.dtype):
# Note: it is *not* the case that axis is always 0 for 1-dim values,
# as we can have 1D ExtensionArrays that we need to treat as 2D
assert axis == 0
Expand Down
7 changes: 4 additions & 3 deletions pandas/core/internals/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
)
from pandas.core.dtypes.common import (
is_1d_only_ea_dtype,
is_1d_only_ea_obj,
is_datetime64tz_dtype,
is_dtype_equal,
)
Expand Down Expand Up @@ -478,7 +477,7 @@ def _concatenate_join_units(join_units: list[JoinUnit], copy: bool) -> ArrayLike
else:
concat_values = concat_values.copy()

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