Skip to content

Commit 58d8387

Browse files
Enforce ruff/refurb rules (FURB) (#10367)
* Apply ruff/refurb rule FURB136 FURB136 Replace `x if x >= y else y` with `max(x, y)` * Apply ruff/refurb rule FURB167 FURB167 Use of regular expression alias The abbreviated flags seem less readable, although experienced programers might know the abbreviated flags match inline flags. * Enforce ruff/refurb rules (FURB)
1 parent 2c10583 commit 58d8387

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ extend-select = [
258258
"TID", # flake8-tidy-imports (absolute imports)
259259
"PGH", # pygrep-hooks
260260
"PERF", # Perflint
261+
"FURB", # refurb
261262
"RUF",
262263
]
263264
extend-safe-fixes = [
@@ -270,6 +271,7 @@ ignore = [
270271
"C40", # unnecessary generator, comprehension, or literal
271272
"PIE790", # unnecessary pass statement
272273
"PERF203", # try-except within a loop incurs performance overhead
274+
"FURB105", # unnecessary empty string passed to `print`
273275
"RUF001", # string contains ambiguous unicode character
274276
"RUF002", # docstring contains ambiguous acute accent unicode character
275277
"RUF003", # comment contains ambiguous no-break space unicode character

xarray/core/accessor_str.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1944,7 +1944,7 @@ def replace(
19441944
if regex:
19451945
pat = self._re_compile(pat=pat, flags=flags, case=case)
19461946
func = lambda x, ipat, irepl, i_n: ipat.sub(
1947-
repl=irepl, string=x, count=i_n if i_n >= 0 else 0
1947+
repl=irepl, string=x, count=max(i_n, 0)
19481948
)
19491949
else:
19501950
pat = self._stringify(pat)

xarray/tests/test_accessor_str.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ def test_extractall_single_single_nocase(dtype) -> None:
906906
pat_re: str | bytes = (
907907
pat_str if dtype == np.str_ else bytes(pat_str, encoding="UTF-8")
908908
)
909-
pat_compiled = re.compile(pat_re, flags=re.I)
909+
pat_compiled = re.compile(pat_re, flags=re.IGNORECASE)
910910

911911
value = xr.DataArray(
912912
[["a_Xy_0", "ab_xY_10", "abc_Xy_01"], ["abcd_Xy_", "", "abcdef_Xy_101"]],
@@ -981,7 +981,7 @@ def test_extractall_single_multi_nocase(dtype) -> None:
981981
pat_re: str | bytes = (
982982
pat_str if dtype == np.str_ else bytes(pat_str, encoding="UTF-8")
983983
)
984-
pat_compiled = re.compile(pat_re, flags=re.I)
984+
pat_compiled = re.compile(pat_re, flags=re.IGNORECASE)
985985

986986
value = xr.DataArray(
987987
[
@@ -1063,7 +1063,7 @@ def test_extractall_multi_single_nocase(dtype) -> None:
10631063
pat_re: str | bytes = (
10641064
pat_str if dtype == np.str_ else bytes(pat_str, encoding="UTF-8")
10651065
)
1066-
pat_compiled = re.compile(pat_re, flags=re.I)
1066+
pat_compiled = re.compile(pat_re, flags=re.IGNORECASE)
10671067

10681068
value = xr.DataArray(
10691069
[["a_Xy_0", "ab_xY_10", "abc_Xy_01"], ["abcd_Xy_", "", "abcdef_Xy_101"]],
@@ -1145,7 +1145,7 @@ def test_extractall_multi_multi_nocase(dtype) -> None:
11451145
pat_re: str | bytes = (
11461146
pat_str if dtype == np.str_ else bytes(pat_str, encoding="UTF-8")
11471147
)
1148-
pat_compiled = re.compile(pat_re, flags=re.I)
1148+
pat_compiled = re.compile(pat_re, flags=re.IGNORECASE)
11491149

11501150
value = xr.DataArray(
11511151
[
@@ -1245,7 +1245,7 @@ def test_findall_single_single_case(dtype) -> None:
12451245

12461246
def test_findall_single_single_nocase(dtype) -> None:
12471247
pat_str = r"(\w+)_Xy_\d*"
1248-
pat_re = re.compile(dtype(pat_str), flags=re.I)
1248+
pat_re = re.compile(dtype(pat_str), flags=re.IGNORECASE)
12491249

12501250
value = xr.DataArray(
12511251
[["a_Xy_0", "ab_xY_10", "abc_Xy_01"], ["abcd_Xy_", "", "abcdef_Xy_101"]],
@@ -1313,7 +1313,7 @@ def test_findall_single_multi_case(dtype) -> None:
13131313

13141314
def test_findall_single_multi_nocase(dtype) -> None:
13151315
pat_str = r"(\w+)_Xy_\d*"
1316-
pat_re = re.compile(dtype(pat_str), flags=re.I)
1316+
pat_re = re.compile(dtype(pat_str), flags=re.IGNORECASE)
13171317

13181318
value = xr.DataArray(
13191319
[
@@ -1387,7 +1387,7 @@ def test_findall_multi_single_case(dtype) -> None:
13871387

13881388
def test_findall_multi_single_nocase(dtype) -> None:
13891389
pat_str = r"(\w+)_Xy_(\d*)"
1390-
pat_re = re.compile(dtype(pat_str), flags=re.I)
1390+
pat_re = re.compile(dtype(pat_str), flags=re.IGNORECASE)
13911391

13921392
value = xr.DataArray(
13931393
[["a_Xy_0", "ab_xY_10", "abc_Xy_01"], ["abcd_Xy_", "", "abcdef_Xy_101"]],
@@ -1463,7 +1463,7 @@ def test_findall_multi_multi_case(dtype) -> None:
14631463

14641464
def test_findall_multi_multi_nocase(dtype) -> None:
14651465
pat_str = r"(\w+)_Xy_(\d*)"
1466-
pat_re = re.compile(dtype(pat_str), flags=re.I)
1466+
pat_re = re.compile(dtype(pat_str), flags=re.IGNORECASE)
14671467

14681468
value = xr.DataArray(
14691469
[

0 commit comments

Comments
 (0)