Skip to content

Commit 272c689

Browse files
committed
Port fix from pandas-dev/pandas#55283 to cftime resample [test-upstream]
1 parent f63ede9 commit 272c689

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

doc/whats-new.rst

+7
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ Deprecations
4343
Bug fixes
4444
~~~~~~~~~
4545

46+
- Port `bug fix from pandas <https://github.com/pandas-dev/pandas/pull/55283>`_
47+
to eliminate the adjustment of resample bin edges in the case that the
48+
resampling frequency has units of days and is greater than one day
49+
(e.g. ``"2D"``, ``"3D"`` etc.) and the ``closed`` argument is set to
50+
``"right"`` to xarray's implementation of resample for data indexed by a
51+
:py:class:`CFTimeIndex` (:pull:`8393`). By `Spencer Clark
52+
<https://github.com/spencerkclark>`_.
4653

4754
Documentation
4855
~~~~~~~~~~~~~

xarray/core/resample_cftime.py

+2-10
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545

4646
from xarray.coding.cftime_offsets import (
4747
BaseCFTimeOffset,
48-
Day,
4948
MonthEnd,
5049
QuarterEnd,
5150
Tick,
@@ -254,8 +253,7 @@ def _adjust_bin_edges(
254253
labels: np.ndarray,
255254
):
256255
"""This is required for determining the bin edges resampling with
257-
daily frequencies greater than one day, month end, and year end
258-
frequencies.
256+
month end, quarter end, and year end frequencies.
259257
260258
Consider the following example. Let's say you want to downsample the
261259
time series with the following coordinates to month end frequency:
@@ -283,14 +281,8 @@ def _adjust_bin_edges(
283281
The labels are still:
284282
285283
CFTimeIndex([2000-01-31 00:00:00, 2000-02-29 00:00:00], dtype='object')
286-
287-
This is also required for daily frequencies longer than one day and
288-
year-end frequencies.
289284
"""
290-
is_super_daily = isinstance(freq, (MonthEnd, QuarterEnd, YearEnd)) or (
291-
isinstance(freq, Day) and freq.n > 1
292-
)
293-
if is_super_daily:
285+
if isinstance(freq, (MonthEnd, QuarterEnd, YearEnd)):
294286
if closed == "right":
295287
datetime_bins = datetime_bins + datetime.timedelta(days=1, microseconds=-1)
296288
if datetime_bins[-2] > index.max():

0 commit comments

Comments
 (0)