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/2145#issuecomment-1073493914,https://api.github.com/repos/pydata/xarray/issues/2145,1073493914,IC_kwDOAMm_X84__Dea,2448579,2022-03-21T05:15:52Z,2022-03-21T05:15:52Z,MEMBER,There is compatibility code in `GroupBy._binary_op` that could be removed when this is fixed. (See #6160),"{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,323839238 https://github.com/pydata/xarray/issues/2145#issuecomment-391114129,https://api.github.com/repos/pydata/xarray/issues/2145,391114129,MDEyOklzc3VlQ29tbWVudDM5MTExNDEyOQ==,1217238,2018-05-22T19:34:48Z,2018-05-22T19:47:09Z,MEMBER,"This is not really desirable behavior, but it's an implication of how xarray implements `ds.resample(time='1M').mean()`: - Resample is converted into a groupby call, e.g., `ds.groupby(time_starts).mean('time')` - `.mean('time')` for each grouped dataset averages over the 'time' dimension, resulting in a dataset with only a 'space' dimension, e.g., ``` >>> list(ds.resample(time='1M'))[0][1].mean('time') Dimensions: (space: 10) Coordinates: * space (space) int64 0 1 2 3 4 5 6 7 8 9 Data variables: var_withtime1 (space) float64 0.008982 -0.09879 0.1361 -0.2485 -0.023 ... var_withtime2 (space) float64 0.2621 0.06009 -0.1686 0.07397 0.1095 ... var_timeless1 (space) float64 0.8519 -0.4253 -0.8581 0.9085 -0.4797 ... var_timeless2 (space) float64 0.8006 1.954 -0.5349 0.3317 1.778 -0.7954 ... ``` - `concat()` is used to combine grouped datasets into the final result, but it doesn't know anything about which variables were aggregated, so every data variable gets the ""time"" dimension added. To fix this I would suggest three steps: 1. Add a `keep_dims` argument to xarray reductions like `mean()`, indicating that a dimension should be preserved with length 1, like `keep_dims=True` for numpy reductions (https://github.com/pydata/xarray/issues/2170). 2. Fix `concat` to only concatenate variables that already have the concatenated dimension, as discussed in https://github.com/pydata/xarray/issues/2064 3. Use `keep_dims=True` in groupby reductions. Then the result should automatically only include aggregated dimensions. This would convenient allow us to remove existing logic in groupby() for restoring the original order of aggregated dimensions (see [`_restore_dim_order()`](https://github.com/pydata/xarray/blob/48d55eea052fec204b843babdc81c258f3ed5ce1/xarray/core/groupby.py#L460)).","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,323839238 https://github.com/pydata/xarray/issues/2145#issuecomment-390275158,https://api.github.com/repos/pydata/xarray/issues/2145,390275158,MDEyOklzc3VlQ29tbWVudDM5MDI3NTE1OA==,10050469,2018-05-18T17:21:11Z,2018-05-18T17:21:11Z,MEMBER,"I see. Note that ``groupby`` does the same. I don't know what the rationale is behind that decision, but there might be a reason...","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,323839238 https://github.com/pydata/xarray/issues/2145#issuecomment-389886807,https://api.github.com/repos/pydata/xarray/issues/2145,389886807,MDEyOklzc3VlQ29tbWVudDM4OTg4NjgwNw==,10050469,2018-05-17T14:29:46Z,2018-05-17T14:29:46Z,MEMBER,Thanks for the report! Do you think you can craft a [minimal working example](http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports) ?,"{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,323839238