pydata / pydata/xarray

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

Open
#1,646 8 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

design question enhancement topic-combine
Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two xarray.concat examples, comparing a DataArray dimension argument with the equivalent pandas.Index. Trace how concat derives the dimension name and coordinates; done means passing the DataArray produces the named dimension and coordinate shown in the pandas.Index result.

Written by the indexing model from the issue text.

Assessment

Tech stack
pandas, python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.