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/issues/2170#issuecomment-474905548,https://api.github.com/repos/pydata/xarray/issues/2170,474905548,MDEyOklzc3VlQ29tbWVudDQ3NDkwNTU0OA==,1217238,2019-03-20T16:08:51Z,2019-03-20T16:08:51Z,MEMBER,Pull requests would be very welcome here.,"{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,325436508 https://github.com/pydata/xarray/issues/2170#issuecomment-474786687,https://api.github.com/repos/pydata/xarray/issues/2170,474786687,MDEyOklzc3VlQ29tbWVudDQ3NDc4NjY4Nw==,2418513,2019-03-20T11:13:40Z,2019-03-20T11:13:40Z,NONE,"Please! It's really painful in some cases where `keepdims` option is not available, tons of unneeded boilerplate required to mimic the same thing. ","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,325436508 https://github.com/pydata/xarray/issues/2170#issuecomment-407159487,https://api.github.com/repos/pydata/xarray/issues/2170,407159487,MDEyOklzc3VlQ29tbWVudDQwNzE1OTQ4Nw==,7441788,2018-07-23T18:39:52Z,2018-07-23T18:39:52Z,CONTRIBUTOR,"I second this request. The following may not be optimal, but seems to work for me as a `keepdims=True` version of `reduce()`: ``` def dim_preserving_reduce(self, func, dim=None, axis=None, label=None, keep_attrs=False, **kwargs): if axis is not None: dim = np.take(self._obj.dims, axis, mode='wrap') dims = dim if isinstance(dim, (list, tuple)) else [dim] dims_coords = {dim: [lab] for dim, lab in zip(dims, (label if isinstance(label, list) else [label]))} return self._obj.reduce(func, dim=dims, keep_attrs=keep_attrs, **kwargs). \ expand_dims(dims, axis=[self._obj.dims.index(dim) for dim in dims]). \ assign_coords(**dims_coords) ``` ","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,325436508