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/pull/964#issuecomment-248957341,https://api.github.com/repos/pydata/xarray/issues/964,248957341,MDEyOklzc3VlQ29tbWVudDI0ODk1NzM0MQ==,1924092,2016-09-22T16:34:44Z,2016-09-22T16:34:44Z,MEMBER,"@shoyer - I agree on 3) that it might too much to pack in to `xr.apply`. As one possibility, here's a half-implemented (probably buggy!) wrapper that would allow this: ``` python @xarray_gufunc @numba.guvectorize(['void(f8[:], f8[:])'], '(n)->()') def std_gufunc(arr, out): out[0] = np.std(arr) std_gufunc(arr, dims=('x',)) ``` https://gist.github.com/chris-b1/d28c6b8e78bf65ef7eb97e1095bc87f2 ","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,170779798 https://github.com/pydata/xarray/pull/964#issuecomment-248772865,https://api.github.com/repos/pydata/xarray/issues/964,248772865,MDEyOklzc3VlQ29tbWVudDI0ODc3Mjg2NQ==,1924092,2016-09-21T23:28:55Z,2016-09-21T23:28:55Z,MEMBER,"A few pieces of feedback trying this out. I'm basically learning xarray as I go (I ran into this right away), so weight appropriately. Usecase - I have a numba gufunc I want to apply to `DataArray`, e.g. a reduction like this (`std` is just for sake of example) ``` @numba.guvectorize(['void(f8[:], f8[:])'], '(n)->()') def std_gufunc(arr, out): out[0] = np.std(arr) arr = xr.DataArray(np.random.randn(100, 100, 100), dims=('x', 'y', 'z')) ``` 1) The ""obvious"" thing doesn't work - maybe catch and show a nicer error message here ``` xr.apply(std_gufunc, arr) ValueError: dimensions ('x', 'y', 'z') must have the same length as the number of data dimensions, ndim=2 ``` 2) I personally found the non-string version of `signature` really difficult to wrap my mind around (the below took several tries to get right). I don't have a concrete suggestion though, maybe only the string form is meant to really be the public api? ``` xr.apply(std_gufunc, arr, signature=([('x',)], [()])) xr.apply(std_gufunc, arr, signature='(x)->()') ``` 3) It would be nice to take advantage of the existing gufunc signature in some way. Maybe this is a wrapper built on top or `xr.apply`, or expand the api to allow something like this; ``` xr.apply(std_gufunc, arr, dims=('x',)) xr.apply(std_gufunc, arr, dims={'n':'x'}) ``` ","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,170779798