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 422903285,MDU6SXNzdWU0MjI5MDMyODU=,2822,to_netcdf() fails to write if input is read from netcdf3_classic,5186647,closed,0,,,6,2019-03-19T19:05:01Z,2023-12-15T20:48:05Z,2023-12-15T20:48:04Z,NONE,,,,"#### Code Sample ```python import xarray as xr with xr.open_dataset('some_netcdf_classic_file') as ds: data = ds #do something with data #Neither of these work, see exception below data.to_netcdf('some_new_file', 'w') data.to_netcdf('some_new_file', 'a') #Writing back to the same file, or a new file with mode of NETCDF3_CLASSIC works data.to_netcdf('some_netcdf_classic_file', 'a') data.to_netcdf('some_new_file', 'w', 'NETCDF3_CLASSIC') ``` #### Problem description ``` File ""/home/nels.frazier/.local/lib/python2.7/site-packages/xarray/core/dataset.py"", line 1232, in to_netcdf compute=compute) File ""/home/nels.frazier/.local/lib/python2.7/site-packages/xarray/backends/api.py"", line 747, in to_netcdf unlimited_dims=unlimited_dims) File ""/home/nels.frazier/.local/lib/python2.7/site-packages/xarray/backends/api.py"", line 790, in dump_to_store unlimited_dims=unlimited_dims) File ""/home/nels.frazier/.local/lib/python2.7/site-packages/xarray/backends/common.py"", line 263, in store self.set_attributes(attributes) File ""/home/nels.frazier/.local/lib/python2.7/site-packages/xarray/backends/common.py"", line 279, in set_attributes self.set_attribute(k, v) File ""/home/nels.frazier/.local/lib/python2.7/site-packages/xarray/backends/netCDF4_.py"", line 421, in set_attribute _set_nc_attribute(self.ds, key, value) File ""/home/nels.frazier/.local/lib/python2.7/site-packages/xarray/backends/netCDF4_.py"", line 297, in _set_nc_attribute obj.setncattr(key, value) File ""netCDF4/_netCDF4.pyx"", line 2619, in netCDF4._netCDF4.Dataset.setncattr File ""netCDF4/_netCDF4.pyx"", line 1479, in netCDF4._netCDF4._set_att File ""netCDF4/_netCDF4.pyx"", line 1745, in netCDF4._netCDF4._ensure_nc_success AttributeError: NetCDF: String match to name in use ``` The generated attribute error isn't clear at all, the file actually gets created, but then fails in the processes of writing. There is no clear connection to the netCDF format. #### Expected Output A new file created/written in (default) NETCDF4 format with contents of the Dataset. Or at the very least provide an exception that clearly indicates the format incompatibilities.
#### Output of ``xr.show_versions()`` INSTALLED VERSIONS ------------------ commit: None python: 2.7.5 (default, Sep 12 2018, 05:31:16) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] python-bits: 64 OS: Linux OS-release: 3.10.0-957.5.1.el7.x86_64 machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: None.None libhdf5: 1.8.18 libnetcdf: 4.4.1.1 xarray: 0.11.3 pandas: 0.22.0 numpy: 1.14.2 scipy: 1.0.0 netCDF4: 1.4.1 pydap: None h5netcdf: None h5py: 2.7.1 Nio: None zarr: None cftime: 1.0.1 PseudonetCDF: None rasterio: None cfgrib: None iris: None bottleneck: None cyordereddict: None dask: None distributed: None matplotlib: 1.2.0 cartopy: None seaborn: None setuptools: 40.4.3 pip: 18.1 conda: None pytest: None IPython: None sphinx: None
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/2822/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue