issues: 559283550
This data as json
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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
559283550 | MDU6SXNzdWU1NTkyODM1NTA= | 3745 | groupby drops the variable used to group | 22245117 | open | 0 | 0 | 2020-02-03T19:25:06Z | 2022-04-09T02:25:17Z | CONTRIBUTOR | MCVE Code Sample
Seasonal meands_season = ds.groupby('time.season').mean() ds_season ``` <xarray.Dataset> Dimensions: (season: 4, x: 275, y: 205) Coordinates: yc (y, x) float64 16.53 16.78 17.02 17.27 ... 28.26 28.01 27.76 27.51 xc (y, x) float64 189.2 189.4 189.6 189.7 ... 17.65 17.4 17.15 16.91 * season (season) object 'DJF' 'JJA' 'MAM' 'SON' Dimensions without coordinates: x, y Data variables: Tair (season, y, x) float64 nan nan nan nan ... 23.13 22.06 21.72 21.94 ```python The seasons are ordered in alphabetical order.I want to sort them based on time.But time was dropped, so I have to do this:time_season = ds['time'].groupby('time.season').mean() ds_season.sortby(time_season) ``` <xarray.Dataset> Dimensions: (season: 4, x: 275, y: 205) Coordinates: yc (y, x) float64 16.53 16.78 17.02 17.27 ... 28.26 28.01 27.76 27.51 xc (y, x) float64 189.2 189.4 189.6 189.7 ... 17.65 17.4 17.15 16.91 * season (season) object 'SON' 'DJF' 'MAM' 'JJA' Dimensions without coordinates: x, y Data variables: Tair (season, y, x) float64 nan nan nan nan ... 29.27 28.39 27.94 28.05 Expected Output```python Why does groupby drop time?I would expect a dataset that looks like this:ds_season['time'] = time_season ds_season ``` <xarray.Dataset> Dimensions: (season: 4, x: 275, y: 205) Coordinates: yc (y, x) float64 16.53 16.78 17.02 17.27 ... 28.26 28.01 27.76 27.51 xc (y, x) float64 189.2 189.4 189.6 189.7 ... 17.65 17.4 17.15 16.91 * season (season) object 'DJF' 'JJA' 'MAM' 'SON' Dimensions without coordinates: x, y Data variables: Tair (season, y, x) float64 nan nan nan nan ... 23.13 22.06 21.72 21.94 time (season) object 1982-01-16 12:00:00 ... 1981-10-17 00:00:00 Problem DescriptionI often use Output of
|
{ "url": "https://api.github.com/repos/pydata/xarray/issues/3745/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
13221727 | issue |