diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 74d77e2f2ca..970b2e5e8ca 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,13 +13,13 @@ repos: - id: mixed-line-ending - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: 'v0.2.0' + rev: 'v0.3.4' hooks: - id: ruff args: ["--fix", "--show-fixes"] # https://github.com/python/black#version-control-integration - repo: https://github.com/psf/black-pre-commit-mirror - rev: 24.1.1 + rev: 24.3.0 hooks: - id: black-jupyter - repo: https://github.com/keewis/blackdoc @@ -27,10 +27,10 @@ repos: hooks: - id: blackdoc exclude: "generate_aggregations.py" - additional_dependencies: ["black==24.1.1"] + additional_dependencies: ["black==24.3.0"] - id: blackdoc-autoupdate-black - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.8.0 + rev: v1.9.0 hooks: - id: mypy # Copied from setup.cfg diff --git a/xarray/coding/times.py b/xarray/coding/times.py index 92bce0abeaa..466e847e003 100644 --- a/xarray/coding/times.py +++ b/xarray/coding/times.py @@ -446,15 +446,7 @@ def format_cftime_datetime(date) -> str: """Converts a cftime.datetime object to a string with the format: YYYY-MM-DD HH:MM:SS.UUUUUU """ - return "{:04d}-{:02d}-{:02d} {:02d}:{:02d}:{:02d}.{:06d}".format( - date.year, - date.month, - date.day, - date.hour, - date.minute, - date.second, - date.microsecond, - ) + return f"{date.year:04d}-{date.month:02d}-{date.day:02d} {date.hour:02d}:{date.minute:02d}:{date.second:02d}.{date.microsecond:06d}" def infer_timedelta_units(deltas) -> str: diff --git a/xarray/coding/variables.py b/xarray/coding/variables.py index 52cf0fc3656..d31cb6e626a 100644 --- a/xarray/coding/variables.py +++ b/xarray/coding/variables.py @@ -81,9 +81,7 @@ def get_duck_array(self): return self.func(self.array.get_duck_array()) def __repr__(self) -> str: - return "{}({!r}, func={!r}, dtype={!r})".format( - type(self).__name__, self.array, self.func, self.dtype - ) + return f"{type(self).__name__}({self.array!r}, func={self.func!r}, dtype={self.dtype!r})" class NativeEndiannessArray(indexing.ExplicitlyIndexedNDArrayMixin): diff --git a/xarray/core/arithmetic.py b/xarray/core/arithmetic.py index 452c7115b75..734d7b328de 100644 --- a/xarray/core/arithmetic.py +++ b/xarray/core/arithmetic.py @@ -62,10 +62,10 @@ def __array_ufunc__(self, ufunc, method, *inputs, **kwargs): if method != "__call__": # TODO: support other methods, e.g., reduce and accumulate. raise NotImplementedError( - "{} method for ufunc {} is not implemented on xarray objects, " + f"{method} method for ufunc {ufunc} is not implemented on xarray objects, " "which currently only support the __call__ method. As an " "alternative, consider explicitly converting xarray objects " - "to NumPy arrays (e.g., with `.values`).".format(method, ufunc) + "to NumPy arrays (e.g., with `.values`)." ) if any(isinstance(o, SupportsArithmetic) for o in out): diff --git a/xarray/core/computation.py b/xarray/core/computation.py index f29f6c4dd35..f09b04b7765 100644 --- a/xarray/core/computation.py +++ b/xarray/core/computation.py @@ -133,11 +133,7 @@ def __ne__(self, other): return not self == other def __repr__(self): - return "{}({!r}, {!r})".format( - type(self).__name__, - list(self.input_core_dims), - list(self.output_core_dims), - ) + return f"{type(self).__name__}({list(self.input_core_dims)!r}, {list(self.output_core_dims)!r})" def __str__(self): lhs = ",".join("({})".format(",".join(dims)) for dims in self.input_core_dims) diff --git a/xarray/core/formatting.py b/xarray/core/formatting.py index 260dabd9d31..3eed7d02a2e 100644 --- a/xarray/core/formatting.py +++ b/xarray/core/formatting.py @@ -289,8 +289,8 @@ 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 "<{}: nnz={:d}, fill_value={!s}>".format( - type(array).__name__, array.nnz, array.fill_value + return ( + f"<{type(array).__name__}: nnz={array.nnz:d}, fill_value={array.fill_value!s}>" )