issues: 366626025
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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
366626025 | MDU6SXNzdWUzNjY2MjYwMjU= | 2461 | Set one-dimensional data variable as dimension coordinate? | 43126798 | closed | 0 | 13 | 2018-10-04T05:19:25Z | 2019-11-21T23:57:15Z | 2018-10-04T06:22:03Z | CONTRIBUTOR | Code SampleI have this dataset, and I'd like to make it indexable by time:
Problem descriptionI expected to be able to use Expected Output```python ds.set_coords('time', inplace=True) <xarray.Dataset> Dimensions: (station_observations: 46862) Coordinates: time (station_observations) datetime64[ns] ... Dimensions without coordinates: station_observations Data variables: SNOW_ON_THE_GROUND (station_observations) float64 ... ONE_DAY_SNOW (station_observations) float64 ... ONE_DAY_RAIN (station_observations) float64 ... ONE_DAY_PRECIPITATION (station_observations) float64 ... MIN_TEMP (station_observations) float64 ... MAX_TEMP (station_observations) float64 ... Attributes: elevation: 15.0 In [95]: ds.sel(time='1896') ValueError: dimensions or multi-index levels ['time'] do not exist ``` with assign_coords: ```python In [97]: ds=ds.assign_coords(station_observations=ds.time) In [98]: ds.sel(station_observations='1896') Out[98]: <xarray.Dataset> Dimensions: (station_observations: 366) Coordinates: * station_observations (station_observations) datetime64[ns] 1896-01-01 ... Data variables: time (station_observations) datetime64[ns] ... SNOW_ON_THE_GROUND (station_observations) float64 ... ONE_DAY_SNOW (station_observations) float64 ... ONE_DAY_RAIN (station_observations) float64 ... ONE_DAY_PRECIPITATION (station_observations) float64 ... MIN_TEMP (station_observations) float64 ... MAX_TEMP (station_observations) float64 ... Attributes: elevation: 15.0 ``` works correctly, but looks ugly. It would be nice if the time variable could be assigned as a dimension directly. I can drop the time variable and rename the station_observations, but it's a little annoying to do so. Output of
|
{ "url": "https://api.github.com/repos/pydata/xarray/issues/2461/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
completed | 13221727 | issue |