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 502720385,MDU6SXNzdWU1MDI3MjAzODU=,3374,Key error in to_netcdf ,6943441,closed,0,,,5,2019-10-04T16:04:30Z,2023-03-14T21:14:33Z,2023-03-14T21:14:33Z,NONE,,,,"#### MCVE Code Sample ```python import xarray as xr p = range(10) ds = xr.Dataset({'precip': (['time'], p)}, coords={'time': range(10)}) ds.attrs['Conventions'] = ['COARDS', 'GrADS'] ds.to_netcdf('a.nc') ``` #### Expected Output Saves data to `a.nc` without error #### Problem Description In version `0.12.1` this works without error. In `0.12.2` it throws an error: ``` File ""xarray_error.py"", line 6, in ds.to_netcdf('a.nc') File ""C:\Users\jsadler\AppData\Local\Continuum\anaconda3\envs\nwm\lib\site-packages\xarray\core\dataset.py"", line 1365, in to_netcdf compute=compute) File ""C:\Users\jsadler\AppData\Local\Continuum\anaconda3\envs\nwm\lib\site-packages\xarray\backends\api.py"", line 900, in to_netcdf store.close() File ""C:\Users\jsadler\AppData\Local\Continuum\anaconda3\envs\nwm\lib\site-packages\xarray\backends\scipy_.py"", line 226, in close self._manager.close() File ""C:\Users\jsadler\AppData\Local\Continuum\anaconda3\envs\nwm\lib\site-packages\xarray\backends\file_manager.py"", line 188, in close file.close() File ""C:\Users\jsadler\AppData\Local\Continuum\anaconda3\envs\nwm\lib\site-packages\scipy\io\netcdf.py"", line 299, in close self.flush() File ""C:\Users\jsadler\AppData\Local\Continuum\anaconda3\envs\nwm\lib\site-packages\scipy\io\netcdf.py"", line 409, in flush self._write() File ""C:\Users\jsadler\AppData\Local\Continuum\anaconda3\envs\nwm\lib\site-packages\scipy\io\netcdf.py"", line 420, in _write self._write_gatt_array() File ""C:\Users\jsadler\AppData\Local\Continuum\anaconda3\envs\nwm\lib\site-packages\scipy\io\netcdf.py"", line 442, in _write_gatt_array self._write_att_array(self._attributes) File ""C:\Users\jsadler\AppData\Local\Continuum\anaconda3\envs\nwm\lib\site-packages\scipy\io\netcdf.py"", line 450, in _write_att_array self._write_att_values(values) File ""C:\Users\jsadler\AppData\Local\Continuum\anaconda3\envs\nwm\lib\site-packages\scipy\io\netcdf.py"", line 562, in _write_att_values nc_type = REVERSE[values.dtype.char, values.dtype.itemsize] KeyError: ('U', 24) ``` If instead the attribute is saved as as string instead of a list, it works: ```python import xarray as xr p = range(10) ds = xr.Dataset({'precip': (['time'], p)}, coords={'time': range(10)}) ds.attrs['Conventions'] = ""['COARDS', 'GrADS']"" ds.to_netcdf('a.nc') ``` #### Output of ``xr.show_versions()``
INSTALLED VERSIONS ------------------ commit: None python: 3.7.4 (default, Aug 9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)] python-bits: 64 OS: Windows OS-release: 10 machine: AMD64 processor: Intel64 Family 6 Model 158 Stepping 10, GenuineIntel byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: None.None libhdf5: None libnetcdf: None xarray: 0.12.2 pandas: 0.25.1 numpy: 1.17.1 scipy: 1.3.1 netCDF4: None pydap: installed h5netcdf: None h5py: None Nio: None zarr: 2.3.2 cftime: None nc_time_axis: None PseudonetCDF: None rasterio: None cfgrib: None iris: None bottleneck: None dask: 2.3.0 distributed: 2.5.1 matplotlib: 3.1.1 cartopy: None seaborn: None numbagg: None setuptools: 41.2.0 pip: 19.2.3 conda: None pytest: 5.1.2 IPython: 7.8.0 sphinx: None
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/3374/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue