Skip to content

Commit 827696b

Browse files
Enforce ruff/Pylint Refactor rules (PLR) (#10459)
* Ignore ruff/Pylint rule PLR0124 PLR0124 Name compared with itself * Apply ruff/Pylint rule PLR5501 PLR5501 Use `elif` instead of `else` then `if`, to reduce indentation * Enforce ruff/Pylint Refactor rules (PLR)
1 parent d4681da commit 827696b

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ extend-select = [
261261
"W", # pycodestyle warnings
262262
"PGH", # pygrep-hooks
263263
"PLE", # Pylint Errors
264+
"PLR", # Pylint Refactor
264265
"PLW", # Pylint Warnings
265266
"UP", # pyupgrade
266267
"FURB", # refurb
@@ -277,6 +278,8 @@ ignore = [
277278
"PERF203", # try-except within a loop incurs performance overhead
278279
"E402", # module level import not at top of file
279280
"E731", # do not assign a lambda expression, use a def
281+
"PLR091", # too many arguments / branches / statements
282+
"PLR2004", # magic value used in comparison
280283
"PLW0603", # using the global statement to update is discouraged
281284
"PLW0642", # reassigned `self` variable in instance method
282285
"PLW1641", # object does not implement `__hash__` method
@@ -293,6 +296,8 @@ ignore = [
293296
[tool.ruff.lint.per-file-ignores]
294297
# don't enforce absolute imports
295298
"asv_bench/**" = ["TID252"]
299+
# comparison with itself in tests
300+
"xarray/tests/**" = ["PLR0124"]
296301
# looks like ruff bugs
297302
"xarray/core/_typed_ops.py" = ["PYI034"]
298303
"xarray/namedarray/_typing.py" = ["PYI018", "PYI046"]

xarray/coding/strings.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,14 @@ def validate_char_dim_name(strlen, encoding, name) -> str:
129129
"To silence this warning either remove 'char_dim_name' from encoding or provide a fitting name."
130130
)
131131
char_dim_name = f"{new_dim_name}{strlen}"
132-
else:
133-
if (
134-
original_shape := encoding.get("original_shape", [-1])[-1]
135-
) != -1 and original_shape != strlen:
136-
emit_user_level_warning(
137-
f"String dimension length mismatch on variable {name!r}. '{original_shape}' provided by encoding, but data has length of '{strlen}'. Using '{char_dim_name}{strlen}' instead of {char_dim_name!r} to prevent possible naming clash.\n"
138-
f"To silence this warning remove 'original_shape' from encoding."
139-
)
140-
char_dim_name = f"{char_dim_name}{strlen}"
132+
elif (
133+
original_shape := encoding.get("original_shape", [-1])[-1]
134+
) != -1 and original_shape != strlen:
135+
emit_user_level_warning(
136+
f"String dimension length mismatch on variable {name!r}. '{original_shape}' provided by encoding, but data has length of '{strlen}'. Using '{char_dim_name}{strlen}' instead of {char_dim_name!r} to prevent possible naming clash.\n"
137+
f"To silence this warning remove 'original_shape' from encoding."
138+
)
139+
char_dim_name = f"{char_dim_name}{strlen}"
141140
else:
142141
char_dim_name = f"string{strlen}"
143142

xarray/core/duck_array_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def isnull(data):
193193
# types. For full consistency with pandas, we should accept None as
194194
# a null value as well as NaN, but it isn't clear how to do this
195195
# with duck typing.
196-
return data != data
196+
return data != data # noqa: PLR0124
197197

198198

199199
def notnull(data):

0 commit comments

Comments
 (0)