pydata / pydata/xarray

LazilyOuterIndexedArray doesn't support slicing with slice objects

Open
#3,022 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

Code Sample, a copy-pastable example if possible
from xarray.core.indexing import LazilyOuterIndexedArray
import numpy as np
x = LazilyOuterIndexedArray(np.ones((5, 5)))
x[:3]
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-42bee9beb30a> in <module>
----> 1 x[:3]

~/workspace/xarray/xarray/core/indexing.py in __getitem__(self, indexer)
    518             array = LazilyVectorizedIndexedArray(self.array, self.key)
    519             return array[indexer]
--> 520         return type(self)(self.array, self._updated_key(indexer))
    521
    522     def __setitem__(self, key, value):

~/workspace/xarray/xarray/core/indexing.py in _updated_key(self, new_key)
    483
    484     def _updated_key(self, new_key):
--> 485         iter_new_key = iter(expanded_indexer(new_key.tuple, self.ndim))
    486         full_key = []
    487         for size, k in zip(self.array.shape, self.key.tuple):

AttributeError: 'slice' object has no attribute 'tuple'
Problem description

Dask array meta computations like to run x[:0, :0] on input arrays. This breaks with this class.

This is on master

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in xarray/core/indexing.py at LazilyOuterIndexedArray._updated_key and getitem, then reproduce the reported x[:3] failure with the provided example. Confirm that slice objects, including the dask-style x[:0, :0] case, are accepted without the AttributeError and preserve lazy indexing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
data
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.