diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 02554cc7a45..eca14fe0631 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,13 +16,13 @@ repos: files: ^xarray/ - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: 'v0.0.277' + rev: 'v0.0.278' hooks: - id: ruff args: ["--fix"] # https://github.com/python/black#version-control-integration - repo: https://github.com/psf/black - rev: 23.3.0 + rev: 23.7.0 hooks: - id: black-jupyter - repo: https://github.com/keewis/blackdoc @@ -30,7 +30,7 @@ repos: hooks: - id: blackdoc exclude: "generate_aggregations.py" - additional_dependencies: ["black==23.3.0"] + additional_dependencies: ["black==23.7.0"] - id: blackdoc-autoupdate-black - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.4.1 diff --git a/xarray/core/common.py b/xarray/core/common.py index 5dd4c4dbd96..d54c259ae2c 100644 --- a/xarray/core/common.py +++ b/xarray/core/common.py @@ -307,9 +307,7 @@ def __setattr__(self, name: str, value: Any) -> None: except AttributeError as e: # Don't accidentally shadow custom AttributeErrors, e.g. # DataArray.dims.setter - if str(e) != "{!r} object has no attribute {!r}".format( - type(self).__name__, name - ): + if str(e) != f"{type(self).__name__!r} object has no attribute {name!r}": raise raise AttributeError( f"cannot set attribute {name!r} on a {type(self).__name__!r} object. Use __setitem__ style" @@ -1293,9 +1291,7 @@ def isin(self: T_DataWithCoords, test_elements: Any) -> T_DataWithCoords: if isinstance(test_elements, Dataset): raise TypeError( - "isin() argument must be convertible to an array: {}".format( - test_elements - ) + f"isin() argument must be convertible to an array: {test_elements}" ) elif isinstance(test_elements, (Variable, DataArray)): # need to explicitly pull out data to support dask arrays as the diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index 9635d678c36..bbaf79e23ba 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -4676,11 +4676,7 @@ def _title_for_slice(self, truncate: int = 50) -> str: for dim, coord in self.coords.items(): if coord.size == 1: one_dims.append( - "{dim} = {v}{unit}".format( - dim=dim, - v=format_item(coord.values), - unit=_get_units_from_attrs(coord), - ) + f"{dim} = {format_item(coord.values)}{_get_units_from_attrs(coord)}" ) title = ", ".join(one_dims) diff --git a/xarray/core/formatting.py b/xarray/core/formatting.py index 7f93706c74c..06f84c3eee1 100644 --- a/xarray/core/formatting.py +++ b/xarray/core/formatting.py @@ -697,9 +697,7 @@ def dataset_repr(ds): def diff_dim_summary(a, b): if a.dims != b.dims: - return "Differing dimensions:\n ({}) != ({})".format( - dim_summary(a), dim_summary(b) - ) + return f"Differing dimensions:\n ({dim_summary(a)}) != ({dim_summary(b)})" else: return "" @@ -826,9 +824,7 @@ def _compat_to_str(compat): def diff_array_repr(a, b, compat): # used for DataArray, Variable and IndexVariable summary = [ - "Left and right {} objects are not {}".format( - type(a).__name__, _compat_to_str(compat) - ) + f"Left and right {type(a).__name__} objects are not {_compat_to_str(compat)}" ] summary.append(diff_dim_summary(a, b)) @@ -859,9 +855,7 @@ def diff_array_repr(a, b, compat): def diff_dataset_repr(a, b, compat): summary = [ - "Left and right {} objects are not {}".format( - type(a).__name__, _compat_to_str(compat) - ) + f"Left and right {type(a).__name__} objects are not {_compat_to_str(compat)}" ] col_width = _calculate_col_width(set(list(a.variables) + list(b.variables))) diff --git a/xarray/core/missing.py b/xarray/core/missing.py index 7dbaf47b5cc..c6efaebc04c 100644 --- a/xarray/core/missing.py +++ b/xarray/core/missing.py @@ -66,9 +66,7 @@ def __call__(self, x): return self.f(x, **self.call_kwargs) def __repr__(self): - return "{type}: method={method}".format( - type=self.__class__.__name__, method=self.method - ) + return f"{self.__class__.__name__}: method={self.method}" class NumpyInterpolator(BaseInterpolator): diff --git a/xarray/core/parallel.py b/xarray/core/parallel.py index 2f8612c5a9b..07c3c606bf2 100644 --- a/xarray/core/parallel.py +++ b/xarray/core/parallel.py @@ -406,9 +406,7 @@ def _wrapper( new_layers: collections.defaultdict[str, dict[Any, Any]] = collections.defaultdict( dict ) - gname = "{}-{}".format( - dask.utils.funcname(func), dask.base.tokenize(npargs[0], args, kwargs) - ) + gname = f"{dask.utils.funcname(func)}-{dask.base.tokenize(npargs[0], args, kwargs)}" # map dims to list of chunk indexes ichunk = {dim: range(len(chunks_v)) for dim, chunks_v in input_chunks.items()} diff --git a/xarray/core/variable.py b/xarray/core/variable.py index d7c927bfd7a..720701be6f0 100644 --- a/xarray/core/variable.py +++ b/xarray/core/variable.py @@ -1083,9 +1083,7 @@ def _copy( ndata = as_compatible_data(data) if self.shape != ndata.shape: raise ValueError( - "Data shape {} must match shape of object {}".format( - ndata.shape, self.shape - ) + f"Data shape {ndata.shape} must match shape of object {self.shape}" ) attrs = copy.deepcopy(self._attrs, memo) if deep else copy.copy(self._attrs) @@ -3044,9 +3042,7 @@ def copy(self, deep: bool = True, data: ArrayLike | None = None): ndata = as_compatible_data(data) if self.shape != ndata.shape: raise ValueError( - "Data shape {} must match shape of object {}".format( - ndata.shape, self.shape - ) + f"Data shape {ndata.shape} must match shape of object {self.shape}" ) attrs = copy.deepcopy(self._attrs) if deep else copy.copy(self._attrs) diff --git a/xarray/testing.py b/xarray/testing.py index b6a88135ee1..dfd84851ac1 100644 --- a/xarray/testing.py +++ b/xarray/testing.py @@ -403,7 +403,5 @@ def _assert_internal_invariants( ) else: raise TypeError( - "{} is not a supported type for xarray invariant checks".format( - type(xarray_obj) - ) + f"{type(xarray_obj)} is not a supported type for xarray invariant checks" )