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/6353#issuecomment-1068703649,https://api.github.com/repos/pydata/xarray/issues/6353,1068703649,IC_kwDOAMm_X84_sx-h,2448579,2022-03-16T03:52:49Z,2022-03-16T03:52:49Z,MEMBER,"@mathause I suspect `coarsen.construct` is faster because it's a simple reshape (ignoring the copies associated with handling the boundary condition):
https://github.com/pydata/xarray/blob/95bb9ae4233c16639682a532c14b26a3ea2728f3/xarray/core/variable.py#L2373
Unstacking allocates a new array and then assigns all values. It is definitely the more general solution though.
We should discuss this in the proposed cookbook (https://github.com/pydata/xarray/issues/1790)","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1167962844
https://github.com/pydata/xarray/pull/6353#issuecomment-1068371598,https://api.github.com/repos/pydata/xarray/issues/6353,1068371598,IC_kwDOAMm_X84_rg6O,5635139,2022-03-15T19:19:33Z,2022-03-15T19:19:33Z,MEMBER,Very good video @dcherian !,"{""total_count"": 1, ""+1"": 1, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1167962844
https://github.com/pydata/xarray/pull/6353#issuecomment-1068305154,https://api.github.com/repos/pydata/xarray/issues/6353,1068305154,IC_kwDOAMm_X84_rQsC,10194086,2022-03-15T18:13:39Z,2022-03-15T18:13:39Z,MEMBER,"Nice! I did not know about `coarsen(...).construct(...)` - interesting. I usually use `set_index` for that - could be interesting to test which approach is faster.
```python
def _to_seasonal(ds):
year = ds.time.dt.year.data
season = ds.time.dt.season.data
# assign new coords
ds = ds.assign_coords(year=(""time"", year), season=(""time"", season))
# reshape the array to (..., ""season"", ""year"")
return ds.set_index(time=(""year"", ""season"")).unstack(""time"")
```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1167962844