Skip to content

Commit 18d46b1

Browse files
TYP: remove some ignores (#42368)
1 parent ed2af7e commit 18d46b1

File tree

5 files changed

+23
-19
lines changed

5 files changed

+23
-19
lines changed

pandas/_testing/asserters.py

+2
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ def assert_almost_equal(
107107
FutureWarning,
108108
stacklevel=2,
109109
)
110+
# https://github.com/python/mypy/issues/7642
110111
# error: Argument 1 to "_get_tol_from_less_precise" has incompatible
111112
# type "Union[bool, int, NoDefault]"; expected "Union[bool, int]"
112113
rtol = atol = _get_tol_from_less_precise(
@@ -340,6 +341,7 @@ def _get_ilevel_values(index, level):
340341
FutureWarning,
341342
stacklevel=2,
342343
)
344+
# https://github.com/python/mypy/issues/7642
343345
# error: Argument 1 to "_get_tol_from_less_precise" has incompatible
344346
# type "Union[bool, int, NoDefault]"; expected "Union[bool, int]"
345347
rtol = atol = _get_tol_from_less_precise(

pandas/core/algorithms.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -1187,13 +1187,10 @@ def _get_score(at):
11871187

11881188
if is_scalar(q):
11891189
return _get_score(q)
1190-
else:
1191-
q = np.asarray(q, np.float64)
1192-
result = [_get_score(x) for x in q]
1193-
# error: Incompatible types in assignment (expression has type
1194-
# "ndarray", variable has type "List[Any]")
1195-
result = np.array(result, dtype=np.float64) # type: ignore[assignment]
1196-
return result
1190+
1191+
q = np.asarray(q, np.float64)
1192+
result = [_get_score(x) for x in q]
1193+
return np.array(result, dtype=np.float64)
11971194

11981195

11991196
# --------------- #

pandas/core/apply.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Any,
88
Dict,
99
Hashable,
10+
Iterable,
1011
Iterator,
1112
List,
1213
cast,
@@ -443,16 +444,15 @@ def agg_dict_like(self) -> DataFrame | Series:
443444

444445
# combine results
445446
if all(is_ndframe):
447+
keys_to_use: Iterable[Hashable]
446448
keys_to_use = [k for k in keys if not results[k].empty]
447449
# Have to check, if at least one DataFrame is not empty.
448450
keys_to_use = keys_to_use if keys_to_use != [] else keys
449451
if selected_obj.ndim == 2:
450452
# keys are columns, so we can preserve names
451453
ktu = Index(keys_to_use)
452454
ktu._set_names(selected_obj.columns.names)
453-
# Incompatible types in assignment (expression has type "Index",
454-
# variable has type "List[Hashable]")
455-
keys_to_use = ktu # type: ignore[assignment]
455+
keys_to_use = ktu
456456

457457
axis = 0 if isinstance(obj, ABCSeries) else 1
458458
result = concat(

pandas/core/base.py

+13-9
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
import pandas._libs.lib as lib
2020
from pandas._typing import (
2121
ArrayLike,
22-
Dtype,
2322
DtypeObj,
2423
FrameOrSeries,
2524
IndexLabel,
2625
Shape,
2726
final,
27+
npt,
2828
)
2929
from pandas.compat import PYPY
3030
from pandas.compat.numpy import function as nv
@@ -411,7 +411,7 @@ def array(self) -> ExtensionArray:
411411

412412
def to_numpy(
413413
self,
414-
dtype: Dtype | None = None,
414+
dtype: npt.DTypeLike | None = None,
415415
copy: bool = False,
416416
na_value=lib.no_default,
417417
**kwargs,
@@ -510,21 +510,24 @@ def to_numpy(
510510
"""
511511
if is_extension_array_dtype(self.dtype):
512512
# error: Too many arguments for "to_numpy" of "ExtensionArray"
513+
514+
# error: Argument 1 to "to_numpy" of "ExtensionArray" has incompatible type
515+
# "Optional[Union[dtype[Any], None, type, _SupportsDType[dtype[Any]], str,
516+
# Union[Tuple[Any, int], Tuple[Any, Union[SupportsIndex,
517+
# Sequence[SupportsIndex]]], List[Any], _DTypeDict, Tuple[Any, Any]]]]";
518+
# expected "Optional[Union[ExtensionDtype, Union[str, dtype[Any]],
519+
# Type[str], Type[float], Type[int], Type[complex], Type[bool],
520+
# Type[object]]]"
513521
return self.array.to_numpy( # type: ignore[call-arg]
514-
dtype, copy=copy, na_value=na_value, **kwargs
522+
dtype, copy=copy, na_value=na_value, **kwargs # type: ignore[arg-type]
515523
)
516524
elif kwargs:
517525
bad_keys = list(kwargs.keys())[0]
518526
raise TypeError(
519527
f"to_numpy() got an unexpected keyword argument '{bad_keys}'"
520528
)
521529

522-
# error: Argument "dtype" to "asarray" has incompatible type
523-
# "Union[ExtensionDtype, str, dtype[Any], Type[str], Type[float], Type[int],
524-
# Type[complex], Type[bool], Type[object], None]"; expected "Union[dtype[Any],
525-
# None, type, _SupportsDType, str, Union[Tuple[Any, int], Tuple[Any, Union[int,
526-
# Sequence[int]]], List[Any], _DTypeDict, Tuple[Any, Any]]]"
527-
result = np.asarray(self._values, dtype=dtype) # type: ignore[arg-type]
530+
result = np.asarray(self._values, dtype=dtype)
528531
# TODO(GH-24345): Avoid potential double copy
529532
if copy or na_value is not lib.no_default:
530533
result = result.copy()
@@ -1091,6 +1094,7 @@ def _memory_usage(self, deep: bool = False) -> int:
10911094
are not components of the array if deep=False or if used on PyPy
10921095
"""
10931096
if hasattr(self.array, "memory_usage"):
1097+
# https://github.com/python/mypy/issues/1424
10941098
# error: "ExtensionArray" has no attribute "memory_usage"
10951099
return self.array.memory_usage(deep=deep) # type: ignore[attr-defined]
10961100

pandas/core/frame.py

+1
Original file line numberDiff line numberDiff line change
@@ -7614,6 +7614,7 @@ def groupby(
76147614
raise TypeError("You have to supply one of 'by' and 'level'")
76157615
axis = self._get_axis_number(axis)
76167616

7617+
# https://github.com/python/mypy/issues/7642
76177618
# error: Argument "squeeze" to "DataFrameGroupBy" has incompatible type
76187619
# "Union[bool, NoDefault]"; expected "bool"
76197620
return DataFrameGroupBy(

0 commit comments

Comments
 (0)