Skip to content

Commit 32f1780

Browse files
add error codes
1 parent 67890ef commit 32f1780

31 files changed

+104
-58
lines changed

pandas/compat/pickle_compat.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class _LoadSparseSeries:
7272
# https://github.com/python/mypy/issues/1020
7373
# error: Incompatible return type for "__new__" (returns "Series", but must return
7474
# a subtype of "_LoadSparseSeries")
75-
def __new__(cls) -> "Series": # type: ignore
75+
def __new__(cls) -> "Series": # type: ignore[misc]
7676
from pandas import Series
7777

7878
warnings.warn(
@@ -90,7 +90,7 @@ class _LoadSparseFrame:
9090
# https://github.com/python/mypy/issues/1020
9191
# error: Incompatible return type for "__new__" (returns "DataFrame", but must
9292
# return a subtype of "_LoadSparseFrame")
93-
def __new__(cls) -> "DataFrame": # type: ignore
93+
def __new__(cls) -> "DataFrame": # type: ignore[misc]
9494
from pandas import DataFrame
9595

9696
warnings.warn(
@@ -202,7 +202,7 @@ def __new__(cls) -> "DataFrame": # type: ignore
202202
# functions for compat and uses a non-public class of the pickle module.
203203

204204
# error: Name 'pkl._Unpickler' is not defined
205-
class Unpickler(pkl._Unpickler): # type: ignore
205+
class Unpickler(pkl._Unpickler): # type: ignore[name-defined]
206206
def find_class(self, module, name):
207207
# override superclass
208208
key = (module, name)

pandas/core/arrays/interval.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ def mid(self):
992992
"""
993993
# https://github.com/python/mypy/issues/1362
994994
# Mypy does not support decorated properties
995-
@property # type: ignore
995+
@property # type: ignore[misc]
996996
@Appender(
997997
_interval_shared_docs["is_non_overlapping_monotonic"] % _shared_docs_kwargs
998998
)

pandas/core/arrays/period.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,8 @@ def _check_compatible_with(self, other):
328328
def dtype(self):
329329
return self._dtype
330330

331-
# read-only property overwriting read/write
332-
@property # type: ignore
331+
# error: Read-only property cannot override read-write property [misc]
332+
@property # type: ignore[misc]
333333
def freq(self):
334334
"""
335335
Return the frequency object for this PeriodArray.

pandas/core/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ def array(self) -> ExtensionArray:
871871
# As a mixin, we depend on the mixing class having _values.
872872
# Special mixin syntax may be developed in the future:
873873
# https://github.com/python/typing/issues/246
874-
result = self._values # type: ignore
874+
result = self._values # type: ignore[attr-defined]
875875

876876
if is_datetime64_ns_dtype(result.dtype):
877877
from pandas.arrays import DatetimeArray
@@ -1000,7 +1000,7 @@ def _ndarray_values(self) -> np.ndarray:
10001000
# As a mixin, we depend on the mixing class having values.
10011001
# Special mixin syntax may be developed in the future:
10021002
# https://github.com/python/typing/issues/246
1003-
return self.values # type: ignore
1003+
return self.values # type: ignore[attr-defined]
10041004

10051005
@property
10061006
def empty(self):

pandas/core/computation/pytables.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def _resolve_name(self):
5050
except UndefinedVariableError:
5151
return self.name
5252

53-
# read-only property overwriting read/write property
54-
@property # type: ignore
53+
# error: Read-only property cannot override read-write property [misc]
54+
@property # type: ignore[misc]
5555
def value(self):
5656
return self._value
5757

pandas/core/config_init.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def is_terminal() -> bool:
308308
"""
309309
try:
310310
# error: Name 'get_ipython' is not defined
311-
ip = get_ipython() # type: ignore
311+
ip = get_ipython() # type: ignore[name-defined]
312312
except NameError: # assume standard Python interpreter in a terminal
313313
return True
314314
else:

pandas/core/dtypes/cast.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ def try_datetime(v):
962962
values, tz = conversion.datetime_to_datetime64(v)
963963
# error: "DatetimeIndex" has no attribute "tz_localize"
964964
return (
965-
DatetimeIndex(values) # type: ignore
965+
DatetimeIndex(values) # type: ignore[attr-defined]
966966
.tz_localize("UTC")
967967
.tz_convert(tz=tz)
968968
)

pandas/core/dtypes/common.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,13 @@ def ensure_int_or_float(arr: ArrayLike, copy: bool = False) -> np.array:
169169
"""
170170
# TODO: GH27506 potential bug with ExtensionArrays
171171
try:
172-
return arr.astype("int64", copy=copy, casting="safe") # type: ignore
172+
# error: Unexpected keyword argument "casting" for "astype"
173+
return arr.astype("int64", copy=copy, casting="safe") # type: ignore[call-arg]
173174
except TypeError:
174175
pass
175176
try:
176-
return arr.astype("uint64", copy=copy, casting="safe") # type: ignore
177+
# error: Unexpected keyword argument "casting" for "astype"
178+
return arr.astype("uint64", copy=copy, casting="safe") # type: ignore[call-arg]
177179
except TypeError:
178180
return arr.astype("float64", copy=copy)
179181

pandas/core/dtypes/generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# objects
66
def create_pandas_abc_type(name, attr, comp):
77
# error: 'classmethod' used with a non-method
8-
@classmethod # type: ignore
8+
@classmethod # type: ignore[misc]
99
def _check(cls, inst):
1010
return getattr(inst, attr, "_typ") in comp
1111

pandas/core/frame.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -3430,10 +3430,15 @@ def select_dtypes(self, include=None, exclude=None):
34303430
def extract_unique_dtypes_from_dtypes_set(
34313431
dtypes_set: FrozenSet[Dtype], unique_dtypes: np.ndarray
34323432
) -> List[Dtype]:
3433+
# error: Argument 1 to "tuple" has incompatible type
3434+
# "FrozenSet[Union[str, Any, ExtensionDtype]]";
3435+
# expected "Iterable[Union[type, Tuple[Any, ...]]]"
34333436
extracted_dtypes = [
34343437
unique_dtype
34353438
for unique_dtype in unique_dtypes
3436-
if issubclass(unique_dtype.type, tuple(dtypes_set)) # type: ignore
3439+
if issubclass(
3440+
unique_dtype.type, tuple(dtypes_set) # type: ignore[arg-type]
3441+
)
34373442
]
34383443
return extracted_dtypes
34393444

pandas/core/groupby/ops.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def get_func(fname):
440440
# https://github.com/python/mypy/issues/2608
441441
# error: "None" not callable
442442
def wrapper(*args, **kwargs):
443-
return f(afunc, *args, **kwargs) # type: ignore
443+
return f(afunc, *args, **kwargs) # type: ignore[misc]
444444

445445
# need to curry our sub-function
446446
func = wrapper

pandas/core/indexes/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ def astype(self, dtype, copy=True):
760760
tz = pandas_dtype(dtype).tz
761761
# error: "DatetimeIndex" has no attribute "tz_localize"
762762
return (
763-
DatetimeIndex(np.asarray(self)) # type: ignore
763+
DatetimeIndex(np.asarray(self)) # type: ignore[attr-defined]
764764
.tz_localize("UTC")
765765
.tz_convert(tz)
766766
)

pandas/core/indexes/datetimelike.py

+15-7
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,21 @@ class DatetimeIndexOpsMixin(ExtensionOpsMixin, _Base):
9090
# properties there. They can be made into cache_readonly for Index
9191
# subclasses bc they are immutable
9292
inferred_freq = cache_readonly(
93-
DatetimeLikeArrayMixin.inferred_freq.fget # type: ignore
93+
DatetimeLikeArrayMixin.inferred_freq.fget # type: ignore[attr-defined]
94+
)
95+
_isnan = cache_readonly(
96+
DatetimeLikeArrayMixin._isnan.fget # type: ignore[attr-defined]
97+
)
98+
hasnans = cache_readonly(
99+
DatetimeLikeArrayMixin._hasnans.fget # type: ignore[attr-defined]
94100
)
95-
_isnan = cache_readonly(DatetimeLikeArrayMixin._isnan.fget) # type: ignore
96-
hasnans = cache_readonly(DatetimeLikeArrayMixin._hasnans.fget) # type: ignore
97101
_hasnans = hasnans # for index / array -agnostic code
98102
_resolution = cache_readonly(
99-
DatetimeLikeArrayMixin._resolution.fget # type: ignore
103+
DatetimeLikeArrayMixin._resolution.fget # type: ignore[attr-defined]
104+
)
105+
resolution = cache_readonly(
106+
DatetimeLikeArrayMixin.resolution.fget # type: ignore[attr-defined]
100107
)
101-
resolution = cache_readonly(DatetimeLikeArrayMixin.resolution.fget) # type: ignore
102108

103109
_maybe_mask_results = ea_passthrough(DatetimeLikeArrayMixin._maybe_mask_results)
104110
__iter__ = ea_passthrough(DatetimeLikeArrayMixin.__iter__)
@@ -165,7 +171,9 @@ def values(self):
165171
# Note: PeriodArray overrides this to return an ndarray of objects.
166172
return self._data._data
167173

168-
@property # type: ignore # https://github.com/python/mypy/issues/1362
174+
# https://github.com/python/mypy/issues/1362
175+
# error: Decorated property not supported [misc]
176+
@property # type: ignore[misc]
169177
@Appender(DatetimeLikeArrayMixin.asi8.__doc__)
170178
def asi8(self):
171179
return self._data.asi8
@@ -226,7 +234,7 @@ def _join_i8_wrapper(joinf, dtype, with_indexers=True):
226234

227235
# https://github.com/python/mypy/issues/1006
228236
# error: 'staticmethod' used with a non-method
229-
@staticmethod # type: ignore
237+
@staticmethod # type: ignore[misc]
230238
def wrapper(left, right):
231239
if isinstance(
232240
left, (np.ndarray, ABCIndex, ABCSeries, DatetimeLikeArrayMixin)

pandas/core/indexes/datetimes.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -1172,9 +1172,15 @@ def slice_indexer(self, start=None, end=None, step=None, kind=None):
11721172
_is_monotonic_decreasing = Index.is_monotonic_decreasing
11731173
_is_unique = Index.is_unique
11741174

1175-
_timezone = cache_readonly(DatetimeArray._timezone.fget) # type: ignore
1176-
is_normalized = cache_readonly(DatetimeArray.is_normalized.fget) # type: ignore
1177-
_resolution = cache_readonly(DatetimeArray._resolution.fget) # type: ignore
1175+
_timezone = cache_readonly(
1176+
DatetimeArray._timezone.fget # type: ignore[attr-defined]
1177+
)
1178+
is_normalized = cache_readonly(
1179+
DatetimeArray.is_normalized.fget # type: ignore[attr-defined]
1180+
)
1181+
_resolution = cache_readonly(
1182+
DatetimeArray._resolution.fget # type: ignore[attr-defined]
1183+
)
11781184

11791185
_has_same_tz = ea_passthrough(DatetimeArray._has_same_tz)
11801186

pandas/core/indexing.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1751,7 +1751,8 @@ def _get_partial_string_timestamp_match_key(self, key, labels):
17511751
# https://github.com/python/mypy/issues/5492
17521752
# error: List item 0 has incompatible type "slice"; expected "str"
17531753
[key]
1754-
+ [slice(None)] * (len(labels.levels) - 1) # type: ignore
1754+
+ [slice(None)] # type: ignore[list-item]
1755+
* (len(labels.levels) - 1)
17551756
)
17561757

17571758
if isinstance(key, tuple):

pandas/core/ops/array_ops.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,6 @@ def fill_bool(x, left=None):
377377
res_values = na_logical_op(lvalues, rvalues, op)
378378
# https://github.com/python/mypy/issues/5128
379379
# error: Cannot call function of unknown type
380-
res_values = filler(res_values) # type: ignore
380+
res_values = filler(res_values) # type: ignore[operator]
381381

382382
return res_values

pandas/core/resample.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def _wrap_result(self, result):
411411
obj = self.obj
412412
if isinstance(obj.index, PeriodIndex):
413413
# error: "PeriodIndex" has no attribute "asfreq"
414-
result.index = obj.index.asfreq(self.freq) # type: ignore
414+
result.index = obj.index.asfreq(self.freq) # type: ignore[attr-defined]
415415
else:
416416
result.index = obj.index._shallow_copy(freq=self.freq)
417417
result.name = getattr(obj, "name", None)
@@ -1580,7 +1580,7 @@ def _get_period_bins(self, ax):
15801580
)
15811581

15821582
# error: "PeriodIndex" has no attribute "asfreq"
1583-
memb = ax.asfreq(self.freq, how=self.convention) # type: ignore
1583+
memb = ax.asfreq(self.freq, how=self.convention) # type: ignore[attr-defined]
15841584

15851585
# NaT handling as in pandas._lib.lib.generate_bins_dt64()
15861586
nat_count = 0
@@ -1819,7 +1819,7 @@ def asfreq(obj, freq, method=None, how=None, normalize=False, fill_value=None):
18191819

18201820
new_obj = obj.copy()
18211821
# error: "PeriodIndex" has no attribute "asfreq"
1822-
new_obj.index = obj.index.asfreq(freq, how=how) # type: ignore
1822+
new_obj.index = obj.index.asfreq(freq, how=how) # type: ignore[attr-defined]
18231823

18241824
elif len(obj.index) == 0:
18251825
new_obj = obj.copy()

pandas/core/window/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(self, obj, *args, **kwargs):
4141
self._groupby.grouper.mutated = True
4242
# https://github.com/python/mypy/issues/5887
4343
# error: Too many arguments for "__init__" of "object"
44-
super().__init__(obj, *args, **kwargs) # type: ignore
44+
super().__init__(obj, *args, **kwargs) # type: ignore[call-arg]
4545

4646
count = GroupByMixin._dispatch("count")
4747
corr = GroupByMixin._dispatch("corr", other=None, pairwise=None)

pandas/core/window/rolling.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ def _apply(
455455
def calc(x):
456456
# https://github.com/python/mypy/issues/2608
457457
# error: "str" not callable
458-
return func( # type: ignore
458+
return func( # type: ignore[operator]
459459
np.concatenate((x, additional_nans)),
460460
window,
461461
min_periods=self.min_periods,
@@ -467,7 +467,7 @@ def calc(x):
467467
def calc(x):
468468
# https://github.com/python/mypy/issues/2608
469469
# error: "str" not callable
470-
return func( # type: ignore
470+
return func( # type: ignore[operator]
471471
x, window, min_periods=self.min_periods, closed=self.closed
472472
)
473473

pandas/io/common.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ def _stringify_path(
163163
"""
164164
if hasattr(filepath_or_buffer, "__fspath__"):
165165
# https://github.com/python/mypy/issues/1424
166-
return filepath_or_buffer.__fspath__() # type: ignore
166+
# error: Item "str" of "Union[str, Path, IO[str]]" has no attribute "__fspath__"
167+
return filepath_or_buffer.__fspath__() # type: ignore[union-attr]
167168
elif isinstance(filepath_or_buffer, pathlib.Path):
168169
return str(filepath_or_buffer)
169170
return _expand_user(filepath_or_buffer)
@@ -411,12 +412,13 @@ def _get_handle(
411412
handles : list of file-like objects
412413
A list of file-like object that were opened in this function.
413414
"""
415+
need_text_wrapping: Union[Type, Tuple[Type, ...]]
414416
try:
415417
from s3fs import S3File
416418

417419
need_text_wrapping = (BufferedIOBase, S3File)
418420
except ImportError:
419-
need_text_wrapping = BufferedIOBase # type: ignore
421+
need_text_wrapping = BufferedIOBase
420422

421423
handles = list() # type: List[IO]
422424
f = path_or_buf
@@ -513,7 +515,19 @@ def _get_handle(
513515
return f, handles
514516

515517

516-
class BytesZipFile(zipfile.ZipFile, BytesIO): # type: ignore
518+
# error: Definition of "__enter__" in base class "ZipFile" is incompatible with
519+
# definition in base class "BytesIO" [misc]
520+
# error: Definition of "__enter__" in base class "ZipFile" is incompatible with
521+
# definition in base class "BinaryIO" [misc]
522+
# error: Definition of "__enter__" in base class "ZipFile" is incompatible with
523+
# definition in base class "IO" [misc]
524+
# error: Definition of "read" in base class "ZipFile" is incompatible with
525+
# definition in base class "BytesIO" [misc]
526+
# error: Definition of "read" in base class "ZipFile" is incompatible with
527+
# definition in base class "IO" [misc]
528+
# error: Definition of "__exit__" in base class "ZipFile" is incompatible with
529+
# definition in base class "BytesIO" [misc]
530+
class BytesZipFile(zipfile.ZipFile, BytesIO): # type: ignore[misc]
517531
"""
518532
Wrapper for standard library class ZipFile and allow the returned file-like
519533
handle to accept byte strings via `write` method.

pandas/io/formats/console.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def check_main():
6666

6767
try:
6868
# error: Name '__IPYTHON__' is not defined
69-
return __IPYTHON__ or check_main() # type: ignore # noqa
69+
return __IPYTHON__ or check_main() # type: ignore[name-defined] # noqa
7070
except NameError:
7171
return check_main()
7272

@@ -77,7 +77,7 @@ def in_ipython_frontend():
7777
"""
7878
try:
7979
# error: Name 'get_ipython' is not defined
80-
ip = get_ipython() # type: ignore # noqa
80+
ip = get_ipython() # type: ignore[name-defined] # noqa
8181
return "zmq" in str(type(ip)).lower()
8282
except NameError:
8383
pass

pandas/io/formats/css.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def _error():
162162

163163
try:
164164
# error: Item "None" of "Optional[Match[Any]]" has no attribute "groups"
165-
val, unit = re.match( # type: ignore
165+
val, unit = re.match( # type: ignore[union-attr]
166166
r"^(\S*?)([a-zA-Z%!].*)", in_val
167167
).groups()
168168
except AttributeError:

pandas/io/formats/format.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,9 @@ def base_formatter(v):
12811281
# "EngFormatter"
12821282
# error: "None" not callable
12831283
return (
1284-
float_format(value=v) if notna(v) else self.na_rep # type: ignore
1284+
float_format(value=v) # type: ignore[operator, call-arg, misc]
1285+
if notna(v)
1286+
else self.na_rep
12851287
)
12861288

12871289
else:
@@ -1725,9 +1727,9 @@ def _make_fixed_width(
17251727

17261728
def just(x):
17271729
if conf_max is not None:
1728-
# error: Item "None" of "Optional[TextAdjustment]" has no attribute "len"
17291730
# https://github.com/python/mypy/issues/2608
1730-
if (conf_max > 3) & (adj.len(x) > max_len): # type: ignore
1731+
# error: Item "None" of "Optional[TextAdjustment]" has no attribute "len"
1732+
if (conf_max > 3) & (adj.len(x) > max_len): # type: ignore[union-attr]
17311733
x = x[: max_len - 3] + "..."
17321734
return x
17331735

pandas/io/formats/html.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ def _get_columns_formatted_values(self) -> Iterable:
8484
return self.columns
8585

8686
# https://github.com/python/mypy/issues/1237
87+
# error: Signature of "is_truncated" incompatible with supertype "TableFormatter"
8788
@property
88-
def is_truncated(self) -> bool: # type: ignore
89+
def is_truncated(self) -> bool: # type: ignore[override]
8990
return self.fmt.is_truncated
9091

9192
@property

0 commit comments

Comments
 (0)