diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py index cba055d5b4345..88a92ea1455d0 100644 --- a/pandas/core/dtypes/cast.py +++ b/pandas/core/dtypes/cast.py @@ -246,6 +246,16 @@ def _disallow_mismatched_datetimelike(value, dtype: DtypeObj): raise TypeError(f"Cannot cast {repr(value)} to {dtype}") +@overload +def maybe_downcast_to_dtype(result: np.ndarray, dtype: str | np.dtype) -> np.ndarray: + ... + + +@overload +def maybe_downcast_to_dtype(result: ExtensionArray, dtype: str | np.dtype) -> ArrayLike: + ... + + def maybe_downcast_to_dtype(result: ArrayLike, dtype: str | np.dtype) -> ArrayLike: """ try to cast to the specified dtype (e.g. convert back to bool/int @@ -301,6 +311,20 @@ def maybe_downcast_to_dtype(result: ArrayLike, dtype: str | np.dtype) -> ArrayLi return result +@overload +def maybe_downcast_numeric( + result: np.ndarray, dtype: np.dtype, do_round: bool = False +) -> np.ndarray: + ... + + +@overload +def maybe_downcast_numeric( + result: ExtensionArray, dtype: DtypeObj, do_round: bool = False +) -> ArrayLike: + ... + + def maybe_downcast_numeric( result: ArrayLike, dtype: DtypeObj, do_round: bool = False ) -> ArrayLike: diff --git a/pandas/core/groupby/ops.py b/pandas/core/groupby/ops.py index a769c92e0b542..599f384a89a68 100644 --- a/pandas/core/groupby/ops.py +++ b/pandas/core/groupby/ops.py @@ -637,9 +637,7 @@ def _call_cython_op( else: op_result = result - # error: Incompatible return value type (got "Union[ExtensionArray, ndarray]", - # expected "ndarray") - return op_result # type: ignore[return-value] + return op_result @final def cython_operation( diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py index f6a20a418c32b..c3acfc5ff2f66 100644 --- a/pandas/core/indexes/interval.py +++ b/pandas/core/indexes/interval.py @@ -1141,11 +1141,7 @@ def interval_range( if all(is_integer(x) for x in com.not_none(start, end, freq)): # np.linspace always produces float output - # error: Incompatible types in assignment (expression has type - # "Union[ExtensionArray, ndarray]", variable has type "ndarray") - breaks = maybe_downcast_numeric( # type: ignore[assignment] - breaks, np.dtype("int64") - ) + breaks = maybe_downcast_numeric(breaks, np.dtype("int64")) else: # delegate to the appropriate range function if isinstance(endpoint, Timestamp):