diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index f337589c355832..7dddb9f3d6f25a 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -493,8 +493,7 @@ def size(self) -> int: """ The number of elements in the array. """ - # error: Incompatible return value type (got "number", expected "int") - return np.prod(self.shape) # type: ignore[return-value] + return np.prod(self.shape) @property def ndim(self) -> int: diff --git a/pandas/core/arrays/sparse/accessor.py b/pandas/core/arrays/sparse/accessor.py index d4faea4fbc42c1..8efdfb719bbfac 100644 --- a/pandas/core/arrays/sparse/accessor.py +++ b/pandas/core/arrays/sparse/accessor.py @@ -354,9 +354,8 @@ def density(self) -> float: """ Ratio of non-sparse points to total (dense) data points. """ - # error: Incompatible return value type (got "number", expected "float") tmp = np.mean([column.array.density for _, column in self._parent.items()]) - return tmp # type: ignore[return-value] + return tmp @staticmethod def _prep_index(data, index, columns): diff --git a/pandas/core/generic.py b/pandas/core/generic.py index c9982db97e8244..7162bda0eff43e 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -693,8 +693,7 @@ def size(self) -> int: >>> df.size 4 """ - # error: Incompatible return value type (got "number", expected "int") - return np.prod(self.shape) # type: ignore[return-value] + return np.prod(self.shape) @overload def set_axis( diff --git a/pandas/core/nanops.py b/pandas/core/nanops.py index 2c31e45d0b4e17..b8909f16ee8760 100644 --- a/pandas/core/nanops.py +++ b/pandas/core/nanops.py @@ -588,17 +588,9 @@ def nansum( dtype_sum = np.float64 # type: ignore[assignment] the_sum = values.sum(axis, dtype=dtype_sum) - # error: Incompatible types in assignment (expression has type "float", variable has - # type "Union[number, ndarray]") - # error: Argument 1 to "_maybe_null_out" has incompatible type "Union[number, - # ndarray]"; expected "ndarray" - the_sum = _maybe_null_out( # type: ignore[assignment] - the_sum, axis, mask, values.shape, min_count=min_count # type: ignore[arg-type] - ) + the_sum = _maybe_null_out(the_sum, axis, mask, values.shape, min_count=min_count) - # error: Incompatible return value type (got "Union[number, ndarray]", expected - # "float") - return the_sum # type: ignore[return-value] + return the_sum def _mask_datetimelike_result( @@ -1343,12 +1335,10 @@ def nanprod( values = values.copy() values[mask] = 1 result = values.prod(axis) - # error: Argument 1 to "_maybe_null_out" has incompatible type "Union[number, - # ndarray]"; expected "ndarray" # error: Incompatible return value type (got "Union[ndarray, float]", expected # "float") return _maybe_null_out( # type: ignore[return-value] - result, axis, mask, values.shape, min_count=min_count # type: ignore[arg-type] + result, axis, mask, values.shape, min_count=min_count ) @@ -1424,13 +1414,7 @@ def _get_counts( # expected "Union[int, float, ndarray]") return dtype.type(count) # type: ignore[return-value] try: - # error: Incompatible return value type (got "Union[ndarray, generic]", expected - # "Union[int, float, ndarray]") - # error: Argument 1 to "astype" of "_ArrayOrScalarCommon" has incompatible type - # "Union[ExtensionDtype, dtype]"; expected "Union[dtype, None, type, - # _SupportsDtype, str, Tuple[Any, int], Tuple[Any, Union[int, Sequence[int]]], - # List[Any], _DtypeDict, Tuple[Any, Any]]" - return count.astype(dtype) # type: ignore[return-value,arg-type] + return count.astype(dtype) except AttributeError: # error: Argument "dtype" to "array" has incompatible type # "Union[ExtensionDtype, dtype]"; expected "Union[dtype, None, type, diff --git a/pandas/core/reshape/reshape.py b/pandas/core/reshape/reshape.py index 037fe5366255ae..93859eb11dd441 100644 --- a/pandas/core/reshape/reshape.py +++ b/pandas/core/reshape/reshape.py @@ -176,9 +176,7 @@ def _make_selectors(self): self.full_shape = ngroups, stride selector = self.sorted_labels[-1] + stride * comp_index + self.lift - # error: Argument 1 to "zeros" has incompatible type "number"; expected - # "Union[int, Sequence[int]]" - mask = np.zeros(np.prod(self.full_shape), dtype=bool) # type: ignore[arg-type] + mask = np.zeros(np.prod(self.full_shape), dtype=bool) mask.put(selector, True) if mask.sum() < len(self.index): diff --git a/pandas/core/sorting.py b/pandas/core/sorting.py index f6c1afbde0bd9b..8531f93fba3217 100644 --- a/pandas/core/sorting.py +++ b/pandas/core/sorting.py @@ -630,22 +630,15 @@ def get_group_index_sorter( np.ndarray[np.intp] """ if ngroups is None: - # error: Incompatible types in assignment (expression has type "number[Any]", - # variable has type "Optional[int]") - ngroups = 1 + group_index.max() # type: ignore[assignment] + ngroups = 1 + group_index.max() count = len(group_index) alpha = 0.0 # taking complexities literally; there may be beta = 1.0 # some room for fine-tuning these parameters - # error: Unsupported operand types for * ("float" and "None") - do_groupsort = count > 0 and ( - (alpha + beta * ngroups) < (count * np.log(count)) # type: ignore[operator] - ) + do_groupsort = count > 0 and ((alpha + beta * ngroups) < (count * np.log(count))) if do_groupsort: - # Argument 2 to "groupsort_indexer" has incompatible type - # "Optional[int]"; expected "int" sorter, _ = algos.groupsort_indexer( ensure_platform_int(group_index), - ngroups, # type: ignore[arg-type] + ngroups, ) # sorter _should_ already be intp, but mypy is not yet able to verify else: diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index a58f913408e0b7..63f79a32f5297d 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1664,19 +1664,9 @@ def format_percentiles( ).astype(int) prec = max(1, prec) out = np.empty_like(percentiles, dtype=object) - # error: No overload variant of "__getitem__" of "list" matches argument type - # "Union[bool_, ndarray]" - out[int_idx] = ( - percentiles[int_idx].astype(int).astype(str) # type: ignore[call-overload] - ) + out[int_idx] = percentiles[int_idx].astype(int).astype(str) - # error: Item "float" of "Union[Any, float, str]" has no attribute "round" - # error: Item "str" of "Union[Any, float, str]" has no attribute "round" - # error: Invalid index type "Union[bool_, Any]" for "Union[ndarray, List[Union[int, - # float]], List[float], List[Union[str, float]]]"; expected type "int" - out[~int_idx] = ( - percentiles[~int_idx].round(prec).astype(str) # type: ignore[union-attr,index] - ) + out[~int_idx] = percentiles[~int_idx].round(prec).astype(str) return [i + "%" for i in out] diff --git a/pandas/io/parsers/base_parser.py b/pandas/io/parsers/base_parser.py index 49eb7ea9f26e59..df2bfa7d2a8700 100644 --- a/pandas/io/parsers/base_parser.py +++ b/pandas/io/parsers/base_parser.py @@ -684,9 +684,7 @@ def _infer_types(self, values, na_values, try_num_bool=True): # error: Argument 2 to "isin" has incompatible type "List[Any]"; expected # "Union[Union[ExtensionArray, ndarray], Index, Series]" mask = algorithms.isin(values, list(na_values)) # type: ignore[arg-type] - # error: Incompatible types in assignment (expression has type - # "number[Any]", variable has type "int") - na_count = mask.sum() # type: ignore[assignment] + na_count = mask.sum() if na_count > 0: if is_integer_dtype(values): values = values.astype(np.float64) diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 10d55053d5bc61..75f5a8bf3c3577 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -3378,10 +3378,7 @@ def validate_multiindex( @property def nrows_expected(self) -> int: """ based on our axes, compute the expected nrows """ - # error: Incompatible return value type (got "number", expected "int") - return np.prod( # type: ignore[return-value] - [i.cvalues.shape[0] for i in self.index_axes] - ) + return np.prod([i.cvalues.shape[0] for i in self.index_axes]) @property def is_exists(self) -> bool: