-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
cftime resampling error #9108
Comments
Can you show the output of
|
Here are the versions:
I get a bunch of these warnings too:
|
Yeah, I get those warnings too. We may decide to do something to silence those, but I think that's a separate issue (not that it necessarily excuses it, but I think they have existed for a while for this case). Weirdly I still cannot reproduce the
This is the only diff in versions:
|
Here's a minimal reproducer import xarray as xr
from xarray.coding.cftime_offsets import MonthEnd
from xarray.core.resample_cftime import _get_time_bins
index = xr.date_range("0001-01-01", periods=10, freq="D")
datetime_bins, label = _get_time_bins(
index,
freq=MonthEnd(1),
closed="right",
label="right",
origin="start_day",
offset=None,
)
print(repr(datetime_bins[0]), '\n', repr(index[0]))
datetime_bins[0] < index[0] # should be True! The output is
The two have different So if I choose to start with year 2 it's all fine. |
Thanks @dcherian—that diagnosis was super helpful. It makes sense that this is sort of an edge case, given that our original tests did not catch it. I think the issue is likely in here: xarray/xarray/coding/cftime_offsets.py Lines 301 to 321 in 8c8d097
In other words we need to ensure that we take whether has_year_zero is True or False into account when computing the new year when shifting months (this is what ends up creating the instance with has_year_zero=True in the example). When I get a chance I'll see if I can push a fix to #9116.
|
Thanks! Why would this be OS-dependent though? |
There may be an underlying cftime issue related to comparison, e.g. this comparison is
but regardless I think generating dates with mismatched |
* Add test for #9108 * Update xarray/tests/test_groupby.py Co-authored-by: Spencer Clark <[email protected]> * Take has_year_zero into account in offset arithmetic * Fix test * Add whats-new * Update doc/whats-new.rst * Add more detail to what's new entry * Modify wording slightly, since this does not always happen when the time coordinate includes "0001-01-01". --------- Co-authored-by: Spencer Clark <[email protected]>
What happened?
Something is very wrong with CFTime resampling for some inputs.
What did you expect to happen?
No error
Minimal Complete Verifiable Example
The text was updated successfully, but these errors were encountered: