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/4417#issuecomment-1239064150,https://api.github.com/repos/pydata/xarray/issues/4417,1239064150,IC_kwDOAMm_X85J2p5W,4160723,2022-09-07T08:18:08Z,2022-09-07T08:18:08Z,MEMBER,"From discussions in #4825 and elsewhere (e.g., https://github.com/pydata/xarray/issues/6607#issuecomment-1126587818), could we say that we're going towards a consensus that the index vs. coordinate API should be decoupled wherever possible?
If that's the case, then `set_coords()` shouldn't create any index, but it could be chained with `set_index()` if necessary (or `swap_dims()` can be used instead).
Apparently `set_coords()` never created an index? I tested @johnomotani's example back to v0.14. Before v2022.6.0, there was a source of confusion where the `Dataset` and `DataArray` reprs still showed an `*` for the dimension coordinate while it had no index. This is fixed in v2022.6.0 where the reprs are now consistent: no `*` and no index. Does this solve the issue here?
@johnomotani from your example it looks like the two alternatives below would produce the desired result with v2022.6.0:
- `ds.set_index(x='b')`
- `ds.rename(b='x').set_coords('x').set_index(x='x')`
I would encourage using the latter. It is more verbose but clearer (each method is explicit).
Note also that Xarray now also supports non-dimension coordinates with an index. Once #6971 is merged, renaming ""b"" to ""x"" won't be needed. Instead you'll be able to do something like:
```
ds = xr.Dataset()
ds['a'] = ('x', np.linspace(0,1))
ds['b'] = ('x', np.linspace(3,4))
ds = ds.set_coords('b').set_xindex('b')
ds.sel(b=...)
```
","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,698577111
https://github.com/pydata/xarray/issues/4417#issuecomment-691099568,https://api.github.com/repos/pydata/xarray/issues/4417,691099568,MDEyOklzc3VlQ29tbWVudDY5MTA5OTU2OA==,2448579,2020-09-11T13:36:34Z,2020-09-11T13:36:34Z,MEMBER,I think I was trying to fix this in #4108,"{""total_count"": 1, ""+1"": 1, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,698577111
https://github.com/pydata/xarray/issues/4417#issuecomment-690815529,https://api.github.com/repos/pydata/xarray/issues/4417,690815529,MDEyOklzc3VlQ29tbWVudDY5MDgxNTUyOQ==,5635139,2020-09-11T01:17:42Z,2020-09-11T01:17:42Z,MEMBER,"Thanks for the clear example @johnomotani !
IIRC, the second creates an index because `ds['x'] = ('x', np.linspace(3,4))` is setting a 1D variable where the name of the variable matches the name of its dimension.
I can see why this is a bit confusing, though it's not an unreasonable default imo. There have been some discussions on this on the issue tracker.
Does `ds.set_index(x='b')` align the examples? Or do you think there's still some confusion from the API?","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,698577111