diff --git a/pandas/_typing.py b/pandas/_typing.py index af037ff0473e3..5c22baa4bd42e 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -65,9 +65,19 @@ from pandas.io.formats.format import EngFormatter + ScalarLike_co = Union[ + int, + float, + complex, + str, + bytes, + np.generic, + ] + # numpy compatible types - NumpyValueArrayLike = Union[npt._ScalarLike_co, npt.ArrayLike] - NumpySorter = Optional[npt._ArrayLikeInt_co] + NumpyValueArrayLike = Union[ScalarLike_co, npt.ArrayLike] + # Name "npt._ArrayLikeInt_co" is not defined [name-defined] + NumpySorter = Optional[npt._ArrayLikeInt_co] # type: ignore[name-defined] else: npt: Any = None diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index 77dfc82e640f2..3e1508a1ec071 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -542,7 +542,9 @@ def size(self) -> int: """ The number of elements in the array. """ - return np.prod(self.shape) + # error: Incompatible return value type (got "signedinteger[_64Bit]", + # expected "int") [return-value] + return np.prod(self.shape) # type: ignore[return-value] @property def ndim(self) -> int: diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py index 40a56e27c63f5..f28aefd63546b 100644 --- a/pandas/core/arrays/sparse/array.py +++ b/pandas/core/arrays/sparse/array.py @@ -1426,8 +1426,7 @@ def __setstate__(self, state) -> None: if isinstance(state, tuple): # Compat for pandas < 0.24.0 nd_state, (fill_value, sp_index) = state - # error: Need type annotation for "sparse_values" - sparse_values = np.array([]) # type: ignore[var-annotated] + sparse_values = np.array([]) sparse_values.__setstate__(nd_state) self._sparse_values = sparse_values diff --git a/pandas/core/base.py b/pandas/core/base.py index 4e2f6a77930a1..927a3ed6a601c 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -84,6 +84,7 @@ DropKeep, NumpySorter, NumpyValueArrayLike, + ScalarLike_co, ) from pandas import ( @@ -1275,7 +1276,7 @@ def factorize( # return types [misc] def searchsorted( # type: ignore[misc] self, - value: npt._ScalarLike_co, + value: ScalarLike_co, side: Literal["left", "right"] = ..., sorter: NumpySorter = ..., ) -> np.intp: diff --git a/pandas/core/dtypes/missing.py b/pandas/core/dtypes/missing.py index cfad439e51ac7..375d05bdf11ff 100644 --- a/pandas/core/dtypes/missing.py +++ b/pandas/core/dtypes/missing.py @@ -775,10 +775,5 @@ def isna_all(arr: ArrayLike) -> bool: ) return all( - # error: Argument 1 to "__call__" of "ufunc" has incompatible type - # "Union[ExtensionArray, Any]"; expected "Union[Union[int, float, complex, str, - # bytes, generic], Sequence[Union[int, float, complex, str, bytes, generic]], - # Sequence[Sequence[Any]], _SupportsArray]" - checker(arr[i : i + chunk_len]).all() # type: ignore[arg-type] - for i in range(0, total_len, chunk_len) + checker(arr[i : i + chunk_len]).all() for i in range(0, total_len, chunk_len) ) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index f192d89bac545..8fe1a4bd515ea 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -714,7 +714,9 @@ def size(self) -> int: >>> df.size 4 """ - return np.prod(self.shape) + # error: Incompatible return value type (got "signedinteger[_64Bit]", + # expected "int") [return-value] + return np.prod(self.shape) # type: ignore[return-value] @overload def set_axis( diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index aebc3c695ba1f..9c71152a44353 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -687,7 +687,12 @@ def value_counts( # multi-index components codes = self.grouper.reconstructed_codes - codes = [rep(level_codes) for level_codes in codes] + [llab(lab, inc)] + # error: Incompatible types in assignment (expression has type + # "List[ndarray[Any, dtype[_SCT]]]", + # variable has type "List[ndarray[Any, dtype[signedinteger[Any]]]]") + codes = [ # type: ignore[assignment] + rep(level_codes) for level_codes in codes + ] + [llab(lab, inc)] # error: List item 0 has incompatible type "Union[ndarray[Any, Any], Index]"; # expected "Index" levels = [ping.group_index for ping in self.grouper.groupings] + [ diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py index c8cb2cfa28640..3eb3226328a61 100644 --- a/pandas/core/indexes/interval.py +++ b/pandas/core/indexes/interval.py @@ -1110,7 +1110,13 @@ def interval_range( if all(is_integer(x) for x in com.not_none(start, end, freq)): # np.linspace always produces float output - breaks = maybe_downcast_numeric(breaks, np.dtype("int64")) + # error: Argument 1 to "maybe_downcast_numeric" has incompatible type + # "Union[ndarray[Any, Any], TimedeltaIndex, DatetimeIndex]"; + # expected "ndarray[Any, Any]" [ + breaks = maybe_downcast_numeric( + breaks, # type: ignore[arg-type] + np.dtype("int64"), + ) else: # delegate to the appropriate range function if isinstance(endpoint, Timestamp): diff --git a/pandas/core/resample.py b/pandas/core/resample.py index d752cb0b5b23f..0cf1aafed0f56 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -1902,7 +1902,9 @@ def _get_period_bins(self, ax: PeriodIndex): # NaT handling as in pandas._lib.lib.generate_bins_dt64() nat_count = 0 if memb.hasnans: - nat_count = np.sum(memb._isnan) + # error: Incompatible types in assignment (expression has type + # "bool_", variable has type "int") [assignment] + nat_count = np.sum(memb._isnan) # type: ignore[assignment] memb = memb[~memb._isnan] if not len(memb): diff --git a/pandas/core/reshape/merge.py b/pandas/core/reshape/merge.py index a84f8af7d4c38..639c518b5412f 100644 --- a/pandas/core/reshape/merge.py +++ b/pandas/core/reshape/merge.py @@ -1301,13 +1301,7 @@ def _maybe_coerce_merge_keys(self) -> None: # "Union[dtype[Any], Type[Any], _SupportsDType[dtype[Any]]]" casted = lk.astype(rk.dtype) # type: ignore[arg-type] - # Argument 1 to "__call__" of "_UFunc_Nin1_Nout1" has - # incompatible type "Union[ExtensionArray, ndarray[Any, Any], - # Index, Series]"; expected "Union[_SupportsArray[dtype[Any]], - # _NestedSequence[_SupportsArray[dtype[Any]]], bool, int, - # float, complex, str, bytes, _NestedSequence[Union[bool, - # int, float, complex, str, bytes]]]" - mask = ~np.isnan(lk) # type: ignore[arg-type] + mask = ~np.isnan(lk) match = lk == casted # error: Item "ExtensionArray" of "Union[ExtensionArray, # ndarray[Any, Any], Any]" has no attribute "all" @@ -1329,13 +1323,7 @@ def _maybe_coerce_merge_keys(self) -> None: # "Union[dtype[Any], Type[Any], _SupportsDType[dtype[Any]]]" casted = rk.astype(lk.dtype) # type: ignore[arg-type] - # Argument 1 to "__call__" of "_UFunc_Nin1_Nout1" has - # incompatible type "Union[ExtensionArray, ndarray[Any, Any], - # Index, Series]"; expected "Union[_SupportsArray[dtype[Any]], - # _NestedSequence[_SupportsArray[dtype[Any]]], bool, int, - # float, complex, str, bytes, _NestedSequence[Union[bool, - # int, float, complex, str, bytes]]]" - mask = ~np.isnan(rk) # type: ignore[arg-type] + mask = ~np.isnan(rk) match = rk == casted # error: Item "ExtensionArray" of "Union[ExtensionArray, # ndarray[Any, Any], Any]" has no attribute "all" diff --git a/pandas/core/reshape/util.py b/pandas/core/reshape/util.py index 459928acc0da3..1154940f2c4a6 100644 --- a/pandas/core/reshape/util.py +++ b/pandas/core/reshape/util.py @@ -55,7 +55,15 @@ def cartesian_product(X) -> list[np.ndarray]: # if any factor is empty, the cartesian product is empty b = np.zeros_like(cumprodX) - return [tile_compat(np.repeat(x, b[i]), np.product(a[i])) for i, x in enumerate(X)] + # error: Argument of type "int_" cannot be assigned to parameter "num" of + # type "int" in function "tile_compat" + return [ + tile_compat( + np.repeat(x, b[i]), + np.product(a[i]), # pyright: ignore[reportGeneralTypeIssues] + ) + for i, x in enumerate(X) + ] def tile_compat(arr: NumpyIndexT, num: int) -> NumpyIndexT: