Skip to content

Enforce ruff/flake8-simplify rules (SIM) #10462

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 8 commits into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Apply ruff/flake8-simplify rule SIM102
SIM102 Use a single `if` statement instead of nested `if` statements
  • Loading branch information
DimitriPapadopoulos committed Jun 29, 2025
commit 18e4381b70c9dee6a722c2355bb72af9dc2b007a
2 changes: 1 addition & 1 deletion xarray/coding/times.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ def infer_calendar_name(dates) -> CFCalendar:
"""Given an array of datetimes, infer the CF calendar name"""
if is_np_datetime_like(dates.dtype):
return "proleptic_gregorian"
elif dates.dtype == np.dtype("O") and dates.size > 0:
elif dates.dtype == np.dtype("O") and dates.size > 0: # noqa: SIM102
# Logic copied from core.common.contains_cftime_datetimes.
if cftime is not None:
sample = np.asarray(dates).flat[0]
Expand Down
14 changes: 8 additions & 6 deletions xarray/core/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -989,9 +989,10 @@ def diff_array_repr(a, b, compat):
):
summary.append(coords_diff)

if compat == "identical":
if attrs_diff := diff_attrs_repr(a.attrs, b.attrs, compat):
summary.append(attrs_diff)
if compat == "identical" and (
attrs_diff := diff_attrs_repr(a.attrs, b.attrs, compat)
):
summary.append(attrs_diff)

return "\n".join(summary)

Expand Down Expand Up @@ -1029,9 +1030,10 @@ def diff_dataset_repr(a, b, compat):
):
summary.append(data_diff)

if compat == "identical":
if attrs_diff := diff_attrs_repr(a.attrs, b.attrs, compat):
summary.append(attrs_diff)
if compat == "identical" and (
attrs_diff := diff_attrs_repr(a.attrs, b.attrs, compat)
):
summary.append(attrs_diff)

return "\n".join(summary)

Expand Down
7 changes: 4 additions & 3 deletions xarray/plot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,10 @@ def _infer_xy_labels(
_assert_valid_xy(darray, x, "x")
_assert_valid_xy(darray, y, "y")

if darray._indexes.get(x, 1) is darray._indexes.get(y, 2):
if isinstance(darray._indexes[x], PandasMultiIndex):
raise ValueError("x and y cannot be levels of the same MultiIndex")
if darray._indexes.get(x, 1) is darray._indexes.get(y, 2) and isinstance(
darray._indexes[x], PandasMultiIndex
):
raise ValueError("x and y cannot be levels of the same MultiIndex")

return x, y

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy