html_url,issue_url,id,node_id,user,created_at,updated_at,author_association,body,reactions,performed_via_github_app,issue
https://github.com/pydata/xarray/issues/7211#issuecomment-1293975333,https://api.github.com/repos/pydata/xarray/issues/7211,1293975333,IC_kwDOAMm_X85NIH8l,35968931,2022-10-27T19:33:55Z,2022-10-27T19:40:19Z,MEMBER,"Hi @airton-neto - here is a much shorter example that reproduces the same error
```python
url = 'https://rda.ucar.edu/thredds/dodsC/files/g/ds084.1/2022/20220201/gfs.0p25.2022020100.f000.grib2'
dataset = xr.open_dataset(url, cache=True, engine=""netcdf4"")
```
```python
from dagster._utils import frozenlist
# variables = list(['u-component_of_wind_height_above_ground']) # <--- This way it runs
variables = frozenlist(['u-component_of_wind_height_above_ground'])
dataset[variables]
```
```python
--------------------------------------------------------------------------
KeyError Traceback (most recent call last)
File ~/miniconda3/envs/py39/lib/python3.9/site-packages/xarray/core/dataset.py:1317, in Dataset._construct_dataarray(self, name)
1316 try:
-> 1317 variable = self._variables[name]
1318 except KeyError:
KeyError: ['u-component_of_wind_height_above_ground']
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last)
Input In [43], in ()
----> 1 dataset[variables]
File ~/miniconda3/envs/py39/lib/python3.9/site-packages/xarray/core/dataset.py:1410, in Dataset.__getitem__(self, key)
1408 return self.isel(**key)
1409 if utils.hashable(key):
-> 1410 return self._construct_dataarray(key)
1411 if utils.iterable_of_hashable(key):
1412 return self._copy_listed(key)
File ~/miniconda3/envs/py39/lib/python3.9/site-packages/xarray/core/dataset.py:1319, in Dataset._construct_dataarray(self, name)
1317 variable = self._variables[name]
1318 except KeyError:
-> 1319 _, name, variable = _get_virtual_variable(self._variables, name, self.dims)
1321 needed_dims = set(variable.dims)
1323 coords: dict[Hashable, Variable] = {}
File ~/miniconda3/envs/py39/lib/python3.9/site-packages/xarray/core/dataset.py:171, in _get_virtual_variable(variables, key, dim_sizes)
168 return key, key, variable
170 if not isinstance(key, str):
--> 171 raise KeyError(key)
173 split_key = key.split(""."", 1)
174 if len(split_key) != 2:
KeyError: ['u-component_of_wind_height_above_ground']
```
I'm not immediately sure why the elements of the list are not properly extracted, but the `frozenlist` class is a [dagster private internal](https://github.com/dagster-io/dagster/blob/688a5d895ff265fbfb90dfb1e2876caa81051ccc/python_modules/dagster/dagster/_utils/__init__.py#L223), and the problem is specific to how that object interacts with the current xarray code. As a downstream user of xarray, can dagster not just change it's code to pass the type xarray expects (i.e. a normal `list`)?
Having said that if you want to submit a PR which fixes this bug (and doesn't require special-casing dagster somehow) then that would be welcome too!","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1422460071
|