home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 1973088408

This data as json

id node_id number title user state locked assignee milestone comments created_at updated_at closed_at author_association active_lock_reason draft pull_request body reactions performed_via_github_app state_reason repo type
1973088408 I_kwDOAMm_X851mvCY 8399 Dataset.resample fails with certain time offset strings provided to the loffset parameter 7872563 closed 0     3 2023-11-01T20:48:04Z 2023-11-08T00:52:07Z 2023-11-08T00:52:07Z CONTRIBUTOR      

What happened?

resample fails with offset aliases provided to the loffset argument that do not result in unambiguous timedelta values following pydata/xarray#7206. We're running into this over on NCAR/geocat-comp.

I realize the loffset argument is slated to be deprecated anyway, but wanted to at least document this for others who might run into it. Especially since #7596 is still open and the time offset arithmetic gets a little tricky with cftime.

What did you expect to happen?

The operation to complete without error.

Minimal Complete Verifiable Example

```Python import xarray as xr import numpy as np

dates = xr.cftime_range(start="0001", periods=24, freq="MS", calendar="noleap") da = xr.DataArray(np.arange(24), coords=[dates], dims=["time"], name="foo") dar = da.resample({'time':'QS-DEC'},loffset='MS').mean() ```

MVCE confirmation

  • [X] Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • [X] Complete example — the example is self-contained, including all data and the text of any traceback.
  • [X] Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • [X] New issue — a search of GitHub Issues suggests this is not a duplicate.
  • [X] Recent environment — the issue occurs with the latest version of xarray and its dependencies.

Relevant log output

Python <stdin>:1: FutureWarning: Following pandas, the `loffset` parameter to resample will be deprecated in a future version of xarray. Switch to using time offset arithmetic. Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/username/miniconda3/envs/pandas/lib/python3.12/site-packages/xarray/core/dataarray.py", line 7087, in resample return self._resample( ^^^^^^^^^^^^^^^ File "/Users/username/miniconda3/envs/pandas/lib/python3.12/site-packages/xarray/core/common.py", line 1055, in _resample return resample_cls( ^^^^^^^^^^^^^ File "/Users//miniconda3/envs/pandas/lib/python3.12/site-packages/xarray/core/resample.py", line 49, in __init__ super().__init__(*args, **kwargs) File "/Users/username/miniconda3/envs/pandas/lib/python3.12/site-packages/xarray/core/groupby.py", line 729, in __init__ grouper_.factorize(squeeze) File "/Users/username/miniconda3/envs/pandas/lib/python3.12/site-packages/xarray/core/groupby.py", line 377, in factorize ) = self._factorize(squeeze) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/username/miniconda3/envs/pandas/lib/python3.12/site-packages/xarray/core/groupby.py", line 546, in _factorize full_index, first_items, codes_ = self._get_index_and_items() ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/username/miniconda3/envs/pandas/lib/python3.12/site-packages/xarray/core/groupby.py", line 519, in _get_index_and_items first_items, codes = self.first_items() ^^^^^^^^^^^^^^^^^^ File "/Users/username/miniconda3/envs/pandas/lib/python3.12/site-packages/xarray/core/groupby.py", line 531, in first_items return self.index_grouper.first_items(self.group_as_index) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/username/miniconda3/envs/pandas/lib/python3.12/site-packages/xarray/core/resample_cftime.py", line 155, in first_items labels = labels + pd.to_timedelta(self.loffset) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/username/miniconda3/envs/pandas/lib/python3.12/site-packages/pandas/core/tools/timedeltas.py", line 223, in to_timedelta return _coerce_scalar_to_timedelta_type(arg, unit=unit, errors=errors) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/username/miniconda3/envs/pandas/lib/python3.12/site-packages/pandas/core/tools/timedeltas.py", line 233, in _coerce_scalar_to_timedelta_type result = Timedelta(r, unit) ^^^^^^^^^^^^^^^^^^ File "timedeltas.pyx", line 1820, in pandas._libs.tslibs.timedeltas.Timedelta.__new__ File "timedeltas.pyx", line 653, in pandas._libs.tslibs.timedeltas.parse_timedelta_string ValueError: unit abbreviation w/o a number

Anything else we need to know?

No response

Environment

INSTALLED VERSIONS ------------------ commit: None python: 3.12.0 | packaged by conda-forge | (main, Oct 3 2023, 08:36:57) [Clang 15.0.7 ] python-bits: 64 OS: Darwin OS-release: 21.6.0 machine: arm64 processor: arm byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: ('en_US', 'UTF-8') libhdf5: None libnetcdf: None xarray: 2023.10.1 pandas: 2.1.2 numpy: 1.26.0 scipy: None netCDF4: None pydap: None h5netcdf: None h5py: None Nio: None zarr: None cftime: 1.6.3 nc_time_axis: None PseudoNetCDF: None iris: None bottleneck: None dask: None distributed: None matplotlib: 3.8.0 cartopy: None seaborn: None numbagg: None fsspec: None cupy: None pint: None sparse: None flox: None numpy_groupies: None setuptools: 68.2.2 pip: 23.3.1 conda: None pytest: None mypy: None IPython: None sphinx: None
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/8399/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed 13221727 issue

Links from other tables

  • 2 rows from issues_id in issues_labels
  • 0 rows from issue in issue_comments
Powered by Datasette · Queries took 158.158ms · About: xarray-datasette