{"action":"closed","issue":{"url":"https://api.github.com/repos/pydata/xarray/issues/2512","repository_url":"https://api.github.com/repos/pydata/xarray","labels_url":"https://api.github.com/repos/pydata/xarray/issues/2512/labels{/name}","comments_url":"https://api.github.com/repos/pydata/xarray/issues/2512/comments","events_url":"https://api.github.com/repos/pydata/xarray/issues/2512/events","html_url":"https://github.com/pydata/xarray/issues/2512","id":374070147,"node_id":"MDU6SXNzdWUzNzQwNzAxNDc=","number":2512,"title":"to_netcdf() fails because of datetime encoding","user":{"login":"njweber2","id":22665917,"node_id":"MDQ6VXNlcjIyNjY1OTE3","avatar_url":"https://avatars1.githubusercontent.com/u/22665917?v=4","gravatar_id":"","url":"https://api.github.com/users/njweber2","html_url":"https://github.com/njweber2","followers_url":"https://api.github.com/users/njweber2/followers","following_url":"https://api.github.com/users/njweber2/following{/other_user}","gists_url":"https://api.github.com/users/njweber2/gists{/gist_id}","starred_url":"https://api.github.com/users/njweber2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/njweber2/subscriptions","organizations_url":"https://api.github.com/users/njweber2/orgs","repos_url":"https://api.github.com/users/njweber2/repos","events_url":"https://api.github.com/users/njweber2/events{/privacy}","received_events_url":"https://api.github.com/users/njweber2/received_events","type":"User","site_admin":false},"labels":[{"id":58766097,"node_id":"MDU6TGFiZWw1ODc2NjA5Nw==","url":"https://api.github.com/repos/pydata/xarray/labels/bug","name":"bug","color":"fc2929","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-10-25T18:17:47Z","updated_at":"2018-10-27T16:34:54Z","closed_at":"2018-10-27T16:34:54Z","author_association":"NONE","body":"#### Simple example:\r\n\r\n```python\r\nimport numpy as np\r\nfrom datetime import datetime, timedelta\r\nimport xarray\r\n\r\n# \"time\" coordinate\r\ndt = datetime(1999, 1, 1)\r\ndts = np.array([dt + timedelta(days=x) for x in range(10)])\r\ncoords = {'time': dts}\r\n\r\n# simple float data\r\ndata = np.arange(10)\r\nvrbls = {'foo': (('time',), data)}\r\n\r\n# create the Dataset\r\nds = xarray.Dataset(vrbls, coords)\r\n\r\n# encode the time coordinate\r\nunits = 'days since 1900-01-01'\r\nds.time.encoding['units'] = units\r\n\r\n# write to netcdf\r\nds.to_netcdf('test.nc')\r\n\r\n```\r\n#### Problem description\r\n\r\nWhen I run the above, I get the following error when executing the last line:\r\n**`ValueError: unsupported dtype for netCDF4 variable: datetime64[ns]`**\r\n\r\nThe documentation indicates that datetime and datetime64 objects are both supported by xarray and should write to netcdf just fine when supplied \"units\" for encoding (this code fails with or without the encoding lines). Any Idea when is going wrong here?\r\n\r\n#### Output of ``xr.show_versions()``\r\n\r\n<details>\r\nINSTALLED VERSIONS\r\n------------------\r\ncommit: None\r\npython: 3.6.2.final.0\r\npython-bits: 64\r\nOS: Linux\r\nOS-release: 4.9.0-8-amd64\r\nmachine: x86_64\r\nprocessor: x86_64\r\nbyteorder: little\r\nLC_ALL: None\r\nLANG: en_US.UTF-8\r\nLOCALE: en_US.UTF-8\r\n\r\nxarray: 0.10.9\r\npandas: 0.20.3\r\nnumpy: 1.13.1\r\nscipy: 0.19.1\r\nnetCDF4: 1.4.2\r\nh5netcdf: 0.5.0\r\nh5py: 2.8.0\r\nNio: None\r\nzarr: None\r\ncftime: 1.0.1\r\nPseudonetCDF: None\r\nrasterio: None\r\niris: None\r\nbottleneck: 1.2.1\r\ncyordereddict: None\r\ndask: 0.16.0\r\ndistributed: 1.20.1\r\nmatplotlib: 2.1.0\r\ncartopy: None\r\nseaborn: 0.8.0\r\nsetuptools: 27.2.0\r\npip: 9.0.1\r\nconda: 4.5.11\r\npytest: 3.1.3\r\nIPython: 6.1.0\r\nsphinx: 1.6.2\r\n</details>\r\n"}}
{"actor":{"display_login":"dcherian"}}