Skip to content

[pre-commit.ci] pre-commit autoupdate #7997

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ 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
rev: v0.3.8
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
Expand Down
8 changes: 2 additions & 6 deletions xarray/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 3 additions & 9 deletions xarray/core/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)))
Expand Down
4 changes: 1 addition & 3 deletions xarray/core/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 1 addition & 3 deletions xarray/core/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
Expand Down
8 changes: 2 additions & 6 deletions xarray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions xarray/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)