Skip to content

Commit 92f5278

Browse files
[pre-commit.ci] pre-commit autoupdate (#8145)
* [pre-commit.ci] pre-commit autoupdate updates: - [github.com/astral-sh/ruff-pre-commit: v0.0.282 → v0.0.287](astral-sh/ruff-pre-commit@v0.0.282...v0.0.287) - [github.com/pre-commit/mirrors-mypy: v1.4.1 → v1.5.1](pre-commit/mirrors-mypy@v1.4.1...v1.5.1) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Maximilian Roos <5635139+max-sixty@users.noreply.github.com> Co-authored-by: Maximilian Roos <m@maxroos.com>
1 parent f13da94 commit 92f5278

23 files changed

+82
-96
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ repos:
1818
files: ^xarray/
1919
- repo: https://github.com/astral-sh/ruff-pre-commit
2020
# Ruff version.
21-
rev: 'v0.0.282'
21+
rev: 'v0.0.287'
2222
hooks:
2323
- id: ruff
2424
args: ["--fix"]
@@ -35,7 +35,7 @@ repos:
3535
additional_dependencies: ["black==23.7.0"]
3636
- id: blackdoc-autoupdate-black
3737
- repo: https://github.com/pre-commit/mirrors-mypy
38-
rev: v1.4.1
38+
rev: v1.5.1
3939
hooks:
4040
- id: mypy
4141
# Copied from setup.cfg

xarray/backends/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,8 +1056,8 @@ def open_mfdataset(
10561056
)
10571057
else:
10581058
raise ValueError(
1059-
"{} is an invalid option for the keyword argument"
1060-
" ``combine``".format(combine)
1059+
f"{combine} is an invalid option for the keyword argument"
1060+
" ``combine``"
10611061
)
10621062
except ValueError:
10631063
for ds in datasets:

xarray/coding/cftime_offsets.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def __init__(self, n: int = 1):
105105
if not isinstance(n, int):
106106
raise TypeError(
107107
"The provided multiple 'n' must be an integer. "
108-
"Instead a value of type {!r} was provided.".format(type(n))
108+
f"Instead a value of type {type(n)!r} was provided."
109109
)
110110
self.n = n
111111

@@ -353,13 +353,13 @@ def _validate_month(month, default_month):
353353
raise TypeError(
354354
"'self.month' must be an integer value between 1 "
355355
"and 12. Instead, it was set to a value of "
356-
"{!r}".format(result_month)
356+
f"{result_month!r}"
357357
)
358358
elif not (1 <= result_month <= 12):
359359
raise ValueError(
360360
"'self.month' must be an integer value between 1 "
361361
"and 12. Instead, it was set to a value of "
362-
"{!r}".format(result_month)
362+
f"{result_month!r}"
363363
)
364364
return result_month
365365

@@ -771,7 +771,7 @@ def to_cftime_datetime(date_str_or_date, calendar=None):
771771
raise TypeError(
772772
"date_str_or_date must be a string or a "
773773
"subclass of cftime.datetime. Instead got "
774-
"{!r}.".format(date_str_or_date)
774+
f"{date_str_or_date!r}."
775775
)
776776

777777

xarray/coding/cftimeindex.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,12 @@ def assert_all_valid_date_type(data):
228228
if not isinstance(sample, cftime.datetime):
229229
raise TypeError(
230230
"CFTimeIndex requires cftime.datetime "
231-
"objects. Got object of {}.".format(date_type)
231+
f"objects. Got object of {date_type}."
232232
)
233233
if not all(isinstance(value, date_type) for value in data):
234234
raise TypeError(
235235
"CFTimeIndex requires using datetime "
236-
"objects of all the same type. Got\n{}.".format(data)
236+
f"objects of all the same type. Got\n{data}."
237237
)
238238

239239

@@ -553,8 +553,7 @@ def shift(self, n: int | float, freq: str | timedelta):
553553
return self + n * to_offset(freq)
554554
else:
555555
raise TypeError(
556-
"'freq' must be of type "
557-
"str or datetime.timedelta, got {}.".format(freq)
556+
"'freq' must be of type " f"str or datetime.timedelta, got {freq}."
558557
)
559558

560559
def __add__(self, other):
@@ -636,10 +635,10 @@ def to_datetimeindex(self, unsafe=False):
636635
if calendar not in _STANDARD_CALENDARS and not unsafe:
637636
warnings.warn(
638637
"Converting a CFTimeIndex with dates from a non-standard "
639-
"calendar, {!r}, to a pandas.DatetimeIndex, which uses dates "
638+
f"calendar, {calendar!r}, to a pandas.DatetimeIndex, which uses dates "
640639
"from the standard calendar. This may lead to subtle errors "
641640
"in operations that depend on the length of time between "
642-
"dates.".format(calendar),
641+
"dates.",
643642
RuntimeWarning,
644643
stacklevel=2,
645644
)

xarray/coding/strings.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ def encode(self, variable, name=None):
5959
if contains_unicode and (encode_as_char or not self.allows_unicode):
6060
if "_FillValue" in attrs:
6161
raise NotImplementedError(
62-
"variable {!r} has a _FillValue specified, but "
62+
f"variable {name!r} has a _FillValue specified, but "
6363
"_FillValue is not yet supported on unicode strings: "
64-
"https://github.com/pydata/xarray/issues/1647".format(name)
64+
"https://github.com/pydata/xarray/issues/1647"
6565
)
6666

6767
string_encoding = encoding.pop("_Encoding", "utf-8")
@@ -176,7 +176,7 @@ def char_to_bytes(arr):
176176
if len(arr.chunks[-1]) > 1:
177177
raise ValueError(
178178
"cannot stacked dask character array with "
179-
"multiple chunks in the last dimension: {}".format(arr)
179+
f"multiple chunks in the last dimension: {arr}"
180180
)
181181

182182
dtype = np.dtype("S" + str(arr.shape[-1]))

xarray/coding/times.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ def _decode_datetime_with_pandas(
218218
) -> np.ndarray:
219219
if not _is_standard_calendar(calendar):
220220
raise OutOfBoundsDatetime(
221-
"Cannot decode times from a non-standard calendar, {!r}, using "
222-
"pandas.".format(calendar)
221+
f"Cannot decode times from a non-standard calendar, {calendar!r}, using "
222+
"pandas."
223223
)
224224

225225
delta, ref_date = _unpack_netcdf_time_units(units)
@@ -452,8 +452,8 @@ def cftime_to_nptime(times, raise_on_invalid: bool = True) -> np.ndarray:
452452
except ValueError as e:
453453
if raise_on_invalid:
454454
raise ValueError(
455-
"Cannot convert date {} to a date in the "
456-
"standard calendar. Reason: {}.".format(t, e)
455+
f"Cannot convert date {t} to a date in the "
456+
f"standard calendar. Reason: {e}."
457457
)
458458
else:
459459
dt = "NaT"
@@ -485,10 +485,8 @@ def convert_times(times, date_type, raise_on_invalid: bool = True) -> np.ndarray
485485
except ValueError as e:
486486
if raise_on_invalid:
487487
raise ValueError(
488-
"Cannot convert date {} to a date in the "
489-
"{} calendar. Reason: {}.".format(
490-
t, date_type(2000, 1, 1).calendar, e
491-
)
488+
f"Cannot convert date {t} to a date in the "
489+
f"{date_type(2000, 1, 1).calendar} calendar. Reason: {e}."
492490
)
493491
else:
494492
dt = np.NaN

xarray/coding/variables.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ def safe_setitem(dest, key: Hashable, value, name: T_Name = None):
179179
if key in dest:
180180
var_str = f" on variable {name!r}" if name else ""
181181
raise ValueError(
182-
"failed to prevent overwriting existing key {} in attrs{}. "
182+
f"failed to prevent overwriting existing key {key} in attrs{var_str}. "
183183
"This is probably an encoding field used by xarray to describe "
184184
"how a variable is serialized. To proceed, remove this key from "
185-
"the variable's attributes manually.".format(key, var_str)
185+
"the variable's attributes manually."
186186
)
187187
dest[key] = value
188188

xarray/conventions.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,18 @@ def _infer_dtype(array, name: T_Name = None) -> np.dtype:
7575
return dtype
7676

7777
raise ValueError(
78-
"unable to infer dtype on variable {!r}; xarray "
79-
"cannot serialize arbitrary Python objects".format(name)
78+
f"unable to infer dtype on variable {name!r}; xarray "
79+
"cannot serialize arbitrary Python objects"
8080
)
8181

8282

8383
def ensure_not_multiindex(var: Variable, name: T_Name = None) -> None:
8484
if isinstance(var, IndexVariable) and isinstance(var.to_index(), pd.MultiIndex):
8585
raise NotImplementedError(
86-
"variable {!r} is a MultiIndex, which cannot yet be "
86+
f"variable {name!r} is a MultiIndex, which cannot yet be "
8787
"serialized to netCDF files. Instead, either use reset_index() "
8888
"to convert MultiIndex levels into coordinate variables instead "
89-
"or use https://cf-xarray.readthedocs.io/en/latest/coding.html.".format(
90-
name
91-
)
89+
"or use https://cf-xarray.readthedocs.io/en/latest/coding.html."
9290
)
9391

9492

@@ -114,11 +112,11 @@ def ensure_dtype_not_object(var: Variable, name: T_Name = None) -> Variable:
114112

115113
if is_duck_dask_array(data):
116114
warnings.warn(
117-
"variable {} has data in the form of a dask array with "
115+
f"variable {name} has data in the form of a dask array with "
118116
"dtype=object, which means it is being loaded into memory "
119117
"to determine a data type that can be safely stored on disk. "
120118
"To avoid this, coerce this variable to a fixed-size dtype "
121-
"with astype() before saving it.".format(name),
119+
"with astype() before saving it.",
122120
SerializationWarning,
123121
)
124122
data = data.compute()
@@ -635,9 +633,9 @@ def _encode_coordinates(variables, attributes, non_dim_coord_names):
635633
for name in list(non_dim_coord_names):
636634
if isinstance(name, str) and " " in name:
637635
warnings.warn(
638-
"coordinate {!r} has a space in its name, which means it "
636+
f"coordinate {name!r} has a space in its name, which means it "
639637
"cannot be marked as a coordinate on disk and will be "
640-
"saved as a data variable instead".format(name),
638+
"saved as a data variable instead",
641639
SerializationWarning,
642640
stacklevel=6,
643641
)

xarray/core/alignment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ def is_alignable(obj):
839839
elif raise_on_invalid:
840840
raise ValueError(
841841
"object to align is neither an xarray.Dataset, "
842-
"an xarray.DataArray nor a dictionary: {!r}".format(variables)
842+
f"an xarray.DataArray nor a dictionary: {variables!r}"
843843
)
844844
else:
845845
out.append(variables)

xarray/core/arithmetic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
5656

5757
if ufunc.signature is not None:
5858
raise NotImplementedError(
59-
"{} not supported: xarray objects do not directly implement "
59+
f"{ufunc} not supported: xarray objects do not directly implement "
6060
"generalized ufuncs. Instead, use xarray.apply_ufunc or "
6161
"explicitly convert to xarray objects to NumPy arrays "
62-
"(e.g., with `.values`).".format(ufunc)
62+
"(e.g., with `.values`)."
6363
)
6464

6565
if method != "__call__":

0 commit comments

Comments
 (0)