Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using uint64 for Dataset indexing gives ValueError #1405

Closed
gerritholl opened this issue May 11, 2017 · 2 comments
Closed

Using uint64 for Dataset indexing gives ValueError #1405

gerritholl opened this issue May 11, 2017 · 2 comments
Labels

Comments

@gerritholl
Copy link
Contributor

Trying to index a Dataset using an index array of dtype uint64 yields a ValueError. int64 works fine. See below:

In [13]: import xarray

In [14]: ds = xarray.Dataset({"A": (("x", "y"), arange(5*6).reshape(5,6))})

In [15]: ds[{"x": numpy.array([0], dtype="int64")}]
Out[15]: 
<xarray.Dataset>
Dimensions:  (x: 1, y: 6)
Dimensions without coordinates: x, y
Data variables:
    A        (x, y) int64 0 1 2 3 4 5

In [16]: ds[{"x": numpy.array([0], dtype="uint64")}]
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-16-4cf23af0967e> in <module>()
----> 1 ds[{"x": numpy.array([0], dtype="uint64")}]

/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/xarray/core/dataset.py in __getitem__(self, key)
    722         """
    723         if utils.is_dict_like(key):
--> 724             return self.isel(**key)
    725 
    726         if hashable(key):

/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/xarray/core/dataset.py in isel(self, drop, **indexers)
   1147         for name, var in iteritems(self._variables):
   1148             var_indexers = dict((k, v) for k, v in indexers if k in var.dims)
-> 1149             new_var = var.isel(**var_indexers)
   1150             if not (drop and name in var_indexers):
   1151                 variables[name] = new_var

/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/xarray/core/variable.py in isel(self, **indexers)
    547             if dim in indexers:
    548                 key[i] = indexers[dim]
--> 549         return self[tuple(key)]
    550 
    551     def squeeze(self, dim=None):

/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/xarray/core/variable.py in __getitem__(self, key)
    377         dims = tuple(dim for k, dim in zip(key, self.dims)
    378                      if not isinstance(k, integer_types))
--> 379         values = self._indexable_data[key]
    380         # orthogonal indexing should ensure the dimensionality is consistent
    381         if hasattr(values, 'ndim'):

/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/xarray/core/indexing.py in __getitem__(self, key)
    467 
    468     def __getitem__(self, key):
--> 469         key = self._convert_key(key)
    470         return self._ensure_ndarray(self.array[key])
    471 

/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/xarray/core/indexing.py in _convert_key(self, key)
    454         if any(not isinstance(k, integer_types + (slice,)) for k in key):
    455             # key would trigger fancy indexing
--> 456             key = orthogonal_indexer(key, self.shape)
    457         return key
    458 

/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/xarray/core/indexing.py in orthogonal_indexer(key, shape)
     78     """
     79     # replace Ellipsis objects with slices
---> 80     key = list(canonicalize_indexer(key, len(shape)))
     81     # replace 1d arrays and slices with broadcast compatible arrays
     82     # note: we treat integers separately (instead of turning them into 1d

/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/xarray/core/indexing.py in canonicalize_indexer(key, ndim)
     66         return indexer
     67 
---> 68     return tuple(canonicalize(k) for k in expanded_indexer(key, ndim))
     69 
     70 

/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/xarray/core/indexing.py in <genexpr>(.0)
     66         return indexer
     67 
---> 68     return tuple(canonicalize(k) for k in expanded_indexer(key, ndim))
     69 
     70 

/dev/shm/gerrit/venv/stable-3.5/lib/python3.5/site-packages/xarray/core/indexing.py in canonicalize(indexer)
     63                                      'array indexing; all subkeys must be '
     64                                      'slices, integers or sequences of '
---> 65                                      'integers or Booleans' % indexer)
     66         return indexer
     67 

ValueError: invalid subkey array([0], dtype=uint64) for integer based array indexing; all subkeys must be slices, integers or sequences of integers or Booleans
@Zac-HD
Copy link
Contributor

Zac-HD commented Oct 23, 2017

I think this was closed by #1473.

@shoyer
Copy link
Member

shoyer commented Oct 23, 2017

Yes, this is fixed.

@shoyer shoyer closed this as completed Oct 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants