{"database": "github", "table": "issues", "is_view": false, "human_description_en": "where \"closed_at\" is on date 2020-03-30, state_reason = \"completed\" and user = 35968931 sorted by updated_at descending", "rows": [[474247717, "MDU6SXNzdWU0NzQyNDc3MTc=", 3168, "apply_ufunc erroneously operating on an empty array when dask used", 35968931, "closed", 0, null, null, 3, "2019-07-29T20:44:23Z", "2020-03-30T15:08:16Z", "2020-03-30T15:08:15Z", "MEMBER", null, null, null, "#### Problem description\r\n\r\n`apply_ufunc` with `dask='parallelized'` appears to be trying to act on an empty numpy array when the computation is specified, but before `.compute()` is called. In other words, a ufunc which just prints the shape of its argument will print `(0,0)` then print the correct shape once `.compute()` is called.\r\n\r\n#### Minimum working example\r\n\r\n```python\r\nimport numpy as np\r\nimport xarray as xr\r\n\r\n\r\ndef example_ufunc(x):\r\n    print(x.shape)\r\n    return np.mean(x, axis=-1)\r\n\r\ndef new_mean(da, dim):\r\n    result = xr.apply_ufunc(example_ufunc, da,\r\n                            input_core_dims=[[dim]], dask='parallelized',\r\n                            output_dtypes=[da.dtype])\r\n    return result\r\n\r\n\r\nshape = {'t': 2, 'x':3}\r\ndata = xr.DataArray(data=np.random.rand(*shape.values()), dims=shape.keys())\r\nunchunked = data\r\nchunked = data.chunk(shape)\r\n\r\n\r\nactual = new_mean(chunked, dim='x')  # raises the warning\r\nprint(actual)\r\n\r\nprint(actual.compute())  # does the computation correctly\r\n```\r\n\r\n#### Result\r\n\r\n```\r\n(0, 0)\r\n/home/tnichol/anaconda3/envs/py36/lib/python3.6/site-packages/numpy/core/fromnumeric.py:3118: RuntimeWarning: Mean of empty slice.\r\n  out=out, **kwargs)\r\n<xarray.DataArray (t: 2)>\r\ndask.array<shape=(2,), dtype=float64, chunksize=(2,)>\r\nDimensions without coordinates: t\r\n(2, 3)\r\n<xarray.DataArray (t: 2)>\r\narray([0.147205, 0.402913])\r\nDimensions without coordinates: t\r\n```\r\n\r\n#### Expected result\r\n\r\nSame thing without the `(0,0)` or the numpy warning.\r\n\r\n\r\n#### Output of ``xr.show_versions()``\r\n(my xarray is up-to-date with master)\r\n\r\n<details>\r\nINSTALLED VERSIONS\r\n------------------\r\ncommit: None\r\npython: 3.6.6 |Anaconda, Inc.| (default, Oct  9 2018, 12:34:16) \r\n[GCC 7.3.0]\r\npython-bits: 64\r\nOS: Linux\r\nOS-release: 3.10.0-862.14.4.el7.x86_64\r\nmachine: x86_64\r\nprocessor: x86_64\r\nbyteorder: little\r\nLC_ALL: None\r\nLANG: en_GB.UTF-8\r\nLOCALE: en_GB.UTF-8\r\nlibhdf5: 1.10.2\r\nlibnetcdf: 4.6.1\r\n\r\nxarray: 0.12.3+23.g1d7bcbd\r\npandas: 0.24.2\r\nnumpy: 1.16.4\r\nscipy: 1.3.0\r\nnetCDF4: 1.4.2\r\npydap: None\r\nh5netcdf: None\r\nh5py: 2.8.0\r\nNio: None\r\nzarr: None\r\ncftime: 1.0.3.4\r\nnc_time_axis: None\r\nPseudoNetCDF: None\r\nrasterio: None\r\ncfgrib: None\r\niris: None\r\nbottleneck: 1.2.1\r\ndask: 2.1.0\r\ndistributed: 2.1.0\r\nmatplotlib: 3.1.0\r\ncartopy: None\r\nseaborn: 0.9.0\r\nnumbagg: None\r\nsetuptools: 40.6.2\r\npip: 18.1\r\nconda: None\r\npytest: 4.0.0\r\nIPython: 7.1.1\r\nsphinx: 1.8.2\r\n</details>\r\n", "{\"url\": \"https://api.github.com/repos/pydata/xarray/issues/3168/reactions\", \"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", null, "completed", 13221727, "issue"]], "truncated": false, "filtered_table_rows_count": 1, "expanded_columns": [], "expandable_columns": [[{"column": "repo", "other_table": "repos", "other_column": "id"}, "name"], [{"column": "milestone", "other_table": "milestones", "other_column": "id"}, "title"], [{"column": "assignee", "other_table": "users", "other_column": "id"}, "login"], [{"column": "user", "other_table": "users", "other_column": "id"}, "login"]], "columns": ["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"], "primary_keys": ["id"], "units": {}, "query": {"sql": "select 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 from issues where date(\"closed_at\") = :p0 and \"state_reason\" = :p1 and \"user\" = :p2 order by updated_at desc limit 101", "params": {"p0": "2020-03-30", "p1": "completed", "p2": "35968931"}}, "facet_results": {"state": {"name": "state", "type": "column", "hideable": false, "toggle_url": "/github/issues.json?closed_at__date=2020-03-30&state_reason=completed&user=35968931", "results": [{"value": "closed", "label": "closed", "count": 1, "toggle_url": "http://xarray-datasette.fly.dev/github/issues.json?closed_at__date=2020-03-30&state_reason=completed&user=35968931&state=closed", "selected": false}], "truncated": false}, "repo": {"name": "repo", "type": "column", "hideable": false, "toggle_url": "/github/issues.json?closed_at__date=2020-03-30&state_reason=completed&user=35968931", "results": [{"value": 13221727, "label": "xarray", "count": 1, "toggle_url": "http://xarray-datasette.fly.dev/github/issues.json?closed_at__date=2020-03-30&state_reason=completed&user=35968931&repo=13221727", "selected": false}], "truncated": false}, "type": {"name": "type", "type": "column", "hideable": false, "toggle_url": "/github/issues.json?closed_at__date=2020-03-30&state_reason=completed&user=35968931", "results": [{"value": "issue", "label": "issue", "count": 1, "toggle_url": "http://xarray-datasette.fly.dev/github/issues.json?closed_at__date=2020-03-30&state_reason=completed&user=35968931&type=issue", "selected": false}], "truncated": false}}, "suggested_facets": [{"name": "created_at", "type": "date", "toggle_url": "http://xarray-datasette.fly.dev/github/issues.json?closed_at__date=2020-03-30&state_reason=completed&user=35968931&_facet_date=created_at"}, {"name": "updated_at", "type": "date", "toggle_url": "http://xarray-datasette.fly.dev/github/issues.json?closed_at__date=2020-03-30&state_reason=completed&user=35968931&_facet_date=updated_at"}, {"name": "closed_at", "type": "date", "toggle_url": "http://xarray-datasette.fly.dev/github/issues.json?closed_at__date=2020-03-30&state_reason=completed&user=35968931&_facet_date=closed_at"}], "next": null, "next_url": null, "private": false, "allow_execute_sql": true, "query_ms": 38.91946701332927}