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/2340#issuecomment-410403455,https://api.github.com/repos/pydata/xarray/issues/2340,410403455,MDEyOklzc3VlQ29tbWVudDQxMDQwMzQ1NQ==,1217238,2018-08-03T23:50:21Z,2018-08-03T23:50:21Z,MEMBER,"Thanks for the very clear report!
I believe this is intentional behavior here. Let me try to clarify how xarray determines coordinates for a variable like `expanded_slice.z`. Xarray requires that dimensions of *coordinates* are a subset of dimensions for a DataArray. So when you pull out a coordinate from a DataArray, the rule xarray uses for determining coordinates on the new DataArray object is to include every coordinate from the original DataArray for which all dimensions still exist on new DataArray.
More specifically, let's look at what `expanded_slice` looks like:
```
array([0.])
Coordinates:
y int64 0
* x (x) int64 1
z int64 1
```
`expanded_slice.z` is a scalar DataArray, since `z` is a scalar:
```
array(1)
Coordinates:
y int64 0
z int64 1
```
The coordinate `x` from `expanded_slice` is lost, because it goes along the `x` dimensions which is not found on `expanded_slice.z`.
To answer your specific questions:
> is the relative order of dimensions maintained between data in the same dataset/dataarray?
No, not necessarily. It's possible to define coordinates with different dimension order than the DataArray itself (although this isn't recommended). For example:
```
>>> xarray.DataArray(np.zeros((2, 2)), dims=['x', 'y'], coords={'foo': (('y', 'x'), np.zeros((2, 2)))})
array([[0., 0.],
[0., 0.]])
Coordinates:
foo (y, x) float64 0.0 0.0 0.0 0.0
Dimensions without coordinates: x, y
```
> Can coordinates have MORE dimensions than the array itself?
No, this isn't allowed by xarray's data model.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,347558405