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 1757818699,PR_kwDOAMm_X85TCxk8,7920,Fix regression with grouper object on an IndexVariable,895458,closed,0,,,5,2023-06-14T23:57:40Z,2023-06-22T18:00:31Z,2023-06-22T16:10:12Z,CONTRIBUTOR,,0,pydata/xarray/pulls/7920,"- [X] Closes #7919 - [X] Tests added - [ ] User visible changes (including notable bug fixes) are documented in `whats-new.rst` - [ ] New functions/methods are listed in `api.rst` ","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/7920/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,,13221727,pull 1757661617,I_kwDOAMm_X85ow8mx,7919,Grouper object does not handle IndexVariable,895458,closed,0,,,2,2023-06-14T21:17:55Z,2023-06-22T16:10:13Z,2023-06-22T16:10:13Z,CONTRIBUTOR,,,,"### What happened? Since #7561 with xarray-2023.5.0, the new grouper object raises an unexpected exception with an IndexVariable. ### What did you expect to happen? With xarray-2023.3.0 there was no issue, the grouper operation returned a new DataArray object. ### Minimal Complete Verifiable Example ```Python import numpy as np import pandas as pd import xarray as xr da = xr.DataArray( np.linspace(0, 1826, num=1827), coords=[pd.date_range(""2000-01-01"", ""2004-12-31"", freq=""D"")], dims=""time"", ) iv = xr.IndexVariable(dims=(""time"",), data=pd.Index(da.time.dt.year)) # This is where the exception is raised m = da.groupby(iv).mean() print(m) ``` ### 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](https://mybinder.org/v2/gh/pydata/xarray/main?urlpath=lab/tree/doc/examples/blank_template.ipynb), returning the result. - [X] New issue — a search of GitHub Issues suggests this is not a duplicate. ### Relevant log output ```Python --------------------------------------------------------------------------- UnboundLocalError Traceback (most recent call last) Cell In[1], line 13 10 iv = xr.IndexVariable(dims=(""time"",), data=pd.Index(da.time.dt.year)) 12 # This is where the exception is raised ---> 13 m = da.groupby(iv).mean() 14 print(m) File /tmp/py310/lib/python3.10/site-packages/xarray/core/dataarray.py:6503, in DataArray.groupby(self, group, squeeze, restore_coord_dims) 6495 from xarray.core.groupby import ( 6496 DataArrayGroupBy, 6497 ResolvedUniqueGrouper, 6498 UniqueGrouper, 6499 _validate_groupby_squeeze, 6500 ) 6502 _validate_groupby_squeeze(squeeze) -> 6503 rgrouper = ResolvedUniqueGrouper(UniqueGrouper(), group, self) 6504 return DataArrayGroupBy( 6505 self, 6506 (rgrouper,), 6507 squeeze=squeeze, 6508 restore_coord_dims=restore_coord_dims, 6509 ) File :6, in __init__(self, grouper, group, obj) File /tmp/py310/lib/python3.10/site-packages/xarray/core/groupby.py:335, in ResolvedGrouper.__post_init__(self) 334 def __post_init__(self) -> None: --> 335 self.group: T_Group = _resolve_group(self.obj, self.group) 337 ( 338 self.group1d, 339 self.stacked_obj, 340 self.stacked_dim, 341 self.inserted_dims, 342 ) = _ensure_1d(group=self.group, obj=self.obj) File /tmp/py310/lib/python3.10/site-packages/xarray/core/groupby.py:640, in _resolve_group(obj, group) 637 else: 638 newgroup = group --> 640 if newgroup.size == 0: 641 raise ValueError(f""{newgroup.name} must not be empty"") 643 return newgroup UnboundLocalError: local variable 'newgroup' referenced before assignment ``` ### Anything else we need to know? With xarray-2023.3.0 the output for the example is: ``` array([ 182.5, 548. , 913. , 1278. , 1643.5]) Coordinates: * time (time) int64 2000 2001 2002 2003 2004 ``` ### Environment
INSTALLED VERSIONS ------------------ commit: None python: 3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0] python-bits: 64 OS: Linux OS-release: 4.4.0-19041-Microsoft machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: C.UTF-8 LOCALE: ('en_US', 'UTF-8') libhdf5: None libnetcdf: None xarray: 2023.5.0 pandas: 1.5.3 numpy: 1.24.3 scipy: None netCDF4: None pydap: None h5netcdf: None h5py: None Nio: None zarr: None cftime: None nc_time_axis: None PseudoNetCDF: None iris: None bottleneck: None dask: None distributed: None matplotlib: 3.7.1 cartopy: None seaborn: None numbagg: None fsspec: None cupy: None pint: None sparse: None flox: None numpy_groupies: None setuptools: 59.6.0 pip: 23.1.2 conda: None pytest: 7.3.1 mypy: None IPython: 8.13.2 sphinx: None
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/7919/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue 1434498245,PR_kwDOAMm_X85CINe7,7253,"Remove setuptools-scm-git-archive, require setuptools-scm>=7",895458,closed,0,,,2,2022-11-03T11:22:31Z,2022-12-01T19:17:38Z,2022-12-01T19:17:37Z,CONTRIBUTOR,,0,pydata/xarray/pulls/7253,"Since June 2022, [setuptools_scm_git_archive](https://github.com/Changaco/setuptools_scm_git_archive) is obsolete since ""setuptools_scm >= 7.0.0 supports Git archives by itself"". This PR follows the migration guide to update `.git_archival.txt`, and establish `setuptools-scm>=7` in `pyproject.toml`.","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/7253/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,,13221727,pull 1359451944,PR_kwDOAMm_X84-Pkru,6979,"Remove unnecessary build dependencies, use build defaults, strict twine check",895458,closed,0,,,3,2022-09-01T21:58:42Z,2022-09-10T07:34:25Z,2022-09-10T06:13:28Z,CONTRIBUTOR,,0,pydata/xarray/pulls/6979,"This PR does a few related things: - Remove `wheel` from `pyproject.toml`, since it is no longer needed/documented (e.g. [here](https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html)), and rename other dependencies to their names in PyPI - Remove `pip install` build dependencies already specified in `pyproject.toml` - Remove [`check-manifest`](https://pypi.org/project/check-manifest/), since it isn't used - The command `python -m build` has defaults to build both sdist and wheel outputs - Use `twine check --strict` to return non-zero status on warnings","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/6979/reactions"", ""total_count"": 1, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 1, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,,13221727,pull 1359532011,PR_kwDOAMm_X84-P2pa,6980,"Improve CITATION.cff, specify license version in metadata",895458,closed,0,,,1,2022-09-01T23:28:51Z,2022-09-03T18:11:29Z,2022-09-03T13:19:44Z,CONTRIBUTOR,,0,pydata/xarray/pulls/6980,"This PR improves CITATION.cff to add abstract, license and repository-code fields, and to modify url to https://xarray.dev/ Also, update the metadata licence from ""Apache"", to ""[Apache-2.0](https://spdx.org/licenses/Apache-2.0.html)"", which is the short identifier defined by SPDX.","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/6980/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,,13221727,pull 1031275532,PR_kwDOAMm_X84tbs_K,5879,"Check for path-like objects rather than Path type, use os.fspath",895458,closed,0,,,14,2021-10-20T11:05:56Z,2022-03-31T21:41:32Z,2021-10-27T22:38:21Z,CONTRIBUTOR,,0,pydata/xarray/pulls/5879,"This PR generally changes (e.g.) `isinstance(filename, pathlib.Path)` to `isinstance(filename, os.PathLike)`, and uses `os.fspath` to convert it to (usually) `str` type. (If it is vital these are always `str`, then should [`os.fsdecode`](https://docs.python.org/3/library/os.html#os.fsdecode) be considered? `bytes` paths are not common, and only possible on some platforms). If other path-like objects are used e.g. [py.path](https://py.readthedocs.io/en/latest/path.html) used by the [tmpdir pytest fixture](https://docs.pytest.org/en/6.2.x/tmpdir.html#the-tmpdir-fixture), an error message is shown: > ValueError: can only read bytes or file-like objects with engine='scipy' or 'h5netcdf' This PR allows other path-like objects to be used. A few typing objects are also adjusted too. --- Be aware there are [file-like](https://docs.python.org/3/glossary.html#term-file-like-object) and [path-like](https://docs.python.org/3/glossary.html#term-path-like-object) object terms used in the core Python glossary. In light of this, some ""file-like"" wordings may need to be adjusted, such as the error message described above. This can be done in this PR if anyone aggrees.","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/5879/reactions"", ""total_count"": 3, ""+1"": 3, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,,13221727,pull 995409132,MDExOlB1bGxSZXF1ZXN0NzMzMTc1MDAw,5793,MAINT: IOError -> OSError,895458,closed,0,,,6,2021-09-13T22:51:45Z,2021-09-15T20:55:07Z,2021-09-15T18:18:30Z,CONTRIBUTOR,,0,pydata/xarray/pulls/5793,IOError has been an alias of [OSError](https://docs.python.org/3/library/exceptions.html#OSError) since Python 3.3 (see [PEP 3151](https://www.python.org/dev/peps/pep-3151/)).,"{""url"": ""https://api.github.com/repos/pydata/xarray/issues/5793/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,,13221727,pull