Return a new Variable object whose contents are consistent with getting the provided key from the underlying data. NB. __getitem__ and __setitem__ implement xarray-style indexing, where if keys are unlabeled arrays, we index the array orthogonally with them. If keys
(self, key)
| 813 | return out_dims, VectorizedIndexer(tuple(out_key)), new_order |
| 814 | |
| 815 | def __getitem__(self, key) -> Self: |
| 816 | """Return a new Variable object whose contents are consistent with |
| 817 | getting the provided key from the underlying data. |
| 818 | |
| 819 | NB. __getitem__ and __setitem__ implement xarray-style indexing, |
| 820 | where if keys are unlabeled arrays, we index the array orthogonally |
| 821 | with them. If keys are labeled array (such as Variables), they are |
| 822 | broadcasted with our usual scheme and then the array is indexed with |
| 823 | the broadcasted key, like numpy's fancy indexing. |
| 824 | |
| 825 | If you really want to do indexing like `x[x > 0]`, manipulate the numpy |
| 826 | array `x.values` directly. |
| 827 | """ |
| 828 | dims, indexer, new_order = self._broadcast_indexes(key) |
| 829 | indexable = as_indexable(self._data) |
| 830 | |
| 831 | data = indexing.apply_indexer(indexable, indexer) |
| 832 | |
| 833 | if new_order: |
| 834 | data = duck_array_ops.moveaxis(data, range(len(new_order)), new_order) |
| 835 | return self._finalize_indexing_result(dims, data) |
| 836 | |
| 837 | def _finalize_indexing_result(self, dims, data) -> Self: |
| 838 | """Used by IndexVariable to return IndexVariable objects when possible.""" |
nothing calls this directly
no test coverage detected