Skip to content

Simplify chained comparison between the operands #10447

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 1 commit into from
Jun 27, 2025
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
14 changes: 6 additions & 8 deletions xarray/coding/cftime_offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,20 +289,18 @@ def _shift_month(date, months, day_option: DayOption = "start"):
_ = attempt_import("cftime")

has_year_zero = date.has_year_zero
delta_year = (date.month + months) // 12
year = date.year + (date.month + months) // 12
month = (date.month + months) % 12

if month == 0:
month = 12
delta_year = delta_year - 1
year -= 1

if not has_year_zero:
if date.year < 0 and date.year + delta_year >= 0:
delta_year = delta_year + 1
elif date.year > 0 and date.year + delta_year <= 0:
delta_year = delta_year - 1

year = date.year + delta_year
if date.year < 0 <= year:
year += 1
elif year <= 0 < date.year:
year -= 1

# Silence warnings associated with generating dates with years < 1.
with warnings.catch_warnings():
Expand Down
4 changes: 1 addition & 3 deletions xarray/plot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,7 @@ def _determine_cmap_params(
isinstance(levels, Iterable) and levels[0] * levels[-1] < 0
)
# kwargs not specific about divergent or not: infer defaults from data
divergent = (
((vmin < 0) and (vmax > 0)) or not center_is_none or levels_are_divergent
)
divergent = (vmin < 0 < vmax) or not center_is_none or levels_are_divergent
else:
divergent = False

Expand Down
Loading