From f26c78a5618ecf9aa073546c05bfa5d83c4fa453 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Wed, 22 Jun 2022 12:39:40 -0700 Subject: [PATCH 1/2] TYP: Fix typing errors on main --- pandas/core/algorithms.py | 8 +++++++- pandas/core/array_algos/quantile.py | 10 ++++++++-- pandas/core/arraylike.py | 3 +-- pandas/core/arrays/arrow/array.py | 10 +++++++++- pandas/core/arrays/datetimes.py | 5 +---- pandas/core/arrays/interval.py | 25 +++++++++---------------- pandas/core/arrays/masked.py | 22 +++++++++++++--------- pandas/core/arrays/sparse/array.py | 19 ++++++++++++++++--- pandas/core/dtypes/astype.py | 8 ++------ pandas/core/dtypes/common.py | 4 +--- pandas/core/exchange/buffer.py | 3 +-- pandas/core/frame.py | 4 +++- pandas/core/indexes/base.py | 17 ++++++++++++++--- pandas/core/indexes/multi.py | 8 +++++++- pandas/core/internals/ops.py | 4 +--- pandas/core/missing.py | 22 +++++++++++++++++++--- pandas/core/reshape/melt.py | 4 +++- pandas/core/series.py | 4 +++- pandas/core/window/rolling.py | 5 +---- pandas/io/formats/style.py | 18 ++---------------- pandas/io/parsers/c_parser_wrapper.py | 10 +++++++++- pandas/tests/extension/date/array.py | 4 +++- 22 files changed, 133 insertions(+), 84 deletions(-) diff --git a/pandas/core/algorithms.py b/pandas/core/algorithms.py index 72f6a7bce4d0e..7f9d77c4193ca 100644 --- a/pandas/core/algorithms.py +++ b/pandas/core/algorithms.py @@ -1064,7 +1064,13 @@ def checked_add_with_arr( elif arr_mask is not None: not_nan = np.logical_not(arr_mask) elif b_mask is not None: - not_nan = np.logical_not(b2_mask) + # error: Argument 1 to "__call__" of "_UFunc_Nin1_Nout1" has + # incompatible type "Optional[ndarray[Any, dtype[bool_]]]"; + # expected "Union[_SupportsArray[dtype[Any]], _NestedSequence + # [_SupportsArray[dtype[Any]]], bool, int, float, complex, str + # , bytes, _NestedSequence[Union[bool, int, float, complex, str + # , bytes]]]" + not_nan = np.logical_not(b2_mask) # type: ignore[arg-type] else: not_nan = np.empty(arr.shape, dtype=bool) not_nan.fill(True) diff --git a/pandas/core/array_algos/quantile.py b/pandas/core/array_algos/quantile.py index de7945a96c69e..217fbafce719c 100644 --- a/pandas/core/array_algos/quantile.py +++ b/pandas/core/array_algos/quantile.py @@ -143,7 +143,10 @@ def _nanpercentile_1d( return np.percentile( values, qs, - **{np_percentile_argname: interpolation}, + # error: No overload variant of "percentile" matches argument + # types "ndarray[Any, Any]", "ndarray[Any, dtype[floating[_64Bit]]]" + # , "Dict[str, str]" [call-overload] + **{np_percentile_argname: interpolation}, # type: ignore[call-overload] ) @@ -212,5 +215,8 @@ def _nanpercentile( values, qs, axis=1, - **{np_percentile_argname: interpolation}, + # error: No overload variant of "percentile" matches argument types + # "ndarray[Any, Any]", "ndarray[Any, dtype[floating[_64Bit]]]", + # "int", "Dict[str, str]" [call-overload] + **{np_percentile_argname: interpolation}, # type: ignore[call-overload] ) diff --git a/pandas/core/arraylike.py b/pandas/core/arraylike.py index e241fc119ae02..d2875be0f58cd 100644 --- a/pandas/core/arraylike.py +++ b/pandas/core/arraylike.py @@ -265,9 +265,8 @@ def array_ufunc(self, ufunc: np.ufunc, method: str, *inputs: Any, **kwargs: Any) return result # Determine if we should defer. - # error: "Type[ndarray[Any, Any]]" has no attribute "__array_ufunc__" no_defer = ( - np.ndarray.__array_ufunc__, # type: ignore[attr-defined] + np.ndarray.__array_ufunc__, cls.__array_ufunc__, ) diff --git a/pandas/core/arrays/arrow/array.py b/pandas/core/arrays/arrow/array.py index c1380fcdbba06..27d74f2140434 100644 --- a/pandas/core/arrays/arrow/array.py +++ b/pandas/core/arrays/arrow/array.py @@ -496,7 +496,15 @@ def _indexing_key_to_indices( if isinstance(key, slice): indices = np.arange(n)[key] elif is_integer(key): - indices = np.arange(n)[[key]] + # error: Invalid index type "List[Union[int, ndarray[Any, Any]]]" + # for "ndarray[Any, dtype[signedinteger[Any]]]"; expected type + # "Union[SupportsIndex, _SupportsArray[dtype[Union[bool_, + # integer[Any]]]], _NestedSequence[_SupportsArray[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]]]]], _NestedSequence[Union[bool, int]]], ...]]" + indices = np.arange(n)[[key]] # type: ignore[index] elif is_bool_dtype(key): key = np.asarray(key) if len(key) != n: diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 97dae33bc0311..5f060542526d3 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -487,10 +487,7 @@ def _generate_range( np.linspace(0, end.value - start.value, periods, dtype="int64") + start.value ) - # error: Non-overlapping equality check - # (left operand type: "dtype[signedinteger[Any]]", - # right operand type: "Literal['i8']") - if i8values.dtype != "i8": # type: ignore[comparison-overlap] + if i8values.dtype != "i8": # 2022-01-09 I (brock) am not sure if it is possible for this # to overflow and cast to e.g. f8, but if it does we need to cast i8values = i8values.astype("i8") diff --git a/pandas/core/arrays/interval.py b/pandas/core/arrays/interval.py index 69814863afefc..1015a54826ac8 100644 --- a/pandas/core/arrays/interval.py +++ b/pandas/core/arrays/interval.py @@ -687,21 +687,7 @@ def __getitem__( if is_scalar(left) and isna(left): return self._fill_value return Interval(left, right, inclusive=self.inclusive) - # error: Argument 1 to "ndim" has incompatible type - # "Union[ndarray[Any, Any], ExtensionArray]"; expected - # "Union[Sequence[Sequence[Sequence[Sequence[Sequence[Any]]]]], - # Union[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]]]]]]], - # Union[bool, int, float, complex, str, bytes, - # Sequence[Union[bool, int, float, complex, str, bytes]], - # Sequence[Sequence[Union[bool, int, float, complex, str, bytes]]], - # Sequence[Sequence[Sequence[Union[bool, int, float, complex, str, bytes]]]], - # Sequence[Sequence[Sequence[Sequence[Union[bool, int, float, - # complex, str, bytes]]]]]]]]" - if np.ndim(left) > 1: # type: ignore[arg-type] + if np.ndim(left) > 1: # GH#30588 multi-dimensional indexer disallowed raise ValueError("multi-dimensional indexing not allowed") return self._shallow_copy(left, right) @@ -1679,7 +1665,14 @@ def isin(self, values) -> np.ndarray: # complex128 ndarray is much more performant. left = self._combined.view("complex128") right = values._combined.view("complex128") - return np.in1d(left, right) + # error: 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]]]" + return np.in1d(left, right) # type: ignore[arg-type] elif needs_i8_conversion(self.left.dtype) ^ needs_i8_conversion( values.left.dtype diff --git a/pandas/core/arrays/masked.py b/pandas/core/arrays/masked.py index d2c082c472e5e..78c82d9a4e478 100644 --- a/pandas/core/arrays/masked.py +++ b/pandas/core/arrays/masked.py @@ -110,13 +110,7 @@ def __init__( self, values: np.ndarray, mask: npt.NDArray[np.bool_], copy: bool = False ) -> None: # values is supposed to already be validated in the subclass - if not ( - isinstance(mask, np.ndarray) - and - # error: Non-overlapping equality check - # (left operand type: "dtype[bool_]", right operand type: "Type[bool_]") - mask.dtype == np.bool_ # type: ignore[comparison-overlap] - ): + if not (isinstance(mask, np.ndarray) and mask.dtype == np.bool_): raise TypeError( "mask should be boolean numpy array. Use " "the 'pd.array' function instead" @@ -1157,7 +1151,12 @@ def any(self, *, skipna: bool = True, **kwargs): nv.validate_any((), kwargs) values = self._data.copy() - np.putmask(values, self._mask, self._falsey_value) + # error: Argument 3 to "putmask" has incompatible type "object"; + # expected "Union[_SupportsArray[dtype[Any]], + # _NestedSequence[_SupportsArray[dtype[Any]]], + # bool, int, float, complex, str, bytes, + # _NestedSequence[Union[bool, int, float, complex, str, bytes]]]" + np.putmask(values, self._mask, self._falsey_value) # type: ignore[arg-type] result = values.any() if skipna: return result @@ -1233,7 +1232,12 @@ def all(self, *, skipna: bool = True, **kwargs): nv.validate_all((), kwargs) values = self._data.copy() - np.putmask(values, self._mask, self._truthy_value) + # error: Argument 3 to "putmask" has incompatible type "object"; + # expected "Union[_SupportsArray[dtype[Any]], + # _NestedSequence[_SupportsArray[dtype[Any]]], + # bool, int, float, complex, str, bytes, + # _NestedSequence[Union[bool, int, float, complex, str, bytes]]]" + np.putmask(values, self._mask, self._truthy_value) # type: ignore[arg-type] result = values.all() if skipna: diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py index 8215abf294221..0c34229fb5080 100644 --- a/pandas/core/arrays/sparse/array.py +++ b/pandas/core/arrays/sparse/array.py @@ -944,7 +944,16 @@ def __getitem__( if is_integer(key): return self._get_val_at(key) elif isinstance(key, tuple): - data_slice = self.to_dense()[key] + # error: Invalid index type "Tuple[Union[int, ellipsis], ...]" + # for "ndarray[Any, Any]"; expected type + # "Union[SupportsIndex, _SupportsArray[dtype[Union[bool_, + # integer[Any]]]], _NestedSequence[_SupportsArray[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]]]]], + # _NestedSequence[Union[bool, int]]], ...]]" + data_slice = self.to_dense()[key] # type: ignore[index] elif isinstance(key, slice): # Avoid densifying when handling contiguous slices @@ -1184,7 +1193,10 @@ def _concat_same_type( data = np.concatenate(values) indices_arr = np.concatenate(indices) - sp_index = IntIndex(length, indices_arr) + # error: 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] else: # when concatenating block indices, we don't claim that you'll @@ -1374,7 +1386,8 @@ def __setstate__(self, state): if isinstance(state, tuple): # Compat for pandas < 0.24.0 nd_state, (fill_value, sp_index) = state - sparse_values = np.array([]) + # error: Need type annotation for "sparse_values" + sparse_values = np.array([]) # type: ignore[var-annotated] sparse_values.__setstate__(nd_state) self._sparse_values = sparse_values diff --git a/pandas/core/dtypes/astype.py b/pandas/core/dtypes/astype.py index 7dc2c81746454..8d1427976276c 100644 --- a/pandas/core/dtypes/astype.py +++ b/pandas/core/dtypes/astype.py @@ -113,9 +113,7 @@ def astype_nansafe( ).reshape(shape) elif is_datetime64_dtype(arr.dtype): - # error: Non-overlapping equality check (left - # operand type: "dtype[Any]", right operand type: "Type[signedinteger[Any]]") - if dtype == np.int64: # type: ignore[comparison-overlap] + if dtype == np.int64: if isna(arr).any(): raise ValueError("Cannot convert NaT values to integer") return arr.view(dtype) @@ -127,9 +125,7 @@ def astype_nansafe( raise TypeError(f"cannot astype a datetimelike from [{arr.dtype}] to [{dtype}]") elif is_timedelta64_dtype(arr.dtype): - # error: Non-overlapping equality check (left - # operand type: "dtype[Any]", right operand type: "Type[signedinteger[Any]]") - if dtype == np.int64: # type: ignore[comparison-overlap] + if dtype == np.int64: if isna(arr).any(): raise ValueError("Cannot convert NaT values to integer") return arr.view(dtype) diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index bdbad2560b2d7..a192337daf59b 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -534,9 +534,7 @@ def is_string_or_object_np_dtype(dtype: np.dtype) -> bool: """ Faster alternative to is_string_dtype, assumes we have a np.dtype object. """ - # error: Non-overlapping equality check (left operand type: - # "dtype[Any]", right operand type: "Type[object]") - return dtype == object or dtype.kind in "SU" # type: ignore[comparison-overlap] + return dtype == object or dtype.kind in "SU" def is_string_dtype(arr_or_dtype) -> bool: diff --git a/pandas/core/exchange/buffer.py b/pandas/core/exchange/buffer.py index 65f2ac6dabef5..098c596bff4cd 100644 --- a/pandas/core/exchange/buffer.py +++ b/pandas/core/exchange/buffer.py @@ -57,8 +57,7 @@ def __dlpack__(self): Represent this structure as DLPack interface. """ if _NUMPY_HAS_DLPACK: - # error: "ndarray[Any, Any]" has no attribute "__dlpack__" - return self._x.__dlpack__() # type: ignore[attr-defined] + return self._x.__dlpack__() raise NotImplementedError("__dlpack__") def __dlpack_device__(self) -> Tuple[DlpackDeviceType, Optional[int]]: diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 535b06650c665..7b5c374dc25d9 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -2481,7 +2481,9 @@ def to_records( if dtype_mapping is None: formats.append(v.dtype) elif isinstance(dtype_mapping, (type, np.dtype, str)): - formats.append(dtype_mapping) + # error: Argument 1 to "append" of "list" has incompatible + # type "Union[type, dtype[Any], str]"; expected "dtype[Any]" + formats.append(dtype_mapping) # type: ignore[arg-type] else: element = "row" if i < index_len else "column" msg = f"Invalid dtype {dtype_mapping} specified for {element} {name}" diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 7e6233d247251..2f0daa9438832 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -4834,7 +4834,13 @@ def _join_non_unique( right = other._values.take(right_idx) if isinstance(join_array, np.ndarray): - np.putmask(join_array, mask, right) + # error: Argument 3 to "putmask" has incompatible type + # "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]]]" + np.putmask(join_array, mask, right) # type: ignore[arg-type] else: join_array._putmask(mask, right) @@ -5348,7 +5354,10 @@ def __getitem__(self, key): if hasattr(result, "_ndarray"): # i.e. NDArrayBackedExtensionArray # Unpack to ndarray for MPL compat - return result._ndarray + # error: Item "ndarray[Any, Any]" of + # "Union[ExtensionArray, ndarray[Any, Any]]" + # has no attribute "_ndarray" + return result._ndarray # type ignore[union-attr] return result # NB: Using _constructor._simple_new would break if MultiIndex @@ -6886,7 +6895,9 @@ def insert(self, loc: int, item) -> Index: new_values = np.insert(arr, loc, casted) else: - new_values = np.insert(arr, loc, None) + # error: No overload variant of "insert" matches argument types + # "ndarray[Any, Any]", "int", "None" + new_values = np.insert(arr, loc, None) # type: ignore[call-overload] loc = loc if loc >= 0 else loc - 1 new_values[loc] = item diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 101eac992e95d..f8ba26f4d4fc3 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -1577,7 +1577,13 @@ def is_monotonic_increasing(self) -> bool: self._get_level_values(i)._values for i in reversed(range(len(self.levels))) ] try: - sort_order = np.lexsort(values) + # error: 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]]]" + sort_order = np.lexsort(values) # type: ignore[arg-type] return Index(sort_order).is_monotonic_increasing except TypeError: diff --git a/pandas/core/internals/ops.py b/pandas/core/internals/ops.py index c938a018574f9..1160d3b2a8e3a 100644 --- a/pandas/core/internals/ops.py +++ b/pandas/core/internals/ops.py @@ -125,9 +125,7 @@ def _get_same_shape_values( # argument type "Tuple[Union[ndarray, slice], slice]" lvals = lvals[rblk.mgr_locs.indexer, :] # type: ignore[call-overload] assert lvals.shape[0] == 1, lvals.shape - # error: No overload variant of "__getitem__" of "ExtensionArray" matches - # argument type "Tuple[int, slice]" - lvals = lvals[0, :] # type: ignore[call-overload] + lvals = lvals[0, :] else: # lvals are 1D, rvals are 2D assert rvals.shape[0] == 1, rvals.shape diff --git a/pandas/core/missing.py b/pandas/core/missing.py index 6224b35f7e680..57b0a95f803b1 100644 --- a/pandas/core/missing.py +++ b/pandas/core/missing.py @@ -333,7 +333,13 @@ def func(yvalues: np.ndarray) -> None: **kwargs, ) - np.apply_along_axis(func, axis, data) + # error: Argument 1 to "apply_along_axis" has incompatible type + # "Callable[[ndarray[Any, Any]], None]"; expected "Callable[..., + # Union[_SupportsArray[dtype[]], Sequence[_SupportsArray + # [dtype[]]], Sequence[Sequence[_SupportsArray[dtype[]]]], + # Sequence[Sequence[Sequence[_SupportsArray[dtype[]]]]], + # Sequence[Sequence[Sequence[Sequence[_SupportsArray[dtype[]]]]]]]]" + np.apply_along_axis(func, axis, data) # type: ignore[arg-type] return @@ -772,13 +778,23 @@ def interpolate_2d( """ if limit_area is not None: np.apply_along_axis( - partial( + # error: Argument 1 to "apply_along_axis" has incompatible type + # "partial[None]"; expected + # "Callable[..., Union[_SupportsArray[dtype[]], + # Sequence[_SupportsArray[dtype[]]], + # Sequence[Sequence[_SupportsArray[dtype[]]]], + # Sequence[Sequence[Sequence[_SupportsArray[dtype[]]]]], + # Sequence[Sequence[Sequence[Sequence[_ + # SupportsArray[dtype[]]]]]]]]" + partial( # type: ignore[arg-type] _interpolate_with_limit_area, method=method, limit=limit, limit_area=limit_area, ), - axis, + # error: Argument 2 to "apply_along_axis" has incompatible type + # "Union[str, int]"; expected "SupportsIndex" + axis, # type: ignore[arg-type] values, ) return diff --git a/pandas/core/reshape/melt.py b/pandas/core/reshape/melt.py index aa426d24db75d..06127c8ecb932 100644 --- a/pandas/core/reshape/melt.py +++ b/pandas/core/reshape/melt.py @@ -133,7 +133,9 @@ def melt( if is_extension_array_dtype(id_data): id_data = concat([id_data] * K, ignore_index=True) else: - id_data = np.tile(id_data._values, K) + # error: Incompatible types in assignment (expression has type + # "ndarray[Any, dtype[Any]]", variable has type "Series") + id_data = np.tile(id_data._values, K) # type: ignore[assignment] mdata[col] = id_data mcolumns = id_vars + var_name + [value_name] diff --git a/pandas/core/series.py b/pandas/core/series.py index cf602115f683f..6ebee74810305 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2024,7 +2024,9 @@ def count(self, level=None): lev = lev.insert(cnt, lev._na_value) obs = level_codes[notna(self._values)] - out = np.bincount(obs, minlength=len(lev) or None) + # error: Argument "minlength" to "bincount" has incompatible type + # "Optional[int]"; expected "SupportsIndex" + out = np.bincount(obs, minlength=len(lev) or None) # type: ignore[arg-type] return self._constructor(out, index=lev, dtype="int64").__finalize__( self, method="count" ) diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index 886d81af8ba6b..b45f43adbe952 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -409,10 +409,7 @@ def _prep_values(self, values: ArrayLike) -> np.ndarray: if inf.any(): values = np.where(inf, np.nan, values) - # error: Incompatible return value type - # (got "Union[ExtensionArray, ndarray[Any, Any], - # ndarray[Any, dtype[floating[_64Bit]]]]", expected "ndarray[Any, Any]") - return values # type: ignore[return-value] + return values def _insert_on_column(self, result: DataFrame, obj: DataFrame) -> None: # if we have an 'on' column we want to put it back into diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 1f42329389a18..24669e84443a6 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -3860,24 +3860,10 @@ def _highlight_between( Return an array of css props based on condition of data values within given range. """ if np.iterable(left) and not isinstance(left, str): - # error: Argument 1 to "_validate_apply_axis_arg" - # has incompatible type "Union[str, float, Period, - # Timedelta, Interval[Any], datetime64, timedelta64, - # datetime, Sequence[Any], ndarray[Any, Any], NDFrame, None]"; - # expected "Union[NDFrame, Sequence[Any], ndarray[Any, Any]]" - left = _validate_apply_axis_arg( - left, "left", None, data # type: ignore[arg-type] - ) + left = _validate_apply_axis_arg(left, "left", None, data) if np.iterable(right) and not isinstance(right, str): - # error: Argument 1 to "_validate_apply_axis_arg" - # has incompatible type "Union[str, float, Period, - # Timedelta, Interval[Any], datetime64, timedelta64, - # datetime, Sequence[Any], ndarray[Any, Any], NDFrame, None]"; - # expected "Union[NDFrame, Sequence[Any], ndarray[Any, Any]]" - right = _validate_apply_axis_arg( - right, "right", None, data # type: ignore[arg-type] - ) + right = _validate_apply_axis_arg(right, "right", None, data) # get ops with correct boundary attribution if inclusive == "both": diff --git a/pandas/io/parsers/c_parser_wrapper.py b/pandas/io/parsers/c_parser_wrapper.py index 7781860f0d61e..3d6b5fcb49b85 100644 --- a/pandas/io/parsers/c_parser_wrapper.py +++ b/pandas/io/parsers/c_parser_wrapper.py @@ -400,7 +400,15 @@ def _concatenate_chunks(chunks: list[dict[int, ArrayLike]]) -> dict: arrs # type: ignore[arg-type] ) else: - result[name] = np.concatenate(arrs) + # error: 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] if warning_columns: warning_names = ",".join(warning_columns) diff --git a/pandas/tests/extension/date/array.py b/pandas/tests/extension/date/array.py index d29ed293e71ed..eca935cdc9128 100644 --- a/pandas/tests/extension/date/array.py +++ b/pandas/tests/extension/date/array.py @@ -109,7 +109,9 @@ def __init__( self._month = np.zeros(ldates, dtype=np.uint8) # 255 (1, 31) self._day = np.zeros(ldates, dtype=np.uint8) # 255 (1, 12) - for (i,), (y, m, d) in np.ndenumerate(np.char.split(dates, sep="-")): + # error: "object_" object is not iterable + obj = np.char.split(dates, sep="-") + for (i,), (y, m, d) in np.ndenumerate(obj): # type: ignore[misc] self._year[i] = int(y) self._month[i] = int(m) self._day[i] = int(d) From b3a7fc015b4411d939aaf5dadcf1d95e1129fd51 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Wed, 22 Jun 2022 13:35:28 -0700 Subject: [PATCH 2/2] Followup fixes --- pandas/core/indexes/base.py | 2 +- pandas/core/indexes/multi.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 2f0daa9438832..0393c9d07cc74 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -5357,7 +5357,7 @@ def __getitem__(self, key): # error: Item "ndarray[Any, Any]" of # "Union[ExtensionArray, ndarray[Any, Any]]" # has no attribute "_ndarray" - return result._ndarray # type ignore[union-attr] + return result._ndarray # type: ignore[union-attr] return result # NB: Using _constructor._simple_new would break if MultiIndex diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index f8ba26f4d4fc3..0a8df9d64d512 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -363,7 +363,10 @@ def _validate_codes(self, level: list, code: list): """ null_mask = isna(level) if np.any(null_mask): - code = np.where(null_mask[code], -1, code) + # error: 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] return code def _verify_integrity(self, codes: list | None = None, levels: list | None = None):