diff --git a/xarray/coding/cftime_offsets.py b/xarray/coding/cftime_offsets.py index 510e9dafad8..d6256e7acb1 100644 --- a/xarray/coding/cftime_offsets.py +++ b/xarray/coding/cftime_offsets.py @@ -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(): diff --git a/xarray/plot/utils.py b/xarray/plot/utils.py index a35128cadb6..dd47df703b5 100644 --- a/xarray/plot/utils.py +++ b/xarray/plot/utils.py @@ -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