Skip to content

Commit

Permalink
Remove type ignores
Browse files Browse the repository at this point in the history
  • Loading branch information
mroeschke committed Jun 13, 2022
1 parent 83052c1 commit 9461d8d
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 107 deletions.
7 changes: 1 addition & 6 deletions pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,12 +1064,7 @@ def checked_add_with_arr(
elif arr_mask is not None:
not_nan = np.logical_not(arr_mask)
elif b_mask is not None:
# Argument 1 to "__call__" of "_UFunc_Nin1_Nout1" has incompatible type
# "Optional[ndarray[Any, dtype[bool_]]]"; expected
# "Union[_SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[An
# y]]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool,
# int, float, complex, str, bytes]]]" [arg-type]
not_nan = np.logical_not(b2_mask) # type: ignore[arg-type]
not_nan = np.logical_not(b2_mask)
else:
not_nan = np.empty(arr.shape, dtype=bool)
not_nan.fill(True)
Expand Down
10 changes: 2 additions & 8 deletions pandas/core/array_algos/quantile.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,7 @@ def _nanpercentile_1d(
return np.percentile(
values,
qs,
# error: No overload variant of "percentile" matches argument types
# "ndarray[Any, Any]", "ndarray[Any, dtype[floating[_64Bit]]]",
# "int", "Dict[str, str]"
**{np_percentile_argname: interpolation}, # type: ignore[call-overload]
**{np_percentile_argname: interpolation},
)


Expand Down Expand Up @@ -215,8 +212,5 @@ def _nanpercentile(
values,
qs,
axis=1,
# error: No overload variant of "percentile" matches argument types
# "ndarray[Any, Any]", "ndarray[Any, dtype[floating[_64Bit]]]",
# "int", "Dict[str, str]"
**{np_percentile_argname: interpolation}, # type: ignore[call-overload]
**{np_percentile_argname: interpolation},
)
8 changes: 1 addition & 7 deletions pandas/core/arrays/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -1665,13 +1665,7 @@ def isin(self, values) -> np.ndarray:
# complex128 ndarray is much more performant.
left = self._combined.view("complex128")
right = values._combined.view("complex128")
# Argument 1 to "in1d" has incompatible type "Union[ExtensionArray,
# ndarray[Any, Any], ndarray[Any, dtype[Any]]]"; expected
# "Union[_SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[
# dtype[Any]]], bool, int, float, complex, str, bytes,
# _NestedSequence[Union[bool, int, float, complex, str, bytes]]]"
# [arg-type]
return np.in1d(left, right) # type: ignore[arg-type]
return np.in1d(left, right)

elif needs_i8_conversion(self.left.dtype) ^ needs_i8_conversion(
values.left.dtype
Expand Down
12 changes: 2 additions & 10 deletions pandas/core/arrays/masked.py
Original file line number Diff line number Diff line change
Expand Up @@ -1151,11 +1151,7 @@ def any(self, *, skipna: bool = True, **kwargs):
nv.validate_any((), kwargs)

values = self._data.copy()
# Argument 3 to "putmask" has incompatible type "object"; expected
# "Union[_SupportsArray[dtype[Any]], _NestedSequence[
# _SupportsArray[dtype[Any]]], bool, int, float, complex, str, bytes, _Nested
# Sequence[Union[bool, int, float, complex, str, bytes]]]" [arg-type]
np.putmask(values, self._mask, self._falsey_value) # type: ignore[arg-type]
np.putmask(values, self._mask, self._falsey_value)
result = values.any()
if skipna:
return result
Expand Down Expand Up @@ -1231,11 +1227,7 @@ def all(self, *, skipna: bool = True, **kwargs):
nv.validate_all((), kwargs)

values = self._data.copy()
# Argument 3 to "putmask" has incompatible type "object"; expected
# "Union[_SupportsArray[dtype[Any]], _NestedSequence[
# _SupportsArray[dtype[Any]]], bool, int, float, complex, str, bytes, _Neste
# dSequence[Union[bool, int, float, complex, str, bytes]]]" [arg-type]
np.putmask(values, self._mask, self._truthy_value) # type: ignore[arg-type]
np.putmask(values, self._mask, self._truthy_value)
result = values.all()

if skipna:
Expand Down
17 changes: 3 additions & 14 deletions pandas/core/arrays/sparse/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,15 +944,7 @@ def __getitem__(
if is_integer(key):
return self._get_val_at(key)
elif isinstance(key, tuple):
# Invalid index type "Tuple[Union[int, ellipsis], ...]" for
# "ndarray[Any, Any]"; expected type "Union[SupportsIndex,
# _SupportsArray[dtype[Union[bool_, integer[Any]]]], _NestedSequence[_Su
# pportsArray[dtype[Union[bool_, integer[Any]]]]],
# _NestedSequence[Union[bool, int]], Tuple[Union[SupportsIndex,
# _SupportsArray[dtype[Union[bool_, integer[Any]]]],
# _NestedSequence[_SupportsArray[dtype[Union[bool_, integer[Any]]]]], _N
# estedSequence[Union[bool, int]]], ...]]" [index]
data_slice = self.to_dense()[key] # type: ignore[index]
data_slice = self.to_dense()[key]
elif isinstance(key, slice):

# Avoid densifying when handling contiguous slices
Expand Down Expand Up @@ -1192,9 +1184,7 @@ def _concat_same_type(

data = np.concatenate(values)
indices_arr = np.concatenate(indices)
# Argument 2 to "IntIndex" has incompatible type "ndarray[Any,
# dtype[signedinteger[_32Bit]]]"; expected "Sequence[int]"
sp_index = IntIndex(length, indices_arr) # type: ignore[arg-type]
sp_index = IntIndex(length, indices_arr)

else:
# when concatenating block indices, we don't claim that you'll
Expand Down Expand Up @@ -1384,8 +1374,7 @@ def __setstate__(self, state):
if isinstance(state, tuple):
# Compat for pandas < 0.24.0
nd_state, (fill_value, sp_index) = state
# Need type annotation for "sparse_values" [var-annotated]
sparse_values = np.array([]) # type: ignore[var-annotated]
sparse_values = np.array([])
sparse_values.__setstate__(nd_state)

self._sparse_values = sparse_values
Expand Down
4 changes: 1 addition & 3 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2481,9 +2481,7 @@ def to_records(
if dtype_mapping is None:
formats.append(v.dtype)
elif isinstance(dtype_mapping, (type, np.dtype, str)):
# Argument 1 to "append" of "list" has incompatible type
# "Union[type, dtype[Any], str]"; expected "dtype[_SCT]" [arg-type]
formats.append(dtype_mapping) # type: ignore[arg-type]
formats.append(dtype_mapping)
else:
element = "row" if i < index_len else "column"
msg = f"Invalid dtype {dtype_mapping} specified for {element} {name}"
Expand Down
15 changes: 3 additions & 12 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4834,12 +4834,7 @@ def _join_non_unique(
right = other._values.take(right_idx)

if isinstance(join_array, np.ndarray):
# Argument 3 to "putmask" has incompatible type "Union[ExtensionArray,
# ndarray[Any, Any]]"; expected "Union[_SupportsArray[dtype[Any]],
# _NestedSequence[_SupportsArray[dtype[Any]]], bool, int, f
# loat, complex, str, bytes, _NestedSequence[Union[bool, int, float,
# complex, str, bytes]]]" [arg-type]
np.putmask(join_array, mask, right) # type: ignore[arg-type]
np.putmask(join_array, mask, right)
else:
join_array._putmask(mask, right)

Expand Down Expand Up @@ -5351,11 +5346,9 @@ def __getitem__(self, key):
if result.ndim > 1:
deprecate_ndim_indexing(result)
if hasattr(result, "_ndarray"):
# error: Item "ndarray[Any, Any]" of "Union[ExtensionArray,
# ndarray[Any, Any]]" has no attribute "_ndarray" [union-attr]
# i.e. NDArrayBackedExtensionArray
# Unpack to ndarray for MPL compat
return result._ndarray # type: ignore[union-attr]
return result._ndarray
return result

# NB: Using _constructor._simple_new would break if MultiIndex
Expand Down Expand Up @@ -6893,9 +6886,7 @@ def insert(self, loc: int, item) -> Index:
new_values = np.insert(arr, loc, casted)

else:
# No overload variant of "insert" matches argument types
# "ndarray[Any, Any]", "int", "None" [call-overload]
new_values = np.insert(arr, loc, None) # type: ignore[call-overload]
new_values = np.insert(arr, loc, None)
loc = loc if loc >= 0 else loc - 1
new_values[loc] = item

Expand Down
11 changes: 2 additions & 9 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,7 @@ def _validate_codes(self, level: list, code: list):
"""
null_mask = isna(level)
if np.any(null_mask):
# Incompatible types in assignment (expression has type
# "ndarray[Any, dtype[Any]]", variable has type "List[Any]")
code = np.where(null_mask[code], -1, code) # type: ignore[assignment]
code = np.where(null_mask[code], -1, code)
return code

def _verify_integrity(self, codes: list | None = None, levels: list | None = None):
Expand Down Expand Up @@ -1579,12 +1577,7 @@ def is_monotonic_increasing(self) -> bool:
self._get_level_values(i)._values for i in reversed(range(len(self.levels)))
]
try:
# Argument 1 to "lexsort" has incompatible type "List[Union[ExtensionArray,
# ndarray[Any, Any]]]"; expected "Union[_SupportsArray[dtype[Any]],
# _NestedSequence[_SupportsArray[dtype[Any]]], bool,
# int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float,
# complex, str, bytes]]]" [arg-type]
sort_order = np.lexsort(values) # type: ignore[arg-type]
sort_order = np.lexsort(values)
return Index(sort_order).is_monotonic_increasing
except TypeError:

Expand Down
23 changes: 3 additions & 20 deletions pandas/core/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,15 +333,7 @@ def func(yvalues: np.ndarray) -> None:
**kwargs,
)

# Argument 1 to "apply_along_axis" has incompatible type
# "Callable[[ndarray[Any, Any]], None]"; expected
# "Callable[..., Union[_SupportsArray[dtype[<nothing>]],
# Sequence[_SupportsArray[dtype[<nothing>
# ]]], Sequence[Sequence[_SupportsArray[dtype[<nothing>]]]],
# Sequence[Sequence[Sequence[_SupportsArray[dtype[<nothing>]]]]],
# Sequence[Sequence[Sequence[Sequence[_SupportsArray[dtype[<nothing>]]]]]]]]"
# interp each column independently
np.apply_along_axis(func, axis, data) # type: ignore[arg-type]
np.apply_along_axis(func, axis, data)
return


Expand Down Expand Up @@ -779,23 +771,14 @@ def interpolate_2d(
Modifies values in-place.
"""
if limit_area is not None:
# Argument 1 to "apply_along_axis" has incompatible type "partial[None]";
# expected "Callable[..., Union[_SupportsArray[dtype[<nothing>]],
# Sequence[_SupportsArray[dtype[<nothing>]]], Sequence[Sequence
# [_SupportsArray[dtype[<nothing>]]]],
# Sequence[Sequence[Sequence[_SupportsArray[dtype[<nothing>]]]]],
# Sequence[Sequence[Sequence[Sequence[_SupportsArray[dtype[<nothing>]]]]]]]]"

# Argument 2 to "apply_along_axis" has incompatible type "Union[str, int]";
# expected "SupportsIndex" [arg-type]
np.apply_along_axis(
partial(
_interpolate_with_limit_area,
method=method,
limit=limit,
limit_area=limit_area,
), # type: ignore[arg-type]
axis, # type: ignore[arg-type]
),
axis,
values,
)
return
Expand Down
4 changes: 1 addition & 3 deletions pandas/core/reshape/melt.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ def melt(
if is_extension_array_dtype(id_data):
id_data = concat([id_data] * K, ignore_index=True)
else:
# Incompatible types in assignment (expression has type
# "ndarray[Any, dtype[Any]]", variable has type "Series") [assignment]
id_data = np.tile(id_data._values, K) # type: ignore[assignment]
id_data = np.tile(id_data._values, K)
mdata[col] = id_data

mcolumns = id_vars + var_name + [value_name]
Expand Down
4 changes: 1 addition & 3 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2023,9 +2023,7 @@ def count(self, level=None):
lev = lev.insert(cnt, lev._na_value)

obs = level_codes[notna(self._values)]
# Argument "minlength" to "bincount" has incompatible type "Optional[int]";
# expected "SupportsIndex" [arg-type]
out = np.bincount(obs, minlength=len(lev) or None) # type: ignore[arg-type]
out = np.bincount(obs, minlength=len(lev) or None)
return self._constructor(out, index=lev, dtype="int64").__finalize__(
self, method="count"
)
Expand Down
9 changes: 1 addition & 8 deletions pandas/io/parsers/c_parser_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,14 +400,7 @@ def _concatenate_chunks(chunks: list[dict[int, ArrayLike]]) -> dict:
arrs # type: ignore[arg-type]
)
else:
# Argument 1 to "concatenate" has incompatible type
# "List[Union[ExtensionArray, ndarray[Any, Any]]]"; expected
# "Union[_SupportsArray[dtype[Any]],
# Sequence[_SupportsArray[dtype[Any]]],
# Sequence[Sequence[_SupportsArray[dtype[Any]]]],
# Sequence[Sequence[Sequence[_SupportsArray[dtype[Any]]]]],
# Sequence[Sequence[Sequence[Sequence[_SupportsArray[dtype[Any]]]]]]]"
result[name] = np.concatenate(arrs) # type: ignore[arg-type]
result[name] = np.concatenate(arrs)

if warning_columns:
warning_names = ",".join(warning_columns)
Expand Down
5 changes: 1 addition & 4 deletions pandas/tests/extension/date/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,7 @@ def __init__(
self._month = np.zeros(ldates, dtype=np.uint8) # 255 (1, 31)
self._day = np.zeros(ldates, dtype=np.uint8) # 255 (1, 12)

# "object_" object is not iterable [misc]
for (i,), (y, m, d) in np.ndenumerate( # type: ignore[misc]
np.char.split(dates, sep="-")
):
for (i,), (y, m, d) in np.ndenumerate(np.char.split(dates, sep="-")):
self._year[i] = int(y)
self._month[i] = int(m)
self._day[i] = int(d)
Expand Down

0 comments on commit 9461d8d

Please sign in to comment.