MCPcopy Index your code
hub / github.com/pydata/xarray / __setitem__

Method __setitem__

xarray/core/dataarray.py:895–911  ·  view source on GitHub ↗
(self, key: Any, value: Any)

Source from the content-addressed store, hash-verified

893 return self.isel(indexers=self._item_key_to_dict(key))
894
895 def __setitem__(self, key: Any, value: Any) -> None:
896 if isinstance(key, str):
897 self.coords[key] = value
898 else:
899 # Coordinates in key, value and self[key] should be consistent.
900 # TODO Coordinate consistency in key is checked here, but it
901 # causes unnecessary indexing. It should be optimized.
902 obj = self[key]
903 if isinstance(value, DataArray):
904 assert_coordinate_consistent(value, obj.coords.variables)
905 value = value.variable
906 # DataArray key -> Variable key
907 key = {
908 k: v.variable if isinstance(v, DataArray) else v
909 for k, v in self._item_key_to_dict(key).items()
910 }
911 self.variable[key] = value
912
913 def __delitem__(self, key: Any) -> None:
914 del self.coords[key]

Callers

nothing calls this directly

Calls 3

_item_key_to_dictMethod · 0.95
itemsMethod · 0.80

Tested by

no test coverage detected