diff --git a/pandas/conftest.py b/pandas/conftest.py index 07a20d9e0eb5c..688ad6dcc5e48 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -326,6 +326,7 @@ def frame_or_series(request): return request.param +# error: List item 0 has incompatible type "Type[Index]"; expected "Type[IndexOpsMixin]" @pytest.fixture( params=[pd.Index, pd.Series], ids=["index", "series"] # type: ignore[list-item] ) diff --git a/pandas/core/arrays/boolean.py b/pandas/core/arrays/boolean.py index 260cd08707473..b37cf0a0ec579 100644 --- a/pandas/core/arrays/boolean.py +++ b/pandas/core/arrays/boolean.py @@ -76,7 +76,8 @@ class BooleanDtype(BaseMaskedDtype): name = "boolean" - # mypy: https://github.com/python/mypy/issues/4125 + # https://github.com/python/mypy/issues/4125 + # error: Signature of "type" incompatible with supertype "BaseMaskedDtype" @property def type(self) -> Type: # type: ignore[override] return np.bool_ diff --git a/pandas/core/arrays/floating.py b/pandas/core/arrays/floating.py index a43b30f5043e2..aace5583ff47a 100644 --- a/pandas/core/arrays/floating.py +++ b/pandas/core/arrays/floating.py @@ -78,7 +78,10 @@ def _get_common_dtype(self, dtypes: List[DtypeObj]) -> Optional[DtypeObj]: if not all(isinstance(t, FloatingDtype) for t in dtypes): return None np_dtype = np.find_common_type( - [t.numpy_dtype for t in dtypes], [] # type: ignore[union-attr] + # error: Item "ExtensionDtype" of "Union[Any, ExtensionDtype]" has no + # attribute "numpy_dtype" + [t.numpy_dtype for t in dtypes], # type: ignore[union-attr] + [], ) if np.issubdtype(np_dtype, np.floating): return FLOAT_STR_TO_DTYPE[str(np_dtype)] diff --git a/pandas/core/common.py b/pandas/core/common.py index 871f5ac651cce..0b2dec371bf02 100644 --- a/pandas/core/common.py +++ b/pandas/core/common.py @@ -493,7 +493,12 @@ def convert_to_list_like( inputs are returned unmodified whereas others are converted to list. """ if isinstance(values, (list, np.ndarray, ABCIndex, ABCSeries, ABCExtensionArray)): - # np.ndarray resolving as Any gives a false positive + # error: Incompatible return value type (got "Union[Any, List[Any], Index, + # Series, ExtensionArray]", expected "Union[List[Any], ExtensionArray]") + # error: Incompatible return value type (got "Union[Any, List[Any], Index, + # Series, ExtensionArray]", expected "Union[List[Any], Index]") + # error: Incompatible return value type (got "Union[Any, List[Any], Index, + # Series, ExtensionArray]", expected "Union[List[Any], Series]") return values # type: ignore[return-value] elif isinstance(values, abc.Iterable) and not isinstance(values, str): return list(values) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 911d6fbfadd5d..38cd730efabd1 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -4079,7 +4079,13 @@ def extract_unique_dtypes_from_dtypes_set( for unique_dtype in unique_dtypes if ( issubclass( - unique_dtype.type, tuple(dtypes_set) # type: ignore[arg-type] + # error: Argument 1 to "tuple" has incompatible type + # "FrozenSet[Union[ExtensionDtype, Union[str, Any], Type[str], + # Type[float], Type[int], Type[complex], Type[bool], + # Type[object]]]"; expected "Iterable[Union[type, Tuple[Any, + # ...]]]" + unique_dtype.type, + tuple(dtypes_set), # type: ignore[arg-type] ) or ( np.number in dtypes_set @@ -6382,7 +6388,14 @@ def _dispatch_frame_op(self, right, func, axis: Optional[int] = None): # TODO operate_blockwise expects a manager of the same type bm = self._mgr.operate_blockwise( - right._mgr, array_op # type: ignore[arg-type] + # error: Argument 1 to "operate_blockwise" of "ArrayManager" has + # incompatible type "Union[ArrayManager, BlockManager]"; expected + # "ArrayManager" + # error: Argument 1 to "operate_blockwise" of "BlockManager" has + # incompatible type "Union[ArrayManager, BlockManager]"; expected + # "BlockManager" + right._mgr, # type: ignore[arg-type] + array_op, ) return type(self)(bm) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index e103f0e938a76..327a69e7f3fb4 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -752,7 +752,12 @@ def swapaxes(self: FrameOrSeries, axis1, axis2, copy=True) -> FrameOrSeries: # ignore needed because of NDFrame constructor is different than # DataFrame/Series constructors. return self._constructor( - new_values, *new_axes # type: ignore[arg-type] + # error: Argument 2 to "NDFrame" has incompatible type "*Generator[Index, + # None, None]"; expected "bool" [arg-type] + # error: Argument 2 to "NDFrame" has incompatible type "*Generator[Index, + # None, None]"; expected "Optional[Mapping[Optional[Hashable], Any]]" + new_values, + *new_axes, # type: ignore[arg-type] ).__finalize__(self, method="swapaxes") @final @@ -11046,37 +11051,47 @@ def _inplace_method(self, other, op): return self def __iadd__(self, other): + # error: Unsupported left operand type for + ("Type[NDFrame]") return self._inplace_method(other, type(self).__add__) # type: ignore[operator] def __isub__(self, other): + # error: Unsupported left operand type for - ("Type[NDFrame]") return self._inplace_method(other, type(self).__sub__) # type: ignore[operator] def __imul__(self, other): + # error: Unsupported left operand type for * ("Type[NDFrame]") return self._inplace_method(other, type(self).__mul__) # type: ignore[operator] def __itruediv__(self, other): + # error: Unsupported left operand type for / ("Type[NDFrame]") return self._inplace_method( other, type(self).__truediv__ # type: ignore[operator] ) def __ifloordiv__(self, other): + # error: Unsupported left operand type for // ("Type[NDFrame]") return self._inplace_method( other, type(self).__floordiv__ # type: ignore[operator] ) def __imod__(self, other): + # error: Unsupported left operand type for % ("Type[NDFrame]") return self._inplace_method(other, type(self).__mod__) # type: ignore[operator] def __ipow__(self, other): + # error: Unsupported left operand type for ** ("Type[NDFrame]") return self._inplace_method(other, type(self).__pow__) # type: ignore[operator] def __iand__(self, other): + # error: Unsupported left operand type for & ("Type[NDFrame]") return self._inplace_method(other, type(self).__and__) # type: ignore[operator] def __ior__(self, other): + # error: Unsupported left operand type for | ("Type[NDFrame]") return self._inplace_method(other, type(self).__or__) # type: ignore[operator] def __ixor__(self, other): + # error: Unsupported left operand type for ^ ("Type[NDFrame]") return self._inplace_method(other, type(self).__xor__) # type: ignore[operator] # ---------------------------------------------------------------------- diff --git a/pandas/core/internals/array_manager.py b/pandas/core/internals/array_manager.py index 905fa448ff033..97a2d4037bf26 100644 --- a/pandas/core/internals/array_manager.py +++ b/pandas/core/internals/array_manager.py @@ -148,6 +148,7 @@ def items(self) -> Index: return self._axes[-1] @property + # error: Signature of "axes" incompatible with supertype "DataManager" def axes(self) -> List[Index]: # type: ignore[override] # mypy doesn't work to override attribute with property # see https://github.com/python/mypy/issues/4125 @@ -454,11 +455,19 @@ def apply_with_block(self: T, f, align_keys=None, swap_axis=True, **kwargs) -> T if obj.ndim == 2: kwargs[k] = obj[[i]] + # error: Item "ExtensionArray" of "Union[Any, ExtensionArray]" has no + # attribute "tz" if hasattr(arr, "tz") and arr.tz is None: # type: ignore[union-attr] # DatetimeArray needs to be converted to ndarray for DatetimeBlock + + # error: Item "ExtensionArray" of "Union[Any, ExtensionArray]" has no + # attribute "_data" arr = arr._data # type: ignore[union-attr] elif arr.dtype.kind == "m" and not isinstance(arr, np.ndarray): # TimedeltaArray needs to be converted to ndarray for TimedeltaBlock + + # error: Item "ExtensionArray" of "Union[Any, ExtensionArray]" has no + # attribute "_data" arr = arr._data # type: ignore[union-attr] if self.ndim == 2: diff --git a/pandas/core/nanops.py b/pandas/core/nanops.py index 247d068aaca8f..d5d04ea2b1539 100644 --- a/pandas/core/nanops.py +++ b/pandas/core/nanops.py @@ -1748,6 +1748,7 @@ def na_accum_func(values: ArrayLike, accum_func, *, skipna: bool) -> ArrayLike: # TODO: have this case go through a DTA method? # For DatetimeTZDtype, view result as M8[ns] npdtype = orig_dtype if isinstance(orig_dtype, np.dtype) else "M8[ns]" + # error: "Type[ExtensionArray]" has no attribute "_simple_new" result = type(values)._simple_new( # type: ignore[attr-defined] result.view(npdtype), dtype=orig_dtype ) diff --git a/pandas/core/series.py b/pandas/core/series.py index e1a6c6884e003..25b46d2cbd278 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1094,6 +1094,9 @@ def _set_labels(self, key, value): def _set_values(self, key, value): if isinstance(key, Series): key = key._values + # error: Incompatible types in assignment (expression has type "Union[Any, + # BlockManager]", variable has type "Union[SingleArrayManager, + # SingleBlockManager]") self._mgr = self._mgr.setitem( # type: ignore[assignment] indexer=key, value=value ) diff --git a/pandas/io/common.py b/pandas/io/common.py index e5da12d7b1753..cf3b92ec93b1f 100644 --- a/pandas/io/common.py +++ b/pandas/io/common.py @@ -625,6 +625,9 @@ def get_handle( ) else: handle = gzip.GzipFile( + # error: Argument "fileobj" to "GzipFile" has incompatible type + # "Union[str, Union[IO[Any], RawIOBase, BufferedIOBase, TextIOBase, + # TextIOWrapper, mmap]]"; expected "Optional[IO[bytes]]" fileobj=handle, # type: ignore[arg-type] mode=ioargs.mode, **compression_args, @@ -633,6 +636,10 @@ def get_handle( # BZ Compression elif compression == "bz2": handle = bz2.BZ2File( + # Argument 1 to "BZ2File" has incompatible type "Union[str, + # Union[IO[Any], RawIOBase, BufferedIOBase, TextIOBase, TextIOWrapper, + # mmap]]"; expected "Union[Union[str, bytes, _PathLike[str], + # _PathLike[bytes]], IO[bytes]]" handle, # type: ignore[arg-type] mode=ioargs.mode, **compression_args, @@ -690,6 +697,9 @@ def get_handle( is_wrapped = False if is_text and (compression or _is_binary_mode(handle, ioargs.mode)): handle = TextIOWrapper( + # error: Argument 1 to "TextIOWrapper" has incompatible type + # "Union[IO[bytes], IO[Any], RawIOBase, BufferedIOBase, TextIOBase, mmap]"; + # expected "IO[bytes]" handle, # type: ignore[arg-type] encoding=ioargs.encoding, errors=errors, @@ -752,6 +762,10 @@ def __init__( kwargs_zip: Dict[str, Any] = {"compression": zipfile.ZIP_DEFLATED} kwargs_zip.update(kwargs) + # error: Argument 1 to "__init__" of "ZipFile" has incompatible type + # "Union[_PathLike[str], Union[str, Union[IO[Any], RawIOBase, BufferedIOBase, + # TextIOBase, TextIOWrapper, mmap]]]"; expected "Union[Union[str, + # _PathLike[str]], IO[bytes]]" super().__init__(file, mode, **kwargs_zip) # type: ignore[arg-type] def write(self, data): @@ -849,6 +863,8 @@ def _maybe_memory_map( handles.append(handle) try: + # error: Argument 1 to "_MMapWrapper" has incompatible type "Union[IO[Any], + # RawIOBase, BufferedIOBase, TextIOBase, mmap]"; expected "IO[Any]" wrapped = cast(mmap.mmap, _MMapWrapper(handle)) # type: ignore[arg-type] handle.close() handles.remove(handle) diff --git a/pandas/io/pickle.py b/pandas/io/pickle.py index 785afce9e0214..6a91c12ee286e 100644 --- a/pandas/io/pickle.py +++ b/pandas/io/pickle.py @@ -104,12 +104,19 @@ def to_pickle( # "zip" would also be here if pandas.io.common._BytesZipFile # wouldn't buffer write calls handles.handle.write( + # error: Argument 1 to "write" of "TextIOBase" has incompatible type + # "bytes"; expected "str" pickle.dumps(obj, protocol=protocol) # type: ignore[arg-type] ) else: # letting pickle write directly to the buffer is more memory-efficient pickle.dump( - obj, handles.handle, protocol=protocol # type: ignore[arg-type] + # error: Argument 2 to "dump" has incompatible type "Union[IO[Any], + # RawIOBase, BufferedIOBase, TextIOBase, TextIOWrapper, mmap]"; expected + # "IO[bytes]" + obj, + handles.handle, # type: ignore[arg-type] + protocol=protocol, ) @@ -204,6 +211,9 @@ def read_pickle( with warnings.catch_warnings(record=True): # We want to silence any warnings about, e.g. moved modules. warnings.simplefilter("ignore", Warning) + # error: Argument 1 to "load" has incompatible type "Union[IO[Any], + # RawIOBase, BufferedIOBase, TextIOBase, TextIOWrapper, mmap]"; + # expected "IO[bytes]" return pickle.load(handles.handle) # type: ignore[arg-type] except excs_to_catch: # e.g. diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 25cabbb7c61b9..ceb4900b887f1 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -4022,10 +4022,14 @@ def get_blk_items(mgr): new_labels = Index(axis_labels).difference(Index(data_columns)) mgr = frame.reindex(new_labels, axis=axis)._mgr + # error: Item "ArrayManager" of "Union[ArrayManager, BlockManager]" has no + # attribute "blocks" blocks = list(mgr.blocks) # type: ignore[union-attr] blk_items = get_blk_items(mgr) for c in data_columns: mgr = frame.reindex([c], axis=axis)._mgr + # error: Item "ArrayManager" of "Union[ArrayManager, BlockManager]" has + # no attribute "blocks" blocks.extend(mgr.blocks) # type: ignore[union-attr] blk_items.extend(get_blk_items(mgr)) diff --git a/pandas/io/stata.py b/pandas/io/stata.py index 462c7b41f4271..ebc0395aec0b2 100644 --- a/pandas/io/stata.py +++ b/pandas/io/stata.py @@ -1091,6 +1091,9 @@ def __init__( compression=compression, ) as handles: # Copy to BytesIO, and ensure no encoding + + # Argument 1 to "BytesIO" has incompatible type "Union[Any, bytes, None, + # str]"; expected "bytes" self.path_or_buf = BytesIO(handles.handle.read()) # type: ignore[arg-type] self._read_header()