Skip to content
forked from pydata/xarray

Commit 57c92d3

Browse files
committed
Raise error when assigning IndexVariable.values
Fixes pydata#3470
1 parent 650a981 commit 57c92d3

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

xarray/core/variable.py

+7
Original file line numberDiff line numberDiff line change
@@ -2065,6 +2065,13 @@ def data(self, data):
20652065
if not isinstance(self._data, PandasIndexAdapter):
20662066
self._data = PandasIndexAdapter(self._data)
20672067

2068+
@Variable.values.setter # type: ignore
2069+
def values(self, values):
2070+
raise ValueError(
2071+
f"Cannot assign to the .values attribute of dimension coordinate a.k.a IndexVariable {self.name!r}. "
2072+
f"Please use DataArray.assign_coords, Dataset.assign_coords or Dataset.assign as appropriate."
2073+
)
2074+
20682075
def chunk(self, chunks=None, name=None, lock=False):
20692076
# Dummy - do not chunk. This method is invoked e.g. by Dataset.chunk()
20702077
return self.copy(deep=False)

0 commit comments

Comments
 (0)