pydata / pydata/xarray

Feature request: xr.concat: `stack` parameter

Open
#4,486 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Is your feature request related to a problem? Please describe.
In the case of dependent dimensions, there is a lot of missing data, and using a stacked layout is preferable. Composing an array using concat and then stack is not very memory efficient and results in NaN's that have to be removed.

I am now composing an array using concat and then reshaping using stack. This can consume a lot of memory, and requires explicit removal of the NaN's after stacking. Having a stack parameter to concat that takes the desired index would be very useful.

Describe the solution you'd like
A stack parameter to concat that takes the desired index would be very useful.

Initially it may just do the naive concat followed by a stack and removal of NaN, but eventually it should insert items correctly without creating NaN.

Describe alternatives you've considered
Composing an array using concat and then stack is not very memory efficient and results in NaN's that have to be removed.

Additional context
Issue related to concat and stack https://github.com/pydata/xarray/issues/981.

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 at the concat and stack entry points and review related issue #981 to understand the existing behavior and proposed API. Done means concat accepts a stack index and produces the requested stacked layout without requiring explicit NaN removal, with the initial naive behavior treated as an interim option.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.