Skip to content
forked from pydata/xarray

Commit

Permalink
Raise error when assigning IndexVariable.values
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed Mar 17, 2020
1 parent 650a981 commit 57c92d3
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions xarray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -2065,6 +2065,13 @@ def data(self, data):
if not isinstance(self._data, PandasIndexAdapter):
self._data = PandasIndexAdapter(self._data)

@Variable.values.setter # type: ignore
def values(self, values):
raise ValueError(
f"Cannot assign to the .values attribute of dimension coordinate a.k.a IndexVariable {self.name!r}. "
f"Please use DataArray.assign_coords, Dataset.assign_coords or Dataset.assign as appropriate."
)

def chunk(self, chunks=None, name=None, lock=False):
# Dummy - do not chunk. This method is invoked e.g. by Dataset.chunk()
return self.copy(deep=False)
Expand Down

0 comments on commit 57c92d3

Please sign in to comment.