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

Method __setitem__

xarray/core/variable.py:886–914  ·  view source on GitHub ↗

__setitem__ is overloaded to access the underlying numpy values with orthogonal indexing. See __getitem__ for more details.

(self, key, value)

Source from the content-addressed store, hash-verified

884 return self._finalize_indexing_result(dims, data)
885
886 def __setitem__(self, key, value):
887 """__setitem__ is overloaded to access the underlying numpy values with
888 orthogonal indexing.
889
890 See __getitem__ for more details.
891 """
892 dims, index_tuple, new_order = self._broadcast_indexes(key)
893
894 if not isinstance(value, Variable):
895 value = as_compatible_data(value)
896 if value.ndim > len(dims):
897 raise ValueError(
898 f"shape mismatch: value array of shape {value.shape} could not be "
899 f"broadcast to indexing result with {len(dims)} dimensions"
900 )
901 if value.ndim == 0:
902 value = Variable((), value)
903 else:
904 value = Variable(dims[-value.ndim :], value)
905 # broadcast to become assignable
906 value = value.set_dims(dims).data
907
908 if new_order:
909 value = duck_array_ops.asarray(value)
910 value = value[(len(dims) - value.ndim) * (np.newaxis,) + (Ellipsis,)]
911 value = duck_array_ops.moveaxis(value, new_order, range(len(new_order)))
912
913 indexable = as_indexable(self._data)
914 indexing.set_with_indexer(indexable, index_tuple, value)
915
916 @property
917 def encoding(self) -> dict[Any, Any]:

Callers

nothing calls this directly

Calls 5

_broadcast_indexesMethod · 0.95
set_dimsMethod · 0.95
as_indexableFunction · 0.90
as_compatible_dataFunction · 0.85
VariableClass · 0.70

Tested by

no test coverage detected