Skip to content

align ignores copy #7737

Open
Open
@dcherian

Description

@dcherian

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

xarray/xarray/core/dataset.py

Lines 2805 to 2818 in f8127fc

def _reindex_callback(
self,
aligner: alignment.Aligner,
dim_pos_indexers: dict[Hashable, Any],
variables: dict[Hashable, Variable],
indexes: dict[Hashable, Index],
fill_value: Any,
exclude_dims: frozenset[Hashable],
exclude_vars: frozenset[Hashable],
) -> Dataset:
"""Callback called from ``Aligner`` to create a new reindexed Dataset."""
new_variables = variables.copy()
new_indexes = indexes.copy()

Describe alternatives you've considered

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions