pydata / pydata/xarray

Provide a "shrink" command to remove bounding nan/ whitespace of DataArray

Open
#4,197 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I'm currently trying to come up with an elegant solution to remove extra whitespace/ nan-values along the edges of a 2D DataArray. I'm working with geographic data and search for an automatic way to shrink the extend to valid data only. Think a map of the EU, but remove all cols/ rows of the array (starting from the edges) that only contain nan.

image

Describe the solution you'd like
A shrink command that removes all nan rows/ cols at the edges of a DataArray.

Describe alternatives you've considered
I currently do this with NumPy operating on the raw data and creating a new DataArray afterwards

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

The issue identifies DataArray and NumPy as the relevant entry points; start by reviewing existing DataArray indexing and trimming behavior and the NumPy-based workaround described. Done means a shrink operation removes only all-NaN rows and columns from the edges of a 2D DataArray while preserving valid data.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
data
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.