Skip to content

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

@d-chambers

Description

@d-chambers

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)]

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