Skip to content
forked from pydata/xarray

Commit fe7f100

Browse files
committed
Raise error when assigning IndexVariable.values, IndexVariable.data
Fixes pydata#3470
1 parent 650a981 commit fe7f100

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

xarray/core/variable.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -2061,9 +2061,17 @@ def load(self):
20612061
# https://github.com/python/mypy/issues/1465
20622062
@Variable.data.setter # type: ignore
20632063
def data(self, data):
2064-
Variable.data.fset(self, data)
2065-
if not isinstance(self._data, PandasIndexAdapter):
2066-
self._data = PandasIndexAdapter(self._data)
2064+
raise ValueError(
2065+
f"Cannot assign to the .data attribute of dimension coordinate a.k.a IndexVariable {self.name!r}. "
2066+
f"Please use DataArray.assign_coords, Dataset.assign_coords or Dataset.assign as appropriate."
2067+
)
2068+
2069+
@Variable.values.setter # type: ignore
2070+
def values(self, values):
2071+
raise ValueError(
2072+
f"Cannot assign to the .values attribute of dimension coordinate a.k.a IndexVariable {self.name!r}. "
2073+
f"Please use DataArray.assign_coords, Dataset.assign_coords or Dataset.assign as appropriate."
2074+
)
20672075

20682076
def chunk(self, chunks=None, name=None, lock=False):
20692077
# Dummy - do not chunk. This method is invoked e.g. by Dataset.chunk()

0 commit comments

Comments
 (0)