Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

align ignores copy #7737

Open
dcherian opened this issue Apr 7, 2023 · 2 comments
Open

align ignores copy #7737

dcherian opened this issue Apr 7, 2023 · 2 comments

Comments

@dcherian
Copy link
Contributor

dcherian commented Apr 7, 2023

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

@benbovy
Copy link
Member

benbovy commented Jun 20, 2023

@dcherian is it solved by #7736?

@dcherian
Copy link
Contributor Author

I think I fixed it only for exact joins

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants