diff --git a/pyproject.toml b/pyproject.toml index c87d2322285..a2093a10fa6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,6 +27,7 @@ exclude_lines = ["pragma: no cover", "if TYPE_CHECKING"] exclude = 'xarray/util/generate_.*\.py' files = "xarray" show_error_codes = true +warn_unused_ignores = true # Most of the numerical computing stack doesn't have type annotations yet. [[tool.mypy.overrides]] diff --git a/xarray/__init__.py b/xarray/__init__.py index 46dcf0e9b32..e920e94ca19 100644 --- a/xarray/__init__.py +++ b/xarray/__init__.py @@ -40,7 +40,7 @@ from importlib.metadata import version as _version except ImportError: # if the fallback library is missing, we are doomed. - from importlib_metadata import version as _version # type: ignore[no-redef] + from importlib_metadata import version as _version try: __version__ = _version("xarray") diff --git a/xarray/backends/locks.py b/xarray/backends/locks.py index 73144df2b41..1de8fc8f7b8 100644 --- a/xarray/backends/locks.py +++ b/xarray/backends/locks.py @@ -61,7 +61,7 @@ def _get_lock_maker(scheduler=None): try: from dask.distributed import Lock as DistributedLock except ImportError: - DistributedLock = None # type: ignore + DistributedLock = None return DistributedLock else: raise KeyError(scheduler) diff --git a/xarray/core/_typed_ops.pyi b/xarray/core/_typed_ops.pyi index 46af53b1097..98a17a47cd5 100644 --- a/xarray/core/_typed_ops.pyi +++ b/xarray/core/_typed_ops.pyi @@ -77,157 +77,157 @@ class DataArrayOpsMixin: @overload def __add__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __add__(self, other: "DatasetGroupBy") -> "Dataset": ... # type: ignore[misc] + def __add__(self, other: "DatasetGroupBy") -> "Dataset": ... @overload def __add__(self: T_DataArray, other: DaCompatible) -> T_DataArray: ... @overload def __sub__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __sub__(self, other: "DatasetGroupBy") -> "Dataset": ... # type: ignore[misc] + def __sub__(self, other: "DatasetGroupBy") -> "Dataset": ... @overload def __sub__(self: T_DataArray, other: DaCompatible) -> T_DataArray: ... @overload def __mul__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __mul__(self, other: "DatasetGroupBy") -> "Dataset": ... # type: ignore[misc] + def __mul__(self, other: "DatasetGroupBy") -> "Dataset": ... @overload def __mul__(self: T_DataArray, other: DaCompatible) -> T_DataArray: ... @overload def __pow__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __pow__(self, other: "DatasetGroupBy") -> "Dataset": ... # type: ignore[misc] + def __pow__(self, other: "DatasetGroupBy") -> "Dataset": ... @overload def __pow__(self: T_DataArray, other: DaCompatible) -> T_DataArray: ... @overload def __truediv__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __truediv__(self, other: "DatasetGroupBy") -> "Dataset": ... # type: ignore[misc] + def __truediv__(self, other: "DatasetGroupBy") -> "Dataset": ... @overload def __truediv__(self: T_DataArray, other: DaCompatible) -> T_DataArray: ... @overload def __floordiv__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __floordiv__(self, other: "DatasetGroupBy") -> "Dataset": ... # type: ignore[misc] + def __floordiv__(self, other: "DatasetGroupBy") -> "Dataset": ... @overload def __floordiv__(self: T_DataArray, other: DaCompatible) -> T_DataArray: ... @overload def __mod__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __mod__(self, other: "DatasetGroupBy") -> "Dataset": ... # type: ignore[misc] + def __mod__(self, other: "DatasetGroupBy") -> "Dataset": ... @overload def __mod__(self: T_DataArray, other: DaCompatible) -> T_DataArray: ... @overload def __and__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __and__(self, other: "DatasetGroupBy") -> "Dataset": ... # type: ignore[misc] + def __and__(self, other: "DatasetGroupBy") -> "Dataset": ... @overload def __and__(self: T_DataArray, other: DaCompatible) -> T_DataArray: ... @overload def __xor__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __xor__(self, other: "DatasetGroupBy") -> "Dataset": ... # type: ignore[misc] + def __xor__(self, other: "DatasetGroupBy") -> "Dataset": ... @overload def __xor__(self: T_DataArray, other: DaCompatible) -> T_DataArray: ... @overload def __or__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __or__(self, other: "DatasetGroupBy") -> "Dataset": ... # type: ignore[misc] + def __or__(self, other: "DatasetGroupBy") -> "Dataset": ... @overload def __or__(self: T_DataArray, other: DaCompatible) -> T_DataArray: ... @overload def __lt__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __lt__(self, other: "DatasetGroupBy") -> "Dataset": ... # type: ignore[misc] + def __lt__(self, other: "DatasetGroupBy") -> "Dataset": ... @overload def __lt__(self: T_DataArray, other: DaCompatible) -> T_DataArray: ... @overload def __le__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __le__(self, other: "DatasetGroupBy") -> "Dataset": ... # type: ignore[misc] + def __le__(self, other: "DatasetGroupBy") -> "Dataset": ... @overload def __le__(self: T_DataArray, other: DaCompatible) -> T_DataArray: ... @overload def __gt__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __gt__(self, other: "DatasetGroupBy") -> "Dataset": ... # type: ignore[misc] + def __gt__(self, other: "DatasetGroupBy") -> "Dataset": ... @overload def __gt__(self: T_DataArray, other: DaCompatible) -> T_DataArray: ... @overload def __ge__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __ge__(self, other: "DatasetGroupBy") -> "Dataset": ... # type: ignore[misc] + def __ge__(self, other: "DatasetGroupBy") -> "Dataset": ... @overload def __ge__(self: T_DataArray, other: DaCompatible) -> T_DataArray: ... @overload # type: ignore[override] def __eq__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __eq__(self, other: "DatasetGroupBy") -> "Dataset": ... # type: ignore[misc] + def __eq__(self, other: "DatasetGroupBy") -> "Dataset": ... @overload def __eq__(self: T_DataArray, other: DaCompatible) -> T_DataArray: ... @overload # type: ignore[override] def __ne__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __ne__(self, other: "DatasetGroupBy") -> "Dataset": ... # type: ignore[misc] + def __ne__(self, other: "DatasetGroupBy") -> "Dataset": ... @overload def __ne__(self: T_DataArray, other: DaCompatible) -> T_DataArray: ... @overload def __radd__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __radd__(self, other: "DatasetGroupBy") -> "Dataset": ... # type: ignore[misc] + def __radd__(self, other: "DatasetGroupBy") -> "Dataset": ... @overload def __radd__(self: T_DataArray, other: DaCompatible) -> T_DataArray: ... @overload def __rsub__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __rsub__(self, other: "DatasetGroupBy") -> "Dataset": ... # type: ignore[misc] + def __rsub__(self, other: "DatasetGroupBy") -> "Dataset": ... @overload def __rsub__(self: T_DataArray, other: DaCompatible) -> T_DataArray: ... @overload def __rmul__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __rmul__(self, other: "DatasetGroupBy") -> "Dataset": ... # type: ignore[misc] + def __rmul__(self, other: "DatasetGroupBy") -> "Dataset": ... @overload def __rmul__(self: T_DataArray, other: DaCompatible) -> T_DataArray: ... @overload def __rpow__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __rpow__(self, other: "DatasetGroupBy") -> "Dataset": ... # type: ignore[misc] + def __rpow__(self, other: "DatasetGroupBy") -> "Dataset": ... @overload def __rpow__(self: T_DataArray, other: DaCompatible) -> T_DataArray: ... @overload def __rtruediv__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __rtruediv__(self, other: "DatasetGroupBy") -> "Dataset": ... # type: ignore[misc] + def __rtruediv__(self, other: "DatasetGroupBy") -> "Dataset": ... @overload def __rtruediv__(self: T_DataArray, other: DaCompatible) -> T_DataArray: ... @overload def __rfloordiv__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __rfloordiv__(self, other: "DatasetGroupBy") -> "Dataset": ... # type: ignore[misc] + def __rfloordiv__(self, other: "DatasetGroupBy") -> "Dataset": ... @overload def __rfloordiv__(self: T_DataArray, other: DaCompatible) -> T_DataArray: ... @overload def __rmod__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __rmod__(self, other: "DatasetGroupBy") -> "Dataset": ... # type: ignore[misc] + def __rmod__(self, other: "DatasetGroupBy") -> "Dataset": ... @overload def __rmod__(self: T_DataArray, other: DaCompatible) -> T_DataArray: ... @overload def __rand__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __rand__(self, other: "DatasetGroupBy") -> "Dataset": ... # type: ignore[misc] + def __rand__(self, other: "DatasetGroupBy") -> "Dataset": ... @overload def __rand__(self: T_DataArray, other: DaCompatible) -> T_DataArray: ... @overload def __rxor__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __rxor__(self, other: "DatasetGroupBy") -> "Dataset": ... # type: ignore[misc] + def __rxor__(self, other: "DatasetGroupBy") -> "Dataset": ... @overload def __rxor__(self: T_DataArray, other: DaCompatible) -> T_DataArray: ... @overload def __ror__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __ror__(self, other: "DatasetGroupBy") -> "Dataset": ... # type: ignore[misc] + def __ror__(self, other: "DatasetGroupBy") -> "Dataset": ... @overload def __ror__(self: T_DataArray, other: DaCompatible) -> T_DataArray: ... def _inplace_binary_op(self, other, f): ... @@ -417,157 +417,157 @@ class DatasetGroupByOpsMixin: @overload def __add__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __add__(self, other: "DataArray") -> "Dataset": ... # type: ignore[misc] + def __add__(self, other: "DataArray") -> "Dataset": ... @overload def __add__(self, other: GroupByIncompatible) -> NoReturn: ... @overload def __sub__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __sub__(self, other: "DataArray") -> "Dataset": ... # type: ignore[misc] + def __sub__(self, other: "DataArray") -> "Dataset": ... @overload def __sub__(self, other: GroupByIncompatible) -> NoReturn: ... @overload def __mul__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __mul__(self, other: "DataArray") -> "Dataset": ... # type: ignore[misc] + def __mul__(self, other: "DataArray") -> "Dataset": ... @overload def __mul__(self, other: GroupByIncompatible) -> NoReturn: ... @overload def __pow__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __pow__(self, other: "DataArray") -> "Dataset": ... # type: ignore[misc] + def __pow__(self, other: "DataArray") -> "Dataset": ... @overload def __pow__(self, other: GroupByIncompatible) -> NoReturn: ... @overload def __truediv__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __truediv__(self, other: "DataArray") -> "Dataset": ... # type: ignore[misc] + def __truediv__(self, other: "DataArray") -> "Dataset": ... @overload def __truediv__(self, other: GroupByIncompatible) -> NoReturn: ... @overload def __floordiv__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __floordiv__(self, other: "DataArray") -> "Dataset": ... # type: ignore[misc] + def __floordiv__(self, other: "DataArray") -> "Dataset": ... @overload def __floordiv__(self, other: GroupByIncompatible) -> NoReturn: ... @overload def __mod__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __mod__(self, other: "DataArray") -> "Dataset": ... # type: ignore[misc] + def __mod__(self, other: "DataArray") -> "Dataset": ... @overload def __mod__(self, other: GroupByIncompatible) -> NoReturn: ... @overload def __and__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __and__(self, other: "DataArray") -> "Dataset": ... # type: ignore[misc] + def __and__(self, other: "DataArray") -> "Dataset": ... @overload def __and__(self, other: GroupByIncompatible) -> NoReturn: ... @overload def __xor__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __xor__(self, other: "DataArray") -> "Dataset": ... # type: ignore[misc] + def __xor__(self, other: "DataArray") -> "Dataset": ... @overload def __xor__(self, other: GroupByIncompatible) -> NoReturn: ... @overload def __or__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __or__(self, other: "DataArray") -> "Dataset": ... # type: ignore[misc] + def __or__(self, other: "DataArray") -> "Dataset": ... @overload def __or__(self, other: GroupByIncompatible) -> NoReturn: ... @overload def __lt__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __lt__(self, other: "DataArray") -> "Dataset": ... # type: ignore[misc] + def __lt__(self, other: "DataArray") -> "Dataset": ... @overload def __lt__(self, other: GroupByIncompatible) -> NoReturn: ... @overload def __le__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __le__(self, other: "DataArray") -> "Dataset": ... # type: ignore[misc] + def __le__(self, other: "DataArray") -> "Dataset": ... @overload def __le__(self, other: GroupByIncompatible) -> NoReturn: ... @overload def __gt__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __gt__(self, other: "DataArray") -> "Dataset": ... # type: ignore[misc] + def __gt__(self, other: "DataArray") -> "Dataset": ... @overload def __gt__(self, other: GroupByIncompatible) -> NoReturn: ... @overload def __ge__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __ge__(self, other: "DataArray") -> "Dataset": ... # type: ignore[misc] + def __ge__(self, other: "DataArray") -> "Dataset": ... @overload def __ge__(self, other: GroupByIncompatible) -> NoReturn: ... @overload # type: ignore[override] def __eq__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __eq__(self, other: "DataArray") -> "Dataset": ... # type: ignore[misc] + def __eq__(self, other: "DataArray") -> "Dataset": ... @overload def __eq__(self, other: GroupByIncompatible) -> NoReturn: ... @overload # type: ignore[override] def __ne__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __ne__(self, other: "DataArray") -> "Dataset": ... # type: ignore[misc] + def __ne__(self, other: "DataArray") -> "Dataset": ... @overload def __ne__(self, other: GroupByIncompatible) -> NoReturn: ... @overload def __radd__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __radd__(self, other: "DataArray") -> "Dataset": ... # type: ignore[misc] + def __radd__(self, other: "DataArray") -> "Dataset": ... @overload def __radd__(self, other: GroupByIncompatible) -> NoReturn: ... @overload def __rsub__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __rsub__(self, other: "DataArray") -> "Dataset": ... # type: ignore[misc] + def __rsub__(self, other: "DataArray") -> "Dataset": ... @overload def __rsub__(self, other: GroupByIncompatible) -> NoReturn: ... @overload def __rmul__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __rmul__(self, other: "DataArray") -> "Dataset": ... # type: ignore[misc] + def __rmul__(self, other: "DataArray") -> "Dataset": ... @overload def __rmul__(self, other: GroupByIncompatible) -> NoReturn: ... @overload def __rpow__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __rpow__(self, other: "DataArray") -> "Dataset": ... # type: ignore[misc] + def __rpow__(self, other: "DataArray") -> "Dataset": ... @overload def __rpow__(self, other: GroupByIncompatible) -> NoReturn: ... @overload def __rtruediv__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __rtruediv__(self, other: "DataArray") -> "Dataset": ... # type: ignore[misc] + def __rtruediv__(self, other: "DataArray") -> "Dataset": ... @overload def __rtruediv__(self, other: GroupByIncompatible) -> NoReturn: ... @overload def __rfloordiv__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __rfloordiv__(self, other: "DataArray") -> "Dataset": ... # type: ignore[misc] + def __rfloordiv__(self, other: "DataArray") -> "Dataset": ... @overload def __rfloordiv__(self, other: GroupByIncompatible) -> NoReturn: ... @overload def __rmod__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __rmod__(self, other: "DataArray") -> "Dataset": ... # type: ignore[misc] + def __rmod__(self, other: "DataArray") -> "Dataset": ... @overload def __rmod__(self, other: GroupByIncompatible) -> NoReturn: ... @overload def __rand__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __rand__(self, other: "DataArray") -> "Dataset": ... # type: ignore[misc] + def __rand__(self, other: "DataArray") -> "Dataset": ... @overload def __rand__(self, other: GroupByIncompatible) -> NoReturn: ... @overload def __rxor__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __rxor__(self, other: "DataArray") -> "Dataset": ... # type: ignore[misc] + def __rxor__(self, other: "DataArray") -> "Dataset": ... @overload def __rxor__(self, other: GroupByIncompatible) -> NoReturn: ... @overload def __ror__(self, other: T_Dataset) -> T_Dataset: ... @overload - def __ror__(self, other: "DataArray") -> "Dataset": ... # type: ignore[misc] + def __ror__(self, other: "DataArray") -> "Dataset": ... @overload def __ror__(self, other: GroupByIncompatible) -> NoReturn: ... diff --git a/xarray/core/alignment.py b/xarray/core/alignment.py index a0650557b56..ef30d9afe85 100644 --- a/xarray/core/alignment.py +++ b/xarray/core/alignment.py @@ -490,7 +490,7 @@ def _get_dim_pos_indexers( obj_idx = matching_indexes.get(key) if obj_idx is not None: if self.reindex[key]: - indexers = obj_idx.reindex_like(aligned_idx, **self.reindex_kwargs) # type: ignore[call-arg] + indexers = obj_idx.reindex_like(aligned_idx, **self.reindex_kwargs) dim_pos_indexers.update(indexers) return dim_pos_indexers diff --git a/xarray/core/combine.py b/xarray/core/combine.py index 4ad96ba39e0..f474d3beb19 100644 --- a/xarray/core/combine.py +++ b/xarray/core/combine.py @@ -377,7 +377,7 @@ def _nested_combine( # Define type for arbitrarily-nested list of lists recursively # Currently mypy cannot handle this but other linters can (https://stackoverflow.com/a/53845083/3154101) -DATASET_HYPERCUBE = Union[Dataset, Iterable["DATASET_HYPERCUBE"]] # type: ignore +DATASET_HYPERCUBE = Union[Dataset, Iterable["DATASET_HYPERCUBE"]] # type: ignore[misc] def combine_nested( diff --git a/xarray/core/computation.py b/xarray/core/computation.py index d2fc9f588b4..41d529b1093 100644 --- a/xarray/core/computation.py +++ b/xarray/core/computation.py @@ -1734,7 +1734,7 @@ def dot( dim_counts.update(arr.dims) dims = tuple(d for d, c in dim_counts.items() if c > 1) - dot_dims: set[Hashable] = set(dims) # type:ignore[arg-type] + dot_dims: set[Hashable] = set(dims) # dimensions to be parallelized broadcast_dims = common_dims - dot_dims diff --git a/xarray/core/coordinates.py b/xarray/core/coordinates.py index 52110d5bfee..3a6b70f117a 100644 --- a/xarray/core/coordinates.py +++ b/xarray/core/coordinates.py @@ -54,11 +54,11 @@ def dtypes(self) -> Frozen[Hashable, np.dtype]: @property def indexes(self) -> Indexes[pd.Index]: - return self._data.indexes # type: ignore[attr-defined] + return self._data.indexes @property def xindexes(self) -> Indexes[Index]: - return self._data.xindexes # type: ignore[attr-defined] + return self._data.xindexes @property def variables(self): @@ -116,11 +116,9 @@ def to_index(self, ordered_dims: Sequence[Hashable] | None = None) -> pd.Index: raise ValueError("no valid index for a 0-dimensional object") elif len(ordered_dims) == 1: (dim,) = ordered_dims - return self._data.get_index(dim) # type: ignore[attr-defined] + return self._data.get_index(dim) else: - indexes = [ - self._data.get_index(k) for k in ordered_dims # type: ignore[attr-defined] - ] + indexes = [self._data.get_index(k) for k in ordered_dims] # compute the sizes of the repeat and tile for the cartesian product # (taken from pandas.core.reshape.util) diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index 6eac634bfff..f939a2c8b6e 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -428,7 +428,7 @@ def __init__( # TODO(shoyer): document this argument, once it becomes part of the # public interface. - self._indexes = indexes # type: ignore[assignment] + self._indexes = indexes self._close = None diff --git a/xarray/core/groupby.py b/xarray/core/groupby.py index 2cd4a2d3805..589f6c98c2a 100644 --- a/xarray/core/groupby.py +++ b/xarray/core/groupby.py @@ -713,7 +713,7 @@ def _flox_reduce( elif dim is ...: parsed_dim = tuple(self._original_obj.dims) else: - parsed_dim = tuple(dim) # type:ignore[arg-type] + parsed_dim = tuple(dim) # Do this so we raise the same error message whether flox is present or not. # Better to control it here than in flox. @@ -747,7 +747,7 @@ def _flox_reduce( result = xarray_reduce( self._original_obj.drop_vars(non_numeric), group, - dim=parsed_dim, # type:ignore[arg-type] # https://github.com/xarray-contrib/flox/issues/96 + dim=parsed_dim, expected_groups=expected_groups, isbin=isbin, keep_attrs=keep_attrs, diff --git a/xarray/core/indexing.py b/xarray/core/indexing.py index 6b33741633d..8dd2d1a0ead 100644 --- a/xarray/core/indexing.py +++ b/xarray/core/indexing.py @@ -180,7 +180,7 @@ def map_index_queries( # forward dimension indexers with no index/coordinate results.append(IndexSelResult(labels)) else: - results.append(index.sel(labels, **options)) # type: ignore[call-arg] + results.append(index.sel(labels, **options)) merged = merge_sel_results(results) @@ -1422,7 +1422,7 @@ def __init__(self, array: pd.Index, dtype: DTypeLike = None): if dtype is None: self._dtype = get_valid_numpy_dtype(array) else: - self._dtype = np.dtype(dtype) # type: ignore[assignment] + self._dtype = np.dtype(dtype) @property def dtype(self) -> np.dtype: diff --git a/xarray/core/variable.py b/xarray/core/variable.py index c06639b75ae..bb988392f50 100644 --- a/xarray/core/variable.py +++ b/xarray/core/variable.py @@ -1509,7 +1509,7 @@ def pad( if reflect_type is not None: pad_option_kwargs["reflect_type"] = reflect_type - array = np.pad( # type: ignore[call-overload] + array = np.pad( self.data.astype(dtype, copy=False), pad_width_by_index, mode=mode, diff --git a/xarray/plot/dataarray_plot.py b/xarray/plot/dataarray_plot.py index ac23f7dc96d..46aaf33f683 100644 --- a/xarray/plot/dataarray_plot.py +++ b/xarray/plot/dataarray_plot.py @@ -1488,7 +1488,7 @@ def newplotfunc( if ax is None: # TODO: Importing Axes3D is no longer necessary in matplotlib >= 3.2. # Remove when minimum requirement of matplotlib is 3.2: - from mpl_toolkits.mplot3d import Axes3D # type: ignore # noqa: F401 + from mpl_toolkits.mplot3d import Axes3D # noqa: F401 # delete so it does not end up in locals() del Axes3D @@ -1521,7 +1521,7 @@ def newplotfunc( and not kwargs.get("_is_facetgrid", False) and ax is not None ): - import mpl_toolkits # type: ignore + import mpl_toolkits if not isinstance(ax, mpl_toolkits.mplot3d.Axes3D): raise ValueError( diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py index 70987a3dd38..9275c689c6d 100644 --- a/xarray/tests/test_backends.py +++ b/xarray/tests/test_backends.py @@ -3153,7 +3153,7 @@ def test_open_badbytes(self) -> None: with pytest.raises( ValueError, match=r"not the signature of a valid netCDF4 file" ): - with open_dataset(BytesIO(b"garbage"), engine="h5netcdf"): # type: ignore[arg-type] + with open_dataset(BytesIO(b"garbage"), engine="h5netcdf"): pass def test_open_twice(self) -> None: diff --git a/xarray/tests/test_coding_times.py b/xarray/tests/test_coding_times.py index a73e5472893..ca3b93728aa 100644 --- a/xarray/tests/test_coding_times.py +++ b/xarray/tests/test_coding_times.py @@ -614,7 +614,7 @@ def test_cf_timedelta_2d() -> None: actual = coding.times.decode_cf_timedelta(numbers, units) assert_array_equal(expected, actual) - assert expected.dtype == actual.dtype # type: ignore + assert expected.dtype == actual.dtype @pytest.mark.parametrize( @@ -651,7 +651,7 @@ def test_format_cftime_datetime(date_args, expected) -> None: def test_decode_cf(calendar) -> None: days = [1.0, 2.0, 3.0] # TODO: GH5690 — do we want to allow this type for `coords`? - da = DataArray(days, coords=[days], dims=["time"], name="test") # type: ignore + da = DataArray(days, coords=[days], dims=["time"], name="test") ds = da.to_dataset() for v in ["test", "time"]: diff --git a/xarray/tests/test_dataarray.py b/xarray/tests/test_dataarray.py index ac6049872b8..8184fe1955c 100644 --- a/xarray/tests/test_dataarray.py +++ b/xarray/tests/test_dataarray.py @@ -512,7 +512,7 @@ def test_equals_and_identical(self) -> None: def test_equals_failures(self) -> None: orig = DataArray(np.arange(5.0), {"a": 42}, dims="x") - assert not orig.equals(np.arange(5)) # type: ignore + assert not orig.equals(np.arange(5)) # type: ignore[arg-type] assert not orig.identical(123) # type: ignore assert not orig.broadcast_equals({1: 2}) # type: ignore @@ -2754,9 +2754,9 @@ def test_quantile_method(self, method) -> None: actual = DataArray(self.va).quantile(q, method=method) if Version(np.__version__) >= Version("1.22.0"): - expected = np.nanquantile(self.dv.values, np.array(q), method=method) # type: ignore[call-arg] + expected = np.nanquantile(self.dv.values, np.array(q), method=method) else: - expected = np.nanquantile(self.dv.values, np.array(q), interpolation=method) # type: ignore[call-arg] + expected = np.nanquantile(self.dv.values, np.array(q), interpolation=method) np.testing.assert_allclose(actual.values, expected) diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index 23ea705db71..8f3eb728f01 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -6230,7 +6230,7 @@ def test_query(self, backend, engine, parser) -> None: with pytest.raises(ValueError): ds.query("a > 5") # type: ignore # must be dict or kwargs with pytest.raises(ValueError): - ds.query(x=(a > 5)) # type: ignore # must be query string + ds.query(x=(a > 5)) with pytest.raises(IndexError): ds.query(y="a > 5") # wrong length dimension with pytest.raises(IndexError): diff --git a/xarray/tests/test_distributed.py b/xarray/tests/test_distributed.py index 780417c488b..2dd589fd872 100644 --- a/xarray/tests/test_distributed.py +++ b/xarray/tests/test_distributed.py @@ -189,7 +189,7 @@ def test_dask_distributed_zarr_integration_test( write_kwargs: dict[str, Any] = {"consolidated": True} read_kwargs: dict[str, Any] = {"backend_kwargs": {"consolidated": True}} else: - write_kwargs = read_kwargs = {} # type: ignore + write_kwargs = read_kwargs = {} chunks = {"dim1": 4, "dim2": 3, "dim3": 5} with cluster() as (s, [a, b]): with Client(s["address"], loop=loop): diff --git a/xarray/tests/test_extensions.py b/xarray/tests/test_extensions.py index 6f91cdf661e..d4414b1f53a 100644 --- a/xarray/tests/test_extensions.py +++ b/xarray/tests/test_extensions.py @@ -37,7 +37,6 @@ def foo(self): da = xr.DataArray(0) assert da.demo.foo == "bar" - # accessor is cached assert ds.demo is ds.demo @@ -45,7 +44,7 @@ def foo(self): assert ds.demo.__doc__ == "Demo accessor." # TODO: typing doesn't seem to work with accessors assert xr.Dataset.demo.__doc__ == "Demo accessor." # type: ignore - assert isinstance(ds.demo, DemoAccessor) # type: ignore + assert isinstance(ds.demo, DemoAccessor) assert xr.Dataset.demo is DemoAccessor # type: ignore # ensure we can remove it diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index 88f03c03b40..d4a707b4e23 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -43,7 +43,7 @@ try: import matplotlib as mpl import matplotlib.pyplot as plt - import mpl_toolkits # type: ignore + import mpl_toolkits except ImportError: pass diff --git a/xarray/tests/test_variable.py b/xarray/tests/test_variable.py index 983c584f69d..3a6c8f1b966 100644 --- a/xarray/tests/test_variable.py +++ b/xarray/tests/test_variable.py @@ -1769,9 +1769,9 @@ def test_quantile_method(self, method, use_dask) -> None: actual = v.quantile(q, dim="y", method=method) if Version(np.__version__) >= Version("1.22"): - expected = np.nanquantile(self.d, q, axis=1, method=method) # type: ignore[call-arg] + expected = np.nanquantile(self.d, q, axis=1, method=method) else: - expected = np.nanquantile(self.d, q, axis=1, interpolation=method) # type: ignore[call-arg] + expected = np.nanquantile(self.d, q, axis=1, interpolation=method) if use_dask: assert isinstance(actual.data, dask_array_type) diff --git a/xarray/util/generate_ops.py b/xarray/util/generate_ops.py index 7407e3d3f4f..0ca5954b056 100644 --- a/xarray/util/generate_ops.py +++ b/xarray/util/generate_ops.py @@ -110,7 +110,7 @@ def {method}(self: T_Dataset, other: DsCompatible) -> T_Dataset: ...{override}"" @overload{override} def {method}(self, other: T_Dataset) -> T_Dataset: ... @overload - def {method}(self, other: "DatasetGroupBy") -> "Dataset": ... # type: ignore[misc] + def {method}(self, other: "DatasetGroupBy") -> "Dataset": ... @overload def {method}(self: T_DataArray, other: DaCompatible) -> T_DataArray: ...""" stub_var = """\ @@ -124,7 +124,7 @@ def {method}(self: T_Variable, other: VarCompatible) -> T_Variable: ...""" @overload{override} def {method}(self, other: T_Dataset) -> T_Dataset: ... @overload - def {method}(self, other: "DataArray") -> "Dataset": ... # type: ignore[misc] + def {method}(self, other: "DataArray") -> "Dataset": ... @overload def {method}(self, other: GroupByIncompatible) -> NoReturn: ...""" stub_dagb = """\