{"database": "github", "table": "issue_comments", "is_view": false, "human_description_en": "where author_association = \"MEMBER\", issue = 860038564 and user = 5635139 sorted by updated_at descending", "rows": [["https://github.com/pydata/xarray/issues/5173#issuecomment-821878676", "https://api.github.com/repos/pydata/xarray/issues/5173", 821878676, "MDEyOklzc3VlQ29tbWVudDgyMTg3ODY3Ng==", 5635139, "2021-04-17T19:55:30Z", "2021-04-17T19:55:30Z", "MEMBER", "I'm looking at implementing this. \r\n\r\n I think we could do this with a simple `broadcast_like` on the input, as above. But is that going to miss things that our normal machinery is capturing? Currently `.clip` is a [`unary_ops`](https://github.com/pydata/xarray/blob/v0.17.0/xarray/core/dataarray.py#L2954) which I haven't looked at in a while. And I'm not being that successful at evaluating what's going wrong from the stack trace \u2014 so posting here in case those who've worked with this recently have it cached.\r\n\r\nOne thing to note: there are different errors depending on which dimensions are missing, because of the missing broadcasting before removing the `dim` information:\r\n\r\n```python\r\n\r\nIn [27]: da.clip(da.mean('a'))\r\n---------------------------------------------------------------------------\r\nValueError                                Traceback (most recent call last)\r\n<ipython-input-27-c8b9c6d0e0a1> in <module>\r\n----> 1 da.clip(da.mean('a'))\r\n\r\n~/.asdf/installs/python/3.8.8/lib/python3.8/site-packages/xarray/core/dataarray.py in func(self, *args, **kwargs)\r\n   2964                 )\r\n   2965                 with np.errstate(all=\"ignore\"):\r\n-> 2966                     da = self.__array_wrap__(f(self.variable.data, *args, **kwargs))\r\n   2967                 if keep_attrs:\r\n   2968                     da.attrs = self.attrs\r\n\r\n~/.asdf/installs/python/3.8.8/lib/python3.8/site-packages/xarray/core/ops.py in func(self, *args, **kwargs)\r\n    228 def _method_wrapper(name):\r\n    229     def func(self, *args, **kwargs):\r\n--> 230         return _call_possibly_missing_method(self, name, args, kwargs)\r\n    231\r\n    232     func.__name__ = name\r\n\r\n~/.asdf/installs/python/3.8.8/lib/python3.8/site-packages/xarray/core/ops.py in _call_possibly_missing_method(arg, name, args, kwargs)\r\n    214         raise\r\n    215     else:\r\n--> 216         return method(*args, **kwargs)\r\n    217\r\n    218\r\n\r\n~/.asdf/installs/python/3.8.8/lib/python3.8/site-packages/numpy/core/_methods.py in _clip(a, min, max, out, casting, **kwargs)\r\n    153             um.minimum, a, max, out=out, casting=casting, **kwargs)\r\n    154     elif max is None:\r\n--> 155         return _clip_dep_invoke_with_casting(\r\n    156             um.maximum, a, min, out=out, casting=casting, **kwargs)\r\n    157     else:\r\n\r\n~/.asdf/installs/python/3.8.8/lib/python3.8/site-packages/numpy/core/_methods.py in _clip_dep_invoke_with_casting(ufunc, out, casting, *args, **kwargs)\r\n    110     # try to deal with broken casting rules\r\n    111     try:\r\n--> 112         return ufunc(*args, out=out, **kwargs)\r\n    113     except _exceptions._UFuncOutputCastingError as e:\r\n    114         # Numpy 1.17.0, 2019-02-24\r\n\r\n~/.asdf/installs/python/3.8.8/lib/python3.8/site-packages/xarray/core/arithmetic.py in __array_ufunc__(self, ufunc, method, *inputs, **kwargs)\r\n     68         join = dataset_join = OPTIONS[\"arithmetic_join\"]\r\n     69\r\n---> 70         return apply_ufunc(\r\n     71             ufunc,\r\n     72             *inputs,\r\n\r\n~/.asdf/installs/python/3.8.8/lib/python3.8/site-packages/xarray/core/computation.py in apply_ufunc(func, input_core_dims, output_core_dims, exclude_dims, vectorize, join, dataset_join, dataset_fill_value, keep_attrs, kwargs, dask, output_dtypes, output_sizes, meta, dask_gufunc_kwargs, *args)\r\n   1126     # feed DataArray apply_variable_ufunc through apply_dataarray_vfunc\r\n   1127     elif any(isinstance(a, DataArray) for a in args):\r\n-> 1128         return apply_dataarray_vfunc(\r\n   1129             variables_vfunc,\r\n   1130             *args,\r\n\r\n~/.asdf/installs/python/3.8.8/lib/python3.8/site-packages/xarray/core/computation.py in apply_dataarray_vfunc(func, signature, join, exclude_dims, keep_attrs, *args)\r\n    269\r\n    270     data_vars = [getattr(a, \"variable\", a) for a in args]\r\n--> 271     result_var = func(*data_vars)\r\n    272\r\n    273     if signature.num_outputs > 1:\r\n\r\n~/.asdf/installs/python/3.8.8/lib/python3.8/site-packages/xarray/core/computation.py in apply_variable_ufunc(func, signature, exclude_dims, dask, output_dtypes, vectorize, keep_attrs, dask_gufunc_kwargs, *args)\r\n    741         data = as_compatible_data(data)\r\n    742         if data.ndim != len(dims):\r\n--> 743             raise ValueError(\r\n    744                 \"applied function returned data with unexpected \"\r\n    745                 f\"number of dimensions. Received {data.ndim} dimension(s) but \"\r\n\r\nValueError: applied function returned data with unexpected number of dimensions. Received 3 dimension(s) but expected 2 dimensions with names: ('b', 'c')\r\n```\r\n\r\nWhen the final dimension is missing:\r\n```python\r\n\r\nIn [28]: da.clip(da.mean('c'))\r\n---------------------------------------------------------------------------\r\nValueError                                Traceback (most recent call last)\r\n<ipython-input-28-8e46fcdf9b64> in <module>\r\n----> 1 da.clip(da.mean('c'))\r\n\r\n~/.asdf/installs/python/3.8.8/lib/python3.8/site-packages/xarray/core/dataarray.py in func(self, *args, **kwargs)\r\n   2964                 )\r\n   2965                 with np.errstate(all=\"ignore\"):\r\n-> 2966                     da = self.__array_wrap__(f(self.variable.data, *args, **kwargs))\r\n   2967                 if keep_attrs:\r\n   2968                     da.attrs = self.attrs\r\n\r\n~/.asdf/installs/python/3.8.8/lib/python3.8/site-packages/xarray/core/ops.py in func(self, *args, **kwargs)\r\n    228 def _method_wrapper(name):\r\n    229     def func(self, *args, **kwargs):\r\n--> 230         return _call_possibly_missing_method(self, name, args, kwargs)\r\n    231\r\n    232     func.__name__ = name\r\n\r\n~/.asdf/installs/python/3.8.8/lib/python3.8/site-packages/xarray/core/ops.py in _call_possibly_missing_method(arg, name, args, kwargs)\r\n    214         raise\r\n    215     else:\r\n--> 216         return method(*args, **kwargs)\r\n    217\r\n    218\r\n\r\n~/.asdf/installs/python/3.8.8/lib/python3.8/site-packages/numpy/core/_methods.py in _clip(a, min, max, out, casting, **kwargs)\r\n    153             um.minimum, a, max, out=out, casting=casting, **kwargs)\r\n    154     elif max is None:\r\n--> 155         return _clip_dep_invoke_with_casting(\r\n    156             um.maximum, a, min, out=out, casting=casting, **kwargs)\r\n    157     else:\r\n\r\n~/.asdf/installs/python/3.8.8/lib/python3.8/site-packages/numpy/core/_methods.py in _clip_dep_invoke_with_casting(ufunc, out, casting, *args, **kwargs)\r\n    110     # try to deal with broken casting rules\r\n    111     try:\r\n--> 112         return ufunc(*args, out=out, **kwargs)\r\n    113     except _exceptions._UFuncOutputCastingError as e:\r\n    114         # Numpy 1.17.0, 2019-02-24\r\n\r\n~/.asdf/installs/python/3.8.8/lib/python3.8/site-packages/xarray/core/arithmetic.py in __array_ufunc__(self, ufunc, method, *inputs, **kwargs)\r\n     68         join = dataset_join = OPTIONS[\"arithmetic_join\"]\r\n     69\r\n---> 70         return apply_ufunc(\r\n     71             ufunc,\r\n     72             *inputs,\r\n\r\n~/.asdf/installs/python/3.8.8/lib/python3.8/site-packages/xarray/core/computation.py in apply_ufunc(func, input_core_dims, output_core_dims, exclude_dims, vectorize, join, dataset_join, dataset_fill_value, keep_attrs, kwargs, dask, output_dtypes, output_sizes, meta, dask_gufunc_kwargs, *args)\r\n   1126     # feed DataArray apply_variable_ufunc through apply_dataarray_vfunc\r\n   1127     elif any(isinstance(a, DataArray) for a in args):\r\n-> 1128         return apply_dataarray_vfunc(\r\n   1129             variables_vfunc,\r\n   1130             *args,\r\n\r\n~/.asdf/installs/python/3.8.8/lib/python3.8/site-packages/xarray/core/computation.py in apply_dataarray_vfunc(func, signature, join, exclude_dims, keep_attrs, *args)\r\n    269\r\n    270     data_vars = [getattr(a, \"variable\", a) for a in args]\r\n--> 271     result_var = func(*data_vars)\r\n    272\r\n    273     if signature.num_outputs > 1:\r\n\r\n~/.asdf/installs/python/3.8.8/lib/python3.8/site-packages/xarray/core/computation.py in apply_variable_ufunc(func, signature, exclude_dims, dask, output_dtypes, vectorize, keep_attrs, dask_gufunc_kwargs, *args)\r\n    722             )\r\n    723\r\n--> 724     result_data = func(*input_data)\r\n    725\r\n    726     if signature.num_outputs == 1:\r\n\r\nValueError: operands could not be broadcast together with shapes (2,4,3) (2,4)\r\n```\r\n\r\n", "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", null, 860038564]], "truncated": false, "filtered_table_rows_count": 1, "expanded_columns": [], "expandable_columns": [[{"column": "issue", "other_table": "issues", "other_column": "id"}, "title"], [{"column": "user", "other_table": "users", "other_column": "id"}, "login"]], "columns": ["html_url", "issue_url", "id", "node_id", "user", "created_at", "updated_at", "author_association", "body", "reactions", "performed_via_github_app", "issue"], "primary_keys": ["id"], "units": {}, "query": {"sql": "select html_url, issue_url, id, node_id, user, created_at, updated_at, author_association, body, reactions, performed_via_github_app, issue from issue_comments where \"author_association\" = :p0 and \"issue\" = :p1 and \"user\" = :p2 order by updated_at desc limit 101", "params": {"p0": "MEMBER", "p1": "860038564", "p2": "5635139"}}, "facet_results": {"author_association": {"name": "author_association", "type": "column", "hideable": false, "toggle_url": "/github/issue_comments.json?author_association=MEMBER&issue=860038564&user=5635139", "results": [{"value": "MEMBER", "label": "MEMBER", "count": 1, "toggle_url": "http://xarray-datasette.fly.dev/github/issue_comments.json?issue=860038564&user=5635139", "selected": true}], "truncated": false}, "user": {"name": "user", "type": "column", "hideable": false, "toggle_url": "/github/issue_comments.json?author_association=MEMBER&issue=860038564&user=5635139", "results": [{"value": 5635139, "label": "max-sixty", "count": 1, "toggle_url": "http://xarray-datasette.fly.dev/github/issue_comments.json?author_association=MEMBER&issue=860038564", "selected": true}], "truncated": false}, "issue": {"name": "issue", "type": "column", "hideable": false, "toggle_url": "/github/issue_comments.json?author_association=MEMBER&issue=860038564&user=5635139", "results": [{"value": 860038564, "label": "Clip broadcasts min or max array input", "count": 1, "toggle_url": "http://xarray-datasette.fly.dev/github/issue_comments.json?author_association=MEMBER&user=5635139", "selected": true}], "truncated": false}}, "suggested_facets": [], "next": null, "next_url": null, "private": false, "allow_execute_sql": true, "query_ms": 4401.022136997199}