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

Assigning an indexed coordinate to a data variable still uses an IndexVariable #9859

Open
shoyer opened this issue Dec 6, 2024 · 0 comments

Comments

@shoyer
Copy link
Member

shoyer commented Dec 6, 2024

What is your issue?

Consider the following example:

In [1]: import xarray

In [2]: ds = xarray.Dataset(coords={'x': [1, 2, 3]})

In [3]: ds['y'] = ds['x']

In [4]: ds
Out[4]:
<xarray.Dataset> Size: 48B
Dimensions:  (x: 3)
Coordinates:
  * x        (x) int64 24B 1 2 3
Data variables:
    y        (x) int64 24B 1 2 3

In [5]: ds['y'].variable
Out[5]:
<xarray.IndexVariable 'x' (x: 3)> Size: 24B
array([1, 2, 3])

In [6]: ds['x'].variable is ds['y'].variable
Out[6]: False

The assigned variable 'y' still uses an IndexVariable under the hood, which means it has immutable data. This is not very useful.

Instead, assigning a DataArray that contains a wrapped IndexVariable to a Dataset should create a new varaible of the base Variable type.

@shoyer shoyer added the needs triage Issue that has not been reviewed by xarray team member label Dec 6, 2024
@TomNicholas TomNicholas added bug topic-internals and removed needs triage Issue that has not been reviewed by xarray team member labels Dec 6, 2024
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