diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index 12e553cbd7ca4..bb0e9a27b376b 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -1739,7 +1739,7 @@ def form_blocks(arrays, names: Index, axes) -> List[Block]: return blocks -def _simple_blockify(tuples, dtype): +def _simple_blockify(tuples, dtype) -> List[Block]: """ return a single array of a block that has a single dtype; if dtype is not None, coerce to this dtype @@ -1862,7 +1862,7 @@ def _merge_blocks( def _compare_or_regex_search( - a: Union[ArrayLike, Scalar], b: Union[ArrayLike, Scalar], regex: bool = False + a: ArrayLike, b: Scalar, regex: bool = False ) -> Union[ArrayLike, bool]: """ Compare two array_like inputs of the same shape or two scalar values @@ -1872,8 +1872,8 @@ def _compare_or_regex_search( Parameters ---------- - a : array_like or scalar - b : array_like or scalar + a : array_like + b : scalar regex : bool, default False Returns @@ -1882,29 +1882,21 @@ def _compare_or_regex_search( """ def _check_comparison_types( - result: Union[ArrayLike, bool], - a: Union[ArrayLike, Scalar], - b: Union[ArrayLike, Scalar], - ) -> Union[ArrayLike, bool]: + result: Union[ArrayLike, bool], a: ArrayLike, b: Scalar, + ): """ Raises an error if the two arrays (a,b) cannot be compared. Otherwise, returns the comparison result as expected. """ - if is_scalar(result) and ( - isinstance(a, np.ndarray) or isinstance(b, np.ndarray) - ): + if is_scalar(result) and isinstance(a, np.ndarray): type_names = [type(a).__name__, type(b).__name__] if isinstance(a, np.ndarray): type_names[0] = f"ndarray(dtype={a.dtype})" - if isinstance(b, np.ndarray): - type_names[1] = f"ndarray(dtype={b.dtype})" - raise TypeError( f"Cannot compare types {repr(type_names[0])} and {repr(type_names[1])}" ) - return result if not regex: op = lambda x: operator.eq(x, b) @@ -1918,18 +1910,13 @@ def _check_comparison_types( # GH#32621 use mask to avoid comparing to NAs if isinstance(a, np.ndarray) and not isinstance(b, np.ndarray): mask = np.reshape(~(isna(a)), a.shape) - elif isinstance(b, np.ndarray) and not isinstance(a, np.ndarray): - mask = np.reshape(~(isna(b)), b.shape) - elif isinstance(a, np.ndarray) and isinstance(b, np.ndarray): - mask = ~(isna(a) | isna(b)) if isinstance(a, np.ndarray): a = a[mask] - if isinstance(b, np.ndarray): - b = b[mask] if is_datetimelike_v_numeric(a, b) or is_numeric_v_string_like(a, b): # GH#29553 avoid deprecation warnings from numpy - return _check_comparison_types(False, a, b) + _check_comparison_types(False, a, b) + return False result = op(a) @@ -1940,7 +1927,8 @@ def _check_comparison_types( tmp[mask] = result result = tmp - return _check_comparison_types(result, a, b) + _check_comparison_types(result, a, b) + return result def _fast_count_smallints(arr: np.ndarray) -> np.ndarray: