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 923355397,MDExOlB1bGxSZXF1ZXN0NjcyMTI5NzY4,5480,Implement weighted groupby,2448579,open,0,,,1,2021-06-17T02:57:17Z,2023-07-27T18:09:55Z,,MEMBER,,1,pydata/xarray/pulls/5480," - xref #3937 - [ ] Tests added - [ ] Passes `pre-commit run --all-files` - [ ] User visible changes (including notable bug fixes) are documented in `whats-new.rst` - [ ] New functions/methods are listed in `api.rst` Initial proof-of-concept. Suggestions to improve this are very welcome. Here's some convenient testing code ``` python import xarray as xr ds = xr.tutorial.open_dataset('rasm').load() month_length = ds.time.dt.days_in_month weights = month_length.groupby('time.season') / month_length.groupby('time.season').sum() actual = ds.weighted(month_length).groupby(""time.season"").mean() expected = (ds * weights).groupby('time.season').sum(skipna=False) xr.testing.assert_allclose(actual, expected) ``` I've added info to the repr ``` python ds.weighted(month_length).groupby(""time.season"") ``` ``` WeightedDatasetGroupBy, grouped over 'season' 4 groups with labels 'DJF', 'JJA', 'MAM', 'SON'. weighted along dimensions: time by 'days_in_month' ```","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/5480/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,,13221727,pull