Skip to content

Commit

Permalink
Port fix from pandas-dev/pandas#55283 to cftime resample [test-upstream]
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerkclark committed Oct 31, 2023
1 parent f63ede9 commit 272c689
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
7 changes: 7 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ Deprecations
Bug fixes
~~~~~~~~~

- Port `bug fix from pandas <https://github.com/pandas-dev/pandas/pull/55283>`_
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
<https://github.com/spencerkclark>`_.

Documentation
~~~~~~~~~~~~~
Expand Down
12 changes: 2 additions & 10 deletions xarray/core/resample_cftime.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@

from xarray.coding.cftime_offsets import (
BaseCFTimeOffset,
Day,
MonthEnd,
QuarterEnd,
Tick,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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():
Expand Down

0 comments on commit 272c689

Please sign in to comment.