@@ -966,15 +966,21 @@ def __iter__(self) -> Iterator[ChunkProjection]:
966966
967967 # handle advanced indexing arrays orthogonally
968968 if self .is_advanced :
969- # N.B., numpy doesn't support orthogonal indexing directly as yet,
970- # so need to work around via np.ix_. Also np.ix_ does not support a
971- # mixture of arrays and slices or integers, so need to convert slices
972- # and integers into ranges.
973- chunk_selection = ix_ (chunk_selection , self .chunk_shape )
974-
975- # special case for non-monotonic indices
976- if not is_basic_selection (out_selection ):
977- out_selection = ix_ (out_selection , self .shape )
969+ # NumPy can handle a single array-indexed dimension directly,
970+ # which keeps slice dimensions as slices and avoids an
971+ # unnecessary advanced-indexing copy. Integer-indexed
972+ # dimensions still need the ix_ path for downstream squeezing.
973+ n_array_dims = sum (isinstance (sel , np .ndarray ) for sel in chunk_selection )
974+
975+ if n_array_dims > 1 or self .drop_axes :
976+ # N.B., numpy doesn't support orthogonal indexing directly
977+ # for multiple array-indexed dimensions, so we need to
978+ # convert the orthogonal selection into coordinate arrays.
979+ chunk_selection = ix_ (chunk_selection , self .chunk_shape )
980+
981+ # special case for non-monotonic indices
982+ if not is_basic_selection (out_selection ):
983+ out_selection = ix_ (out_selection , self .shape )
978984
979985 is_complete_chunk = all (p .is_complete_chunk for p in dim_projections )
980986 yield ChunkProjection (chunk_coords , chunk_selection , out_selection , is_complete_chunk )
0 commit comments