Skip to content

Commit a97b373

Browse files
committed
Add more logs
1 parent c3db166 commit a97b373

2 files changed

Lines changed: 35 additions & 4 deletions

File tree

xarray/namedarray/_array_api/_utils.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,29 @@ def _dims_from_tuple_indexing(dims: _Dims, key: _IndexKeysDims) -> _Dims:
560560
raise NotImplementedError(
561561
f"What happens here? {key_no_ellipsis=}, {dims=}, {i=}, {k=}"
562562
)
563+
# If T contains at least one non-zero-dimensional integer array,
564+
# all elements of T must be broadcast against each other to determine
565+
# a common shape S2 = (s1, s2, ..., sN) according to standard
566+
# broadcasting rules (see Broadcasting). If one or more elements in T
567+
# are not broadcast-compatible with the others, an exception must be
568+
# raised.
569+
570+
# After broadcasting elements of T to a common shape S2, the resulting
571+
# tuple U = (u1, u2, ..., uN) must only contain integer arrays having
572+
# shape S2 (i.e.,
573+
# u1 = broadcast_to(t1, S2),
574+
# u2 = broadcast_to(t2, S2), et cetera).
575+
576+
# Each element in U must specify a multi-dimensional index
577+
# v_i = (u1[i], u2[i], ..., uN[i]), where i ranges over S2. The result
578+
# of A[U] must be constructed by gathering elements from A at each
579+
# coordinate tuple v_i. For example, let A have shape (4,4) and U
580+
# contain integer arrays equivalent to ([0,1], [2,3]), with u1 = [0,1]
581+
# and u2 = [2,3]. The resulting coordinate tuples must be (0,2) and
582+
# (1,3), respectively, and the resulting array must have shape (2,)
583+
# and contain elements A[(0,2)] and A[(1,3)].
584+
585+
# The result of A[U] must be an array having the broadcasted shape S2.
563586

564587
return tuple(new_dims)
565588

xarray/namedarray/core.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,9 @@ def __getitem__(
692692
<xarray.NamedArray (z: 2, x: 1)> Size: 16B
693693
array([[4],
694694
[4]])
695+
>>> key = NamedArray(("z", "y"), np.array([[1], [-1]]))
696+
>>> x[key]
697+
695698
696699
OLD
697700
@@ -747,10 +750,15 @@ def __getitem__(
747750
# TODO: __getitem__ not always available, use expand_dims
748751
_key_tuple = key if isinstance(key, tuple) else (key,)
749752
# _dims = _dims_from_tuple_indexing(self.dims, _key_tuple)
750-
_dims = _dims_from_tuple_indexing(
751-
self.dims,
752-
tuple(k.dims if isinstance(k, NamedArray) else k for k in _key_tuple),
753-
)
753+
try:
754+
_dims = _dims_from_tuple_indexing(
755+
self.dims,
756+
tuple(
757+
k.dims if isinstance(k, NamedArray) else k for k in _key_tuple
758+
),
759+
)
760+
except Exception as e:
761+
raise NotImplementedError(f"{self=}\n{key=}")
754762

755763
_data = self._data[
756764
tuple(k._data if isinstance(k, NamedArray) else k for k in _key_tuple)

0 commit comments

Comments
 (0)