diff --git a/pandas/_typing.py b/pandas/_typing.py index 08096569c61a7..03fb5fcb1b0d4 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 1e3b137184660..4b87194a2f1f1 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -540,7 +540,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/accessor.py b/pandas/core/arrays/sparse/accessor.py index 80713a6fca323..f1e4412ff8cd8 100644 --- a/pandas/core/arrays/sparse/accessor.py +++ b/pandas/core/arrays/sparse/accessor.py @@ -369,7 +369,8 @@ def density(self) -> float: Ratio of non-sparse points to total (dense) data points. """ tmp = np.mean([column.array.density for _, column in self._parent.items()]) - return tmp + # error: Expression of type "floating" cannot be assigned to return type "float" + return tmp # pyright: ignore[reportGeneralTypeIssues] @staticmethod def _prep_index(data, index, columns): diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py index e2a0740dd214e..5831aafa6a293 100644 --- a/pandas/core/arrays/sparse/array.py +++ b/pandas/core/arrays/sparse/array.py @@ -1424,8 +1424,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 ca3ba5ec4bdd4..1323ecaa7f1e2 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -80,6 +80,7 @@ from pandas._typing import ( NumpySorter, NumpyValueArrayLike, + ScalarLike_co, ) from pandas import ( @@ -1267,7 +1268,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 e809e761ebbb2..189ffc3d485bf 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 20c5592071e2c..e3153487cbf81 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -707,7 +707,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 7fe1d55ba55be..16a7e537544c3 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -691,7 +691,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 943077e575266..92331c9777abb 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 7cb78bda90606..56c04b8a6d6e3 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -1886,7 +1886,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/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: