diff --git a/doc/whats-new.rst b/doc/whats-new.rst index b24a19c9129..18c0f3fc3f1 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -43,6 +43,13 @@ Deprecations Bug fixes ~~~~~~~~~ +- Port `bug fix from pandas `_ + to eliminate the adjustment of resample bin edges in the case that the + resampling frequency has units of days and is greater than one day + (e.g. ``"2D"``, ``"3D"`` etc.) and the ``closed`` argument is set to + ``"right"`` to xarray's implementation of resample for data indexed by a + :py:class:`CFTimeIndex` (:pull:`8393`). By `Spencer Clark + `_. Documentation ~~~~~~~~~~~~~ diff --git a/xarray/core/resample_cftime.py b/xarray/core/resample_cftime.py index 43edbc08456..5e3f2f57397 100644 --- a/xarray/core/resample_cftime.py +++ b/xarray/core/resample_cftime.py @@ -45,7 +45,6 @@ from xarray.coding.cftime_offsets import ( BaseCFTimeOffset, - Day, MonthEnd, QuarterEnd, Tick, @@ -254,8 +253,7 @@ def _adjust_bin_edges( labels: np.ndarray, ): """This is required for determining the bin edges resampling with - daily frequencies greater than one day, month end, and year end - frequencies. + month end, quarter end, and year end frequencies. Consider the following example. Let's say you want to downsample the time series with the following coordinates to month end frequency: @@ -283,14 +281,8 @@ def _adjust_bin_edges( The labels are still: CFTimeIndex([2000-01-31 00:00:00, 2000-02-29 00:00:00], dtype='object') - - This is also required for daily frequencies longer than one day and - year-end frequencies. """ - is_super_daily = isinstance(freq, (MonthEnd, QuarterEnd, YearEnd)) or ( - isinstance(freq, Day) and freq.n > 1 - ) - if is_super_daily: + if isinstance(freq, (MonthEnd, QuarterEnd, YearEnd)): if closed == "right": datetime_bins = datetime_bins + datetime.timedelta(days=1, microseconds=-1) if datetime_bins[-2] > index.max():