pydata / pydata/xarray

align ignores `copy`

Open
#7,737 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-indexing topic-performance
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?

cc @benbovy

xref #7730

import numpy as np
import xarray as xr

arr = np.random.randn(10, 10, 365*30)
time = xr.date_range("2000", periods=30*365, calendar="noleap")
da = xr.DataArray(arr, dims=("y", "x", "time"), coords={"time": time})
year = da["time.year"]
xr.align(da, year, join="outer", copy=False)

This should result in no copies, but does

image
Describe the solution you'd like

I think we need to check aligner.copy and/or aligner.reindex (maybe?) before copying here

https://github.com/pydata/xarray/blob/f8127fc9ad24fe8b41cce9f891ab2c98eb2c679a/xarray/core/dataset.py#L2805-L2818

Describe alternatives you've considered

No response

Additional context

No response

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 provided xarray.align example, then inspect the referenced section of xarray/core/dataset.py around lines 2805–2818 and trace how copy=False is handled. Done means alignment with copy=False avoids the unnecessary copies shown in the report, with the behavior covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
data, performance
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 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.