diff --git a/asv_bench/benchmarks/dataset_io.py b/asv_bench/benchmarks/dataset_io.py index 8ab367b76e0..527a2d41138 100644 --- a/asv_bench/benchmarks/dataset_io.py +++ b/asv_bench/benchmarks/dataset_io.py @@ -722,7 +722,7 @@ class PerformanceBackend(xr.backends.BackendEntrypoint): def open_dataset( self, filename_or_obj: str | os.PathLike | None, - drop_variables: tuple[str, ...] = None, + drop_variables: tuple[str, ...] | None = None, *, mask_and_scale=True, decode_times=True, diff --git a/ci/min_deps_check.py b/ci/min_deps_check.py index 9096f2df28b..a01d82ebfbb 100755 --- a/ci/min_deps_check.py +++ b/ci/min_deps_check.py @@ -186,7 +186,7 @@ def process_pkg( ) -def fmt_version(major: int, minor: int, patch: int = None) -> str: +def fmt_version(major: int, minor: int, patch: int | None = None) -> str: if patch is None: return f"{major}.{minor}" else: diff --git a/pyproject.toml b/pyproject.toml index 83e575bebef..9ba2bf33c2b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -245,6 +245,12 @@ ignore = [ "E501", "E731", "UP007", + "RUF001", + "RUF002", + "RUF003", + "RUF005", + "RUF007", + "RUF012", ] extend-select = [ "B", # flake8-bugbear @@ -254,6 +260,7 @@ extend-select = [ "TID", # flake8-tidy-imports (absolute imports) "I", # isort "PGH", # pygrep-hooks + "RUF", "UP", # Pyupgrade ] diff --git a/xarray/__init__.py b/xarray/__init__.py index e818d6c53b2..e474cee85ad 100644 --- a/xarray/__init__.py +++ b/xarray/__init__.py @@ -78,13 +78,13 @@ "combine_by_coords", "combine_nested", "concat", + "corr", + "cov", + "cross", "date_range", "date_range_like", "decode_cf", "dot", - "cov", - "corr", - "cross", "full_like", "get_options", "group_subtrees", @@ -121,8 +121,8 @@ "Index", "IndexSelResult", "IndexVariable", - "Variable", "NamedArray", + "Variable", # Exceptions "InvalidTreeError", "MergeError", diff --git a/xarray/backends/__init__.py b/xarray/backends/__init__.py index 550b9e29e42..e5df179716f 100644 --- a/xarray/backends/__init__.py +++ b/xarray/backends/__init__.py @@ -23,21 +23,21 @@ "AbstractDataStore", "BackendArray", "BackendEntrypoint", - "FileManager", "CachingFileManager", "DummyFileManager", - "InMemoryDataStore", - "NetCDF4DataStore", - "PydapDataStore", - "ScipyDataStore", + "FileManager", "H5NetCDFStore", - "ZarrStore", "H5netcdfBackendEntrypoint", + "InMemoryDataStore", "NetCDF4BackendEntrypoint", + "NetCDF4DataStore", "PydapBackendEntrypoint", + "PydapDataStore", "ScipyBackendEntrypoint", + "ScipyDataStore", "StoreBackendEntrypoint", "ZarrBackendEntrypoint", + "ZarrStore", "list_engines", "refresh_engines", ] diff --git a/xarray/backends/common.py b/xarray/backends/common.py index 57542a8e8f4..c51cf3d1964 100644 --- a/xarray/backends/common.py +++ b/xarray/backends/common.py @@ -276,7 +276,7 @@ def __exit__(self, exception_type, exception_value, traceback): class ArrayWriter: - __slots__ = ("sources", "targets", "regions", "lock") + __slots__ = ("lock", "regions", "sources", "targets") def __init__(self, lock=None): self.sources = [] diff --git a/xarray/backends/h5netcdf_.py b/xarray/backends/h5netcdf_.py index f51f5873817..80579d68415 100644 --- a/xarray/backends/h5netcdf_.py +++ b/xarray/backends/h5netcdf_.py @@ -100,14 +100,14 @@ class H5NetCDFStore(WritableCFDataStore): """Store for reading and writing data via h5netcdf""" __slots__ = ( - "autoclose", - "format", - "is_remote", - "lock", "_filename", "_group", "_manager", "_mode", + "autoclose", + "format", + "is_remote", + "lock", ) def __init__(self, manager, group=None, mode=None, lock=HDF5_LOCK, autoclose=False): diff --git a/xarray/backends/locks.py b/xarray/backends/locks.py index 69cef309b45..7cff53d6267 100644 --- a/xarray/backends/locks.py +++ b/xarray/backends/locks.py @@ -149,7 +149,7 @@ def _get_scheduler(get=None, collection=None) -> str | None: # Fix for bug caused by dask installation that doesn't involve the toolz library # Issue: 4164 import dask - from dask.base import get_scheduler # noqa: F401 + from dask.base import get_scheduler actual_get = get_scheduler(get, collection) except ImportError: diff --git a/xarray/backends/netCDF4_.py b/xarray/backends/netCDF4_.py index 09db8679070..acc083ee4c8 100644 --- a/xarray/backends/netCDF4_.py +++ b/xarray/backends/netCDF4_.py @@ -361,14 +361,14 @@ class NetCDF4DataStore(WritableCFDataStore): """ __slots__ = ( - "autoclose", - "format", - "is_remote", - "lock", "_filename", "_group", "_manager", "_mode", + "autoclose", + "format", + "is_remote", + "lock", ) def __init__( diff --git a/xarray/backends/zarr.py b/xarray/backends/zarr.py index bed7d84d60d..ba74f8829b6 100644 --- a/xarray/backends/zarr.py +++ b/xarray/backends/zarr.py @@ -182,7 +182,7 @@ def encode_zarr_attr_value(value): class ZarrArrayWrapper(BackendArray): - __slots__ = ("dtype", "shape", "_array") + __slots__ = ("_array", "dtype", "shape") def __init__(self, zarr_array): # some callers attempt to evaluate an array if an `array` property exists on the object. @@ -598,18 +598,18 @@ class ZarrStore(AbstractWritableDataStore): """Store for reading and writing data via zarr""" __slots__ = ( - "zarr_group", "_append_dim", + "_close_store_on_close", "_consolidate_on_close", "_group", "_mode", "_read_only", - "_synchronizer", - "_write_region", "_safe_chunks", - "_write_empty", - "_close_store_on_close", + "_synchronizer", "_use_zarr_fill_value_as_mask", + "_write_empty", + "_write_region", + "zarr_group", ) @classmethod diff --git a/xarray/conventions.py b/xarray/conventions.py index 9f719b8497c..133dbf00063 100644 --- a/xarray/conventions.py +++ b/xarray/conventions.py @@ -368,13 +368,13 @@ def _update_bounds_encoding(variables: T_Variables) -> None: and attrs["bounds"] in variables ): emit_user_level_warning( - f"Variable {name:s} has datetime type and a " - f"bounds variable but {name:s}.encoding does not have " - f"units specified. The units encodings for {name:s} " + f"Variable {name} has datetime type and a " + f"bounds variable but {name}.encoding does not have " + f"units specified. The units encodings for {name} " f"and {attrs['bounds']} will be determined independently " "and may not be equal, counter to CF-conventions. " "If this is a concern, specify a units encoding for " - f"{name:s} before writing to a file.", + f"{name} before writing to a file.", ) if has_date_units and "bounds" in attrs: @@ -486,9 +486,7 @@ def stackable(dim: Hashable) -> bool: for role_or_name in part.split() ] if len(roles_and_names) % 2 == 1: - emit_user_level_warning( - f"Attribute {attr_name:s} malformed" - ) + emit_user_level_warning(f"Attribute {attr_name} malformed") var_names = roles_and_names[1::2] if all(var_name in variables for var_name in var_names): new_vars[k].encoding[attr_name] = attr_val @@ -500,7 +498,7 @@ def stackable(dim: Hashable) -> bool: if proj_name not in variables ] emit_user_level_warning( - f"Variable(s) referenced in {attr_name:s} not in variables: {referenced_vars_not_in_variables!s}", + f"Variable(s) referenced in {attr_name} not in variables: {referenced_vars_not_in_variables}", ) del var_attrs[attr_name] diff --git a/xarray/core/computation.py b/xarray/core/computation.py index b8ebb2ff841..552a10adde4 100644 --- a/xarray/core/computation.py +++ b/xarray/core/computation.py @@ -77,11 +77,11 @@ class _UFuncSignature: """ __slots__ = ( - "input_core_dims", - "output_core_dims", + "_all_core_dims", "_all_input_core_dims", "_all_output_core_dims", - "_all_core_dims", + "input_core_dims", + "output_core_dims", ) def __init__(self, input_core_dims, output_core_dims=((),)): diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index 45d27f56f50..171fa58201a 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -421,13 +421,13 @@ class DataArray( _variable: Variable __slots__ = ( + "__weakref__", "_cache", - "_coords", "_close", + "_coords", "_indexes", "_name", "_variable", - "__weakref__", ) dt = utils.UncachedAccessor(CombinedDatetimelikeAccessor["DataArray"]) @@ -4537,7 +4537,7 @@ def from_dict(cls, d: Mapping[str, Any]) -> Self: except KeyError as e: raise ValueError( "cannot convert dict when coords are missing the key " - f"'{str(e.args[0])}'" + f"'{e.args[0]}'" ) from e try: data = d["data"] diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index f21e365c05a..889384bc068 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -684,15 +684,15 @@ class Dataset( _variables: dict[Hashable, Variable] __slots__ = ( + "__weakref__", "_attrs", "_cache", + "_close", "_coord_names", "_dims", "_encoding", - "_close", "_indexes", "_variables", - "__weakref__", ) def __init__( @@ -6430,7 +6430,7 @@ def transpose( """ # Raise error if list is passed as dim if (len(dim) > 0) and (isinstance(dim[0], list)): - list_fix = [f"{repr(x)}" if isinstance(x, str) else f"{x}" for x in dim[0]] + list_fix = [f"{x!r}" if isinstance(x, str) else f"{x}" for x in dim[0]] raise TypeError( f'transpose requires dim to be passed as multiple arguments. Expected `{", ".join(list_fix)}`. Received `{dim[0]}` instead' ) @@ -7800,7 +7800,7 @@ def from_dict(cls, d: Mapping[Any, Any]) -> Self: } except KeyError as e: raise ValueError( - f"cannot convert dict without the key '{str(e.args[0])}'" + f"cannot convert dict without the key '{e.args[0]}'" ) from e obj = cls(variable_dict) @@ -10155,7 +10155,7 @@ def _wrapper(Y, *args, **kwargs): if name is _THIS_ARRAY: name = "" else: - name = f"{str(name)}_" + name = f"{name}_" input_core_dims = [reduce_dims_ for _ in range(n_coords + 1)] input_core_dims.extend( diff --git a/xarray/core/datatree.py b/xarray/core/datatree.py index efbdd6bc8eb..6d673389e05 100644 --- a/xarray/core/datatree.py +++ b/xarray/core/datatree.py @@ -217,10 +217,10 @@ class DatasetView(Dataset): __slots__ = ( "_attrs", "_cache", # used by _CachedAccessor + "_close", "_coord_names", "_dims", "_encoding", - "_close", "_indexes", "_variables", ) @@ -457,17 +457,17 @@ class DataTree( _close: Callable[[], None] | None __slots__ = ( - "_name", - "_parent", - "_children", + "_attrs", "_cache", # used by _CachedAccessor + "_children", + "_close", "_data_variables", + "_encoding", + "_name", "_node_coord_variables", "_node_dims", "_node_indexes", - "_attrs", - "_encoding", - "_close", + "_parent", ) def __init__( diff --git a/xarray/core/datatree_render.py b/xarray/core/datatree_render.py index b79882a6abb..1781c49d83a 100644 --- a/xarray/core/datatree_render.py +++ b/xarray/core/datatree_render.py @@ -205,8 +205,8 @@ def __repr__(self) -> str: classname = self.__class__.__name__ args = [ repr(self.node), - f"style={repr(self.style)}", - f"childiter={repr(self.childiter)}", + f"style={self.style!r}", + f"childiter={self.childiter!r}", ] return f"{classname}({', '.join(args)})" diff --git a/xarray/core/dtypes.py b/xarray/core/dtypes.py index 74b529f1265..362cd78c689 100644 --- a/xarray/core/dtypes.py +++ b/xarray/core/dtypes.py @@ -208,7 +208,7 @@ def isdtype(dtype, kind: str | tuple[str, ...], xp=None) -> bool: if not isinstance(kind, str) and not ( isinstance(kind, tuple) and all(isinstance(k, str) for k in kind) # type: ignore[redundant-expr] ): - raise TypeError(f"kind must be a string or a tuple of strings: {repr(kind)}") + raise TypeError(f"kind must be a string or a tuple of strings: {kind!r}") if isinstance(dtype, np.dtype): return npcompat.isdtype(dtype, kind) diff --git a/xarray/core/extension_array.py b/xarray/core/extension_array.py index b2efeae7bb0..8e6ab7a85f1 100644 --- a/xarray/core/extension_array.py +++ b/xarray/core/extension_array.py @@ -106,7 +106,7 @@ def __array_ufunc__(ufunc, method, *inputs, **kwargs): return ufunc(*inputs, **kwargs) def __repr__(self): - return f"{type(self)}(array={repr(self.array)})" + return f"{type(self)}(array={self.array!r})" def __getattr__(self, attr: str) -> object: return getattr(self.array, attr) diff --git a/xarray/core/formatting.py b/xarray/core/formatting.py index 3e23e41ff93..ab17fa85381 100644 --- a/xarray/core/formatting.py +++ b/xarray/core/formatting.py @@ -293,9 +293,7 @@ def inline_sparse_repr(array): """Similar to sparse.COO.__repr__, but without the redundant shape/dtype.""" sparse_array_type = array_type("sparse") assert isinstance(array, sparse_array_type), array - return ( - f"<{type(array).__name__}: nnz={array.nnz:d}, fill_value={array.fill_value!s}>" - ) + return f"<{type(array).__name__}: nnz={array.nnz:d}, fill_value={array.fill_value}>" def inline_variable_array_repr(var, max_width): diff --git a/xarray/core/groupby.py b/xarray/core/groupby.py index 5c4633c1612..8770a5f408d 100644 --- a/xarray/core/groupby.py +++ b/xarray/core/groupby.py @@ -173,7 +173,7 @@ class _DummyGroup(Generic[T_Xarray]): Should not be user visible. """ - __slots__ = ("name", "coords", "size", "dataarray") + __slots__ = ("coords", "dataarray", "name", "size") def __init__(self, obj: T_Xarray, name: Hashable, coords) -> None: self.name = name @@ -567,24 +567,24 @@ class GroupBy(Generic[T_Xarray]): """ __slots__ = ( + "_by_chunked", + "_codes", + "_dims", "_group_dim", - "groupers", - "_obj", - "_restore_coord_dims", # cached properties "_groups", - "_dims", - "_sizes", + "_inserted_dims", "_len", - "_by_chunked", + "_obj", # Save unstacked object for flox "_original_obj", - "_codes", - # stack nD vars - "group1d", + "_restore_coord_dims", + "_sizes", "_stacked_dim", - "_inserted_dims", "encoded", + # stack nD vars + "group1d", + "groupers", ) _obj: T_Xarray groupers: tuple[ResolvedGrouper, ...] diff --git a/xarray/core/indexes.py b/xarray/core/indexes.py index 81ea9b5dca5..13fd0bca95e 100644 --- a/xarray/core/indexes.py +++ b/xarray/core/indexes.py @@ -573,7 +573,7 @@ class PandasIndex(Index): dim: Hashable coord_dtype: Any - __slots__ = ("index", "dim", "coord_dtype") + __slots__ = ("coord_dtype", "dim", "index") def __init__( self, @@ -872,7 +872,7 @@ def __getitem__(self, indexer: Any): return self._replace(self.index[indexer]) def __repr__(self): - return f"PandasIndex({repr(self.index)})" + return f"PandasIndex({self.index!r})" def _check_dim_compat(variables: Mapping[Any, Variable], all_dims: str = "equal"): @@ -939,7 +939,7 @@ class PandasMultiIndex(PandasIndex): coord_dtype: Any level_coords_dtype: dict[str, Any] - __slots__ = ("index", "dim", "coord_dtype", "level_coords_dtype") + __slots__ = ("coord_dtype", "dim", "index", "level_coords_dtype") def __init__(self, array: Any, dim: Hashable, level_coords_dtype: Any = None): super().__init__(array, dim) @@ -1451,13 +1451,13 @@ class Indexes(collections.abc.Mapping, Generic[T_PandasOrXarrayIndex]): _variables: dict[Any, Variable] __slots__ = ( + "__coord_name_id", + "__id_coord_names", + "__id_index", + "_dims", "_index_type", "_indexes", "_variables", - "_dims", - "__coord_name_id", - "__id_index", - "__id_coord_names", ) def __init__( diff --git a/xarray/core/indexing.py b/xarray/core/indexing.py index 04eb67b981e..0a7b94a53c7 100644 --- a/xarray/core/indexing.py +++ b/xarray/core/indexing.py @@ -599,7 +599,7 @@ def __getitem__(self, key: Any): class LazilyIndexedArray(ExplicitlyIndexedNDArrayMixin): """Wrap an array to make basic and outer indexing lazy.""" - __slots__ = ("array", "key", "_shape") + __slots__ = ("_shape", "array", "key") def __init__(self, array: Any, key: ExplicitIndexer | None = None): """ @@ -779,7 +779,7 @@ def _wrap_numpy_scalars(array): class CopyOnWriteArray(ExplicitlyIndexedNDArrayMixin): - __slots__ = ("array", "_copied") + __slots__ = ("_copied", "array") def __init__(self, array: duckarray[Any, Any]): self.array = as_indexable(array) @@ -1658,7 +1658,7 @@ def transpose(self, order): class PandasIndexingAdapter(ExplicitlyIndexedNDArrayMixin): """Wrap a pandas.Index to preserve dtypes and handle explicit indexing.""" - __slots__ = ("array", "_dtype") + __slots__ = ("_dtype", "array") array: pd.Index _dtype: np.dtype @@ -1825,7 +1825,7 @@ class PandasMultiIndexingAdapter(PandasIndexingAdapter): the same multi-index). """ - __slots__ = ("array", "_dtype", "level", "adapter") + __slots__ = ("_dtype", "adapter", "array", "level") array: pd.MultiIndex _dtype: np.dtype diff --git a/xarray/core/merge.py b/xarray/core/merge.py index 43d3ac9b404..61c73ca9a7c 100644 --- a/xarray/core/merge.py +++ b/xarray/core/merge.py @@ -582,7 +582,7 @@ def merge_attrs(variable_attrs, combine_attrs, context=None): except ValueError as e: raise MergeError( "combine_attrs='no_conflicts', but some values are not " - f"the same. Merging {str(result)} with {str(attrs)}" + f"the same. Merging {result} with {attrs}" ) from e return result elif combine_attrs == "drop_conflicts": @@ -608,8 +608,8 @@ def merge_attrs(variable_attrs, combine_attrs, context=None): for attrs in variable_attrs[1:]: if not dict_equiv(result, attrs): raise MergeError( - f"combine_attrs='identical', but attrs differ. First is {str(result)} " - f", other is {str(attrs)}." + f"combine_attrs='identical', but attrs differ. First is {result} " + f", other is {attrs}." ) return result else: diff --git a/xarray/core/rolling.py b/xarray/core/rolling.py index 072012e5f51..d2b65fbaf74 100644 --- a/xarray/core/rolling.py +++ b/xarray/core/rolling.py @@ -64,7 +64,7 @@ class Rolling(Generic[T_Xarray]): xarray.DataArray.rolling """ - __slots__ = ("obj", "window", "min_periods", "center", "dim") + __slots__ = ("center", "dim", "min_periods", "obj", "window") _attributes = ("window", "min_periods", "center", "dim") dim: list[Hashable] window: list[int] @@ -907,12 +907,12 @@ class Coarsen(CoarsenArithmetic, Generic[T_Xarray]): """ __slots__ = ( - "obj", "boundary", "coord_func", - "windows", + "obj", "side", "trim_excess", + "windows", ) _attributes = ("windows", "side", "trim_excess") obj: T_Xarray diff --git a/xarray/core/variable.py b/xarray/core/variable.py index 16e292796a7..228e10e3009 100644 --- a/xarray/core/variable.py +++ b/xarray/core/variable.py @@ -379,7 +379,7 @@ class Variable(NamedArray, AbstractArray, VariableArithmetic): they can use more complete metadata in context of coordinate labels. """ - __slots__ = ("_dims", "_data", "_attrs", "_encoding") + __slots__ = ("_attrs", "_data", "_dims", "_encoding") def __init__( self, @@ -695,7 +695,7 @@ def _validate_indexers(self, key): if self.shape[self.get_axis_num(dim)] != len(k): raise IndexError( f"Boolean array size {len(k):d} is used to index array " - f"with shape {str(self.shape):s}." + f"with shape {self.shape}." ) if k.ndim > 1: raise IndexError( @@ -713,7 +713,7 @@ def _validate_indexers(self, key): raise IndexError( "Boolean indexer should be unlabeled or on the " "same dimension to the indexed array. Indexer is " - f"on {str(k.dims):s} but the target dimension is {dim:s}." + f"on {k.dims} but the target dimension is {dim}." ) def _broadcast_indexes_outer(self, key): diff --git a/xarray/groupers.py b/xarray/groupers.py index c4980e6d810..0adfcce9483 100644 --- a/xarray/groupers.py +++ b/xarray/groupers.py @@ -35,12 +35,12 @@ from xarray.namedarray.pycompat import is_chunked_array __all__ = [ + "BinGrouper", "EncodedGroups", "Grouper", "Resampler", - "UniqueGrouper", - "BinGrouper", "TimeResampler", + "UniqueGrouper", ] RESAMPLE_DIM = "__resample_dim__" diff --git a/xarray/namedarray/core.py b/xarray/namedarray/core.py index b753d26d622..98d96c73e91 100644 --- a/xarray/namedarray/core.py +++ b/xarray/namedarray/core.py @@ -248,7 +248,7 @@ class NamedArray(NamedArrayAggregations, Generic[_ShapeType_co, _DType_co]): >>> narr = NamedArray(("x",), data, {"units": "m"}) # TODO: Better name than narr? """ - __slots__ = ("_data", "_dims", "_attrs") + __slots__ = ("_attrs", "_data", "_dims") _data: duckarray[Any, _DType_co] _dims: _Dims diff --git a/xarray/plot/__init__.py b/xarray/plot/__init__.py index ae7a0012b32..49f12e13bfc 100644 --- a/xarray/plot/__init__.py +++ b/xarray/plot/__init__.py @@ -22,15 +22,15 @@ from xarray.plot.facetgrid import FacetGrid __all__ = [ - "plot", - "line", - "step", + "FacetGrid", "contour", "contourf", "hist", "imshow", + "line", "pcolormesh", - "FacetGrid", + "plot", "scatter", + "step", "surface", ] diff --git a/xarray/plot/dataarray_plot.py b/xarray/plot/dataarray_plot.py index adf0f2e9906..a12f900b43f 100644 --- a/xarray/plot/dataarray_plot.py +++ b/xarray/plot/dataarray_plot.py @@ -1480,7 +1480,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 # noqa: F401 + from mpl_toolkits.mplot3d import Axes3D # delete so it does not end up in locals() del Axes3D diff --git a/xarray/plot/utils.py b/xarray/plot/utils.py index 5e20592c8c0..2f19d2e7566 100644 --- a/xarray/plot/utils.py +++ b/xarray/plot/utils.py @@ -1383,10 +1383,10 @@ class _Normalize(Sequence): __slots__ = ( "_data", + "_data_is_numeric", "_data_unique", "_data_unique_index", "_data_unique_inverse", - "_data_is_numeric", "_width", ) diff --git a/xarray/testing/__init__.py b/xarray/testing/__init__.py index a4770071d3a..a18b1963421 100644 --- a/xarray/testing/__init__.py +++ b/xarray/testing/__init__.py @@ -17,8 +17,8 @@ __all__ = [ "assert_allclose", "assert_chunks_equal", - "assert_duckarray_equal", "assert_duckarray_allclose", + "assert_duckarray_equal", "assert_equal", "assert_identical", "assert_isomorphic", diff --git a/xarray/testing/assertions.py b/xarray/testing/assertions.py index 6cd88be6e24..d2b01677ce4 100644 --- a/xarray/testing/assertions.py +++ b/xarray/testing/assertions.py @@ -423,7 +423,7 @@ def _assert_dataset_invariants(ds: Dataset, check_default_indexes: bool): set(ds._variables), ) - assert type(ds._dims) is dict, ds._dims # noqa: E721 + assert type(ds._dims) is dict, ds._dims assert all(isinstance(v, int) for v in ds._dims.values()), ds._dims var_dims: set[Hashable] = set() for v in ds._variables.values(): diff --git a/xarray/testing/strategies.py b/xarray/testing/strategies.py index eeba8540133..db7660c07ab 100644 --- a/xarray/testing/strategies.py +++ b/xarray/testing/strategies.py @@ -20,14 +20,14 @@ __all__ = [ - "supported_dtypes", - "pandas_index_dtypes", - "names", + "attrs", "dimension_names", "dimension_sizes", - "attrs", - "variables", + "names", + "pandas_index_dtypes", + "supported_dtypes", "unique_subset_of", + "variables", ] diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index 95285b1c913..6b582fc8ea0 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -684,7 +684,7 @@ def test_properties(self) -> None: assert isinstance(ds.dims, utils.Frozen) # TODO change after deprecation cycle in GH #8500 is complete assert isinstance(ds.dims.mapping, dict) - assert type(ds.dims.mapping) is dict # noqa: E721 + assert type(ds.dims.mapping) is dict with pytest.warns( FutureWarning, match=" To access a mapping from dimension names to lengths, please use `Dataset.sizes`", @@ -3069,7 +3069,7 @@ def test_rename(self) -> None: renamed[k].variable.to_base_variable(), ) assert v.encoding == renamed[k].encoding - assert type(v) is type(renamed.variables[k]) # noqa: E721 + assert type(v) is type(renamed.variables[k]) assert "var1" not in renamed assert "dim2" not in renamed diff --git a/xarray/tests/test_formatting.py b/xarray/tests/test_formatting.py index 6b1fb56c0d9..c7af13415c0 100644 --- a/xarray/tests/test_formatting.py +++ b/xarray/tests/test_formatting.py @@ -1142,7 +1142,7 @@ def test_array_repr_dtypes(): actual = repr(ds) expected = f""" Size: {array.dtype.itemsize}B -{repr(array)} +{array!r} Dimensions without coordinates: x """.strip() assert actual == expected @@ -1152,7 +1152,7 @@ def test_array_repr_dtypes(): actual = repr(ds) expected = f""" Size: 4B -{repr(array)} +{array!r} Dimensions without coordinates: x """.strip() assert actual == expected @@ -1162,7 +1162,7 @@ def test_array_repr_dtypes(): actual = repr(ds) expected = f""" Size: 8B -{repr(array)} +{array!r} Dimensions without coordinates: x """.strip() assert actual == expected diff --git a/xarray/tests/test_variable.py b/xarray/tests/test_variable.py index 1d430b6b27e..9ebd4e4a4d3 100644 --- a/xarray/tests/test_variable.py +++ b/xarray/tests/test_variable.py @@ -1071,7 +1071,7 @@ def test_values(self): def test_numpy_same_methods(self): v = Variable([], np.float32(0.0)) assert v.item() == 0 - assert type(v.item()) is float # noqa: E721 + assert type(v.item()) is float v = IndexVariable("x", np.arange(5)) assert 2 == v.searchsorted(2) diff --git a/xarray/tutorial.py b/xarray/tutorial.py index 6f57a7b1b42..ccdb0d8e031 100644 --- a/xarray/tutorial.py +++ b/xarray/tutorial.py @@ -59,7 +59,7 @@ def _check_netcdf_engine_installed(name): import scipy # noqa: F401 except ImportError: try: - import netCDF4 # noqa: F401 + import netCDF4 except ImportError as err: raise ImportError( f"opening tutorial dataset {name} requires either scipy or "