Skip to content

Commit 9461d8d

Browse files
committed
Remove type ignores
1 parent 83052c1 commit 9461d8d

File tree

13 files changed

+22
-107
lines changed

13 files changed

+22
-107
lines changed

pandas/core/algorithms.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -1064,12 +1064,7 @@ def checked_add_with_arr(
10641064
elif arr_mask is not None:
10651065
not_nan = np.logical_not(arr_mask)
10661066
elif b_mask is not None:
1067-
# Argument 1 to "__call__" of "_UFunc_Nin1_Nout1" has incompatible type
1068-
# "Optional[ndarray[Any, dtype[bool_]]]"; expected
1069-
# "Union[_SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[An
1070-
# y]]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool,
1071-
# int, float, complex, str, bytes]]]" [arg-type]
1072-
not_nan = np.logical_not(b2_mask) # type: ignore[arg-type]
1067+
not_nan = np.logical_not(b2_mask)
10731068
else:
10741069
not_nan = np.empty(arr.shape, dtype=bool)
10751070
not_nan.fill(True)

pandas/core/array_algos/quantile.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,7 @@ def _nanpercentile_1d(
143143
return np.percentile(
144144
values,
145145
qs,
146-
# error: No overload variant of "percentile" matches argument types
147-
# "ndarray[Any, Any]", "ndarray[Any, dtype[floating[_64Bit]]]",
148-
# "int", "Dict[str, str]"
149-
**{np_percentile_argname: interpolation}, # type: ignore[call-overload]
146+
**{np_percentile_argname: interpolation},
150147
)
151148

152149

@@ -215,8 +212,5 @@ def _nanpercentile(
215212
values,
216213
qs,
217214
axis=1,
218-
# error: No overload variant of "percentile" matches argument types
219-
# "ndarray[Any, Any]", "ndarray[Any, dtype[floating[_64Bit]]]",
220-
# "int", "Dict[str, str]"
221-
**{np_percentile_argname: interpolation}, # type: ignore[call-overload]
215+
**{np_percentile_argname: interpolation},
222216
)

pandas/core/arrays/interval.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -1665,13 +1665,7 @@ def isin(self, values) -> np.ndarray:
16651665
# complex128 ndarray is much more performant.
16661666
left = self._combined.view("complex128")
16671667
right = values._combined.view("complex128")
1668-
# Argument 1 to "in1d" has incompatible type "Union[ExtensionArray,
1669-
# ndarray[Any, Any], ndarray[Any, dtype[Any]]]"; expected
1670-
# "Union[_SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[
1671-
# dtype[Any]]], bool, int, float, complex, str, bytes,
1672-
# _NestedSequence[Union[bool, int, float, complex, str, bytes]]]"
1673-
# [arg-type]
1674-
return np.in1d(left, right) # type: ignore[arg-type]
1668+
return np.in1d(left, right)
16751669

16761670
elif needs_i8_conversion(self.left.dtype) ^ needs_i8_conversion(
16771671
values.left.dtype

pandas/core/arrays/masked.py

+2-10
Original file line numberDiff line numberDiff line change
@@ -1151,11 +1151,7 @@ def any(self, *, skipna: bool = True, **kwargs):
11511151
nv.validate_any((), kwargs)
11521152

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

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

12411233
if skipna:

pandas/core/arrays/sparse/array.py

+3-14
Original file line numberDiff line numberDiff line change
@@ -944,15 +944,7 @@ def __getitem__(
944944
if is_integer(key):
945945
return self._get_val_at(key)
946946
elif isinstance(key, tuple):
947-
# Invalid index type "Tuple[Union[int, ellipsis], ...]" for
948-
# "ndarray[Any, Any]"; expected type "Union[SupportsIndex,
949-
# _SupportsArray[dtype[Union[bool_, integer[Any]]]], _NestedSequence[_Su
950-
# pportsArray[dtype[Union[bool_, integer[Any]]]]],
951-
# _NestedSequence[Union[bool, int]], Tuple[Union[SupportsIndex,
952-
# _SupportsArray[dtype[Union[bool_, integer[Any]]]],
953-
# _NestedSequence[_SupportsArray[dtype[Union[bool_, integer[Any]]]]], _N
954-
# estedSequence[Union[bool, int]]], ...]]" [index]
955-
data_slice = self.to_dense()[key] # type: ignore[index]
947+
data_slice = self.to_dense()[key]
956948
elif isinstance(key, slice):
957949

958950
# Avoid densifying when handling contiguous slices
@@ -1192,9 +1184,7 @@ def _concat_same_type(
11921184

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

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

13911380
self._sparse_values = sparse_values

pandas/core/frame.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -2481,9 +2481,7 @@ def to_records(
24812481
if dtype_mapping is None:
24822482
formats.append(v.dtype)
24832483
elif isinstance(dtype_mapping, (type, np.dtype, str)):
2484-
# Argument 1 to "append" of "list" has incompatible type
2485-
# "Union[type, dtype[Any], str]"; expected "dtype[_SCT]" [arg-type]
2486-
formats.append(dtype_mapping) # type: ignore[arg-type]
2484+
formats.append(dtype_mapping)
24872485
else:
24882486
element = "row" if i < index_len else "column"
24892487
msg = f"Invalid dtype {dtype_mapping} specified for {element} {name}"

pandas/core/indexes/base.py

+3-12
Original file line numberDiff line numberDiff line change
@@ -4834,12 +4834,7 @@ def _join_non_unique(
48344834
right = other._values.take(right_idx)
48354835

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

@@ -5351,11 +5346,9 @@ def __getitem__(self, key):
53515346
if result.ndim > 1:
53525347
deprecate_ndim_indexing(result)
53535348
if hasattr(result, "_ndarray"):
5354-
# error: Item "ndarray[Any, Any]" of "Union[ExtensionArray,
5355-
# ndarray[Any, Any]]" has no attribute "_ndarray" [union-attr]
53565349
# i.e. NDArrayBackedExtensionArray
53575350
# Unpack to ndarray for MPL compat
5358-
return result._ndarray # type: ignore[union-attr]
5351+
return result._ndarray
53595352
return result
53605353

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

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

pandas/core/indexes/multi.py

+2-9
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,7 @@ def _validate_codes(self, level: list, code: list):
363363
"""
364364
null_mask = isna(level)
365365
if np.any(null_mask):
366-
# Incompatible types in assignment (expression has type
367-
# "ndarray[Any, dtype[Any]]", variable has type "List[Any]")
368-
code = np.where(null_mask[code], -1, code) # type: ignore[assignment]
366+
code = np.where(null_mask[code], -1, code)
369367
return code
370368

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

pandas/core/missing.py

+3-20
Original file line numberDiff line numberDiff line change
@@ -333,15 +333,7 @@ def func(yvalues: np.ndarray) -> None:
333333
**kwargs,
334334
)
335335

336-
# Argument 1 to "apply_along_axis" has incompatible type
337-
# "Callable[[ndarray[Any, Any]], None]"; expected
338-
# "Callable[..., Union[_SupportsArray[dtype[<nothing>]],
339-
# Sequence[_SupportsArray[dtype[<nothing>
340-
# ]]], Sequence[Sequence[_SupportsArray[dtype[<nothing>]]]],
341-
# Sequence[Sequence[Sequence[_SupportsArray[dtype[<nothing>]]]]],
342-
# Sequence[Sequence[Sequence[Sequence[_SupportsArray[dtype[<nothing>]]]]]]]]"
343-
# interp each column independently
344-
np.apply_along_axis(func, axis, data) # type: ignore[arg-type]
336+
np.apply_along_axis(func, axis, data)
345337
return
346338

347339

@@ -779,23 +771,14 @@ def interpolate_2d(
779771
Modifies values in-place.
780772
"""
781773
if limit_area is not None:
782-
# Argument 1 to "apply_along_axis" has incompatible type "partial[None]";
783-
# expected "Callable[..., Union[_SupportsArray[dtype[<nothing>]],
784-
# Sequence[_SupportsArray[dtype[<nothing>]]], Sequence[Sequence
785-
# [_SupportsArray[dtype[<nothing>]]]],
786-
# Sequence[Sequence[Sequence[_SupportsArray[dtype[<nothing>]]]]],
787-
# Sequence[Sequence[Sequence[Sequence[_SupportsArray[dtype[<nothing>]]]]]]]]"
788-
789-
# Argument 2 to "apply_along_axis" has incompatible type "Union[str, int]";
790-
# expected "SupportsIndex" [arg-type]
791774
np.apply_along_axis(
792775
partial(
793776
_interpolate_with_limit_area,
794777
method=method,
795778
limit=limit,
796779
limit_area=limit_area,
797-
), # type: ignore[arg-type]
798-
axis, # type: ignore[arg-type]
780+
),
781+
axis,
799782
values,
800783
)
801784
return

pandas/core/reshape/melt.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,7 @@ def melt(
133133
if is_extension_array_dtype(id_data):
134134
id_data = concat([id_data] * K, ignore_index=True)
135135
else:
136-
# Incompatible types in assignment (expression has type
137-
# "ndarray[Any, dtype[Any]]", variable has type "Series") [assignment]
138-
id_data = np.tile(id_data._values, K) # type: ignore[assignment]
136+
id_data = np.tile(id_data._values, K)
139137
mdata[col] = id_data
140138

141139
mcolumns = id_vars + var_name + [value_name]

pandas/core/series.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -2023,9 +2023,7 @@ def count(self, level=None):
20232023
lev = lev.insert(cnt, lev._na_value)
20242024

20252025
obs = level_codes[notna(self._values)]
2026-
# Argument "minlength" to "bincount" has incompatible type "Optional[int]";
2027-
# expected "SupportsIndex" [arg-type]
2028-
out = np.bincount(obs, minlength=len(lev) or None) # type: ignore[arg-type]
2026+
out = np.bincount(obs, minlength=len(lev) or None)
20292027
return self._constructor(out, index=lev, dtype="int64").__finalize__(
20302028
self, method="count"
20312029
)

pandas/io/parsers/c_parser_wrapper.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -400,14 +400,7 @@ def _concatenate_chunks(chunks: list[dict[int, ArrayLike]]) -> dict:
400400
arrs # type: ignore[arg-type]
401401
)
402402
else:
403-
# Argument 1 to "concatenate" has incompatible type
404-
# "List[Union[ExtensionArray, ndarray[Any, Any]]]"; expected
405-
# "Union[_SupportsArray[dtype[Any]],
406-
# Sequence[_SupportsArray[dtype[Any]]],
407-
# Sequence[Sequence[_SupportsArray[dtype[Any]]]],
408-
# Sequence[Sequence[Sequence[_SupportsArray[dtype[Any]]]]],
409-
# Sequence[Sequence[Sequence[Sequence[_SupportsArray[dtype[Any]]]]]]]"
410-
result[name] = np.concatenate(arrs) # type: ignore[arg-type]
403+
result[name] = np.concatenate(arrs)
411404

412405
if warning_columns:
413406
warning_names = ",".join(warning_columns)

pandas/tests/extension/date/array.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,7 @@ def __init__(
109109
self._month = np.zeros(ldates, dtype=np.uint8) # 255 (1, 31)
110110
self._day = np.zeros(ldates, dtype=np.uint8) # 255 (1, 12)
111111

112-
# "object_" object is not iterable [misc]
113-
for (i,), (y, m, d) in np.ndenumerate( # type: ignore[misc]
114-
np.char.split(dates, sep="-")
115-
):
112+
for (i,), (y, m, d) in np.ndenumerate(np.char.split(dates, sep="-")):
116113
self._year[i] = int(y)
117114
self._month[i] = int(m)
118115
self._day[i] = int(d)

0 commit comments

Comments
 (0)