pydata / pydata/xarray

interpolation of xarray do not preserve attributes

Open
#6,423 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

What is your issue?

Hi all,
Interpolation over an xarray variable do not preserve its attributes:
Here is a minimal example

x=np.arange(100)
x=xr.DataArray(x, dims='x', coords={'x':x})
t=np.arange(40,60,0.5)
t=xr.DataArray(t, dims='t', coords={'t':t}, attrs={'units':'s'})
result = x.interp(x=t)

t coordinate in result do not have the t unit anymore

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 with the minimal Python example in the issue and inspect the DataArray.interp path to see where the input coordinate attributes are lost. The fix is complete when the interpolated t coordinate retains its units attribute, with regression coverage for this example.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.