{"action":"created","issue":{"url":"https://api.github.com/repos/pydata/xarray/issues/1225","repository_url":"https://api.github.com/repos/pydata/xarray","labels_url":"https://api.github.com/repos/pydata/xarray/issues/1225/labels{/name}","comments_url":"https://api.github.com/repos/pydata/xarray/issues/1225/comments","events_url":"https://api.github.com/repos/pydata/xarray/issues/1225/events","html_url":"https://github.com/pydata/xarray/issues/1225","id":202964277,"number":1225,"title":"“ValueError: chunksize cannot exceed dimension size” when trying to write xarray to netcdf","user":{"login":"shoyer","id":1217238,"avatar_url":"https://avatars1.githubusercontent.com/u/1217238?v=3","gravatar_id":"","url":"https://api.github.com/users/shoyer","html_url":"https://github.com/shoyer","followers_url":"https://api.github.com/users/shoyer/followers","following_url":"https://api.github.com/users/shoyer/following{/other_user}","gists_url":"https://api.github.com/users/shoyer/gists{/gist_id}","starred_url":"https://api.github.com/users/shoyer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shoyer/subscriptions","organizations_url":"https://api.github.com/users/shoyer/orgs","repos_url":"https://api.github.com/users/shoyer/repos","events_url":"https://api.github.com/users/shoyer/events{/privacy}","received_events_url":"https://api.github.com/users/shoyer/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-01-24T22:52:36Z","updated_at":"2017-06-09T23:02:20Z","closed_at":null,"body":"Reported on StackOverflow: http://stackoverflow.com/questions/39900011/valueerror-chunksize-cannot-exceed-dimension-size-when-trying-to-write-xarray\r\n\r\nUnfortunately, the given example is not self-contained:\r\n```\r\nimport xarray as xr  \r\nds=xr.open_dataset(\"somefile.nc\",chunks={'lat':72,'lon':144}  \r\nmyds=ds.copy()\r\n#ds is 335 (time) on 720 on 1440 and has variable var  \r\ndef some_function(x):\r\n  return x*2\r\nmyds['newvar']=xr.DataArray(np.apply_along_axis(some_function,0,ds['var']))  \r\nmyds.drop('var')  \r\nmyds.to_netcdf(\"somenewfile.nc\")\r\n```\r\n\r\nApparently this works if `engine='scipy'` in `to_netcdf`!\r\n\r\nSomething strange is definitely going on, I suspect a bug."},"comment":{"url":"https://api.github.com/repos/pydata/xarray/issues/comments/307519054","html_url":"https://github.com/pydata/xarray/issues/1225#issuecomment-307519054","issue_url":"https://api.github.com/repos/pydata/xarray/issues/1225","id":307519054,"user":{"login":"shoyer","id":1217238,"avatar_url":"https://avatars1.githubusercontent.com/u/1217238?v=3","gravatar_id":"","url":"https://api.github.com/users/shoyer","html_url":"https://github.com/shoyer","followers_url":"https://api.github.com/users/shoyer/followers","following_url":"https://api.github.com/users/shoyer/following{/other_user}","gists_url":"https://api.github.com/users/shoyer/gists{/gist_id}","starred_url":"https://api.github.com/users/shoyer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shoyer/subscriptions","organizations_url":"https://api.github.com/users/shoyer/orgs","repos_url":"https://api.github.com/users/shoyer/repos","events_url":"https://api.github.com/users/shoyer/events{/privacy}","received_events_url":"https://api.github.com/users/shoyer/received_events","type":"User","site_admin":false},"created_at":"2017-06-09T23:02:20Z","updated_at":"2017-06-09T23:02:20Z","body":"@tbohn \"self-contained\" just means something that I can run on my machine. For example, the code above plus the \"somefile.nc\" netCDF file that I can load to reproduce this example.\r\n\r\nThinking about this a little more, I think the issue is somehow related to the `encoding['chunksizes']` property on the Dataset variables loaded from the original netCDF file. Something like this should work as a work-around:\r\n```\r\ndel myds.var.encoding['chunksizes']\r\n```\r\n\r\nThe bug is somewhere in our [handling of chunksize encoding](https://github.com/pydata/xarray/blob/bbeab6954c4bf06145c64bf90fbb268fce2ab7f1/xarray/backends/netCDF4_.py#L160) for netCDF4, but it is difficult to fix it without being able to run code that reproduces it."}}
{"actor":{"display_login":"shoyer"}}