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

setting values with getattr performs wrong opperation with multi-dimensional coordinate #1430

Closed
d-chambers opened this issue May 27, 2017 · 3 comments

Comments

@d-chambers
Copy link

I am using Ubuntu 16, python 3.6, and xarray 0.9.1

Consider the following code:

import xarray as xr
import numpy as np

dims = ['a', 'b']
coords = {'a': range(2), 'b':range(2), 'group': (('a', 'b'), [[0, 0], [0, 1]])}
values = [[0, 0], [0, 0]]

dar = xr.DataArray(values, coords, dims)

dar[dict(group=0)] = 1  # group is only 0 for three of the four elements

expected_values = np.array([[1, 1], [1, 0]])
# yet this raises because all four values are set to 1
assert np.all(np.isclose(dar.values, expected_values))

I suspect trying to assign values in this way using a multi-dimensional coordinate should raise a ValueError as this does:

dar[dict(group=0)]
@shoyer
Copy link
Member

shoyer commented May 30, 2017

Thanks for the report. This should actually raise an error instead -- indexing with coordinates that don't go along a dimension is not supported. For example, note:

In [37]: dar[dict(group=0)]
ValueError: dimensions ['group'] do not exist

@stale
Copy link

stale bot commented Apr 30, 2019

In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity

If this issue remains relevant, please comment here or remove the stale label; otherwise it will be marked as closed automatically

@stale stale bot added the stale label Apr 30, 2019
@jhamman
Copy link
Member

jhamman commented Apr 30, 2019

I think this can be safely closed now. Running the example above now raises a ValueError:

dar[dict(group=0)] = 1
...
ValueError: dimensions ['group'] do not exist

@jhamman jhamman closed this as completed Apr 30, 2019
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

3 participants