I remember pointing out this same semantic error in Pandas, as banging my head against a wall that no one seemed to get it.
Consider the following:
In [1]: import xarray as xr
In [2]: xr.DataArray([5,4,3,2,8,-1], dims=('foo',), coords={'foo': ['a', 'b', 'c', 'd', 'e', 'f']}).argsort()
Out[2]:
<xarray.DataArray (foo: 6)>
array([5, 3, 2, 1, 0, 4], dtype=int64)
Coordinates:
* foo (foo) <U1 'a' 'b' 'c' 'd' 'e' 'f'
The resulting values [5, 3, 2, 1, 0, 4] are indices into the original array, and it does not make sense to label them with the foo coordinates 'a', 'b', ..., 'f'. They should just be left as an ndarray.
It *would* make sense to have a function that returned a similarly shaped DataArray whose values are the ordered location of the corresponding values, i.e. something like this:
In [3]: xr.DataArray([5,4,3,2,8,-1], dims=('foo',), coords={'foo': ['a', 'b', 'c', 'd', 'e', 'f']}).rank() # hypothetical
Out[3]:
<xarray.DataArray (foo: 6)>
array([4, 3, 2, 1, 5, 0])
Coordinates:
* foo (foo) <U1 'a' 'b' 'c' 'd' 'e' 'f'