Skip to content

Make passing a DataArray for the xarray.concat dim argument equivalent to passing a pandas Index #1646

Open
@ceridwen

Description

@ceridwen

Extending from #839, if I'm concatenating some DataArrays using concat,

print(xarray.concat(data, xarray.DataArray(['foo1', 'foo2', 'foo3', 'foo4', 'foo5'], name='stat'))

I get an unnamed dimension without coordinates.

<xarray.DataArray (dim_0: 5, index: 2)>
array([[ 24.841064,   0.750451],
       [ 24.841064,   0.750451],
       [ 19.062874,   0.796722],
       [ 14.9631  ,   0.354273],
       [ 14.9631  ,   0.354273]])
Coordinates:
  * index    (index) object 'Intercept' 'Lvl'
         (dim_0) <U3 'foo1' foo2' 'foo3' 'foo4' 'foo5'
Dimensions without coordinates: dim_0

Using a pandas.Index,

print(xarray.concat(data, pandas.Index(['foo1', 'foo2', 'foo3', 'foo4', 'foo5'], name='stat'))
<xarray.DataArray (stat: 5, index: 2)>
array([[ 14.9631  ,   0.354273],
       [ 19.982272,   0.555708],
       [ 14.974026,   0.60658 ],
       [ 24.841064,   0.750451],
       [ 24.841064,   0.750451]])
Coordinates:
  * index    (index) object 'Intercept' 'Lvl'
  * stat     (stat) object 'foo1' 'foo2' 'foo3' 'foo4' 'foo5'

I want the latter, not the former, but I expected the latter when using a DataArray.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions