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

Support fancy indexing #42

Open
fperez opened this issue Apr 8, 2011 · 2 comments
Open

Support fancy indexing #42

fperez opened this issue Apr 8, 2011 · 2 comments

Comments

@fperez
Copy link
Collaborator

fperez commented Apr 8, 2011

Currently fancy indexing isn't supported at all.

In [79]: cap_ax_spec = 'capitals', ['washington', 'london', 'berlin', 'paris', 'moscow']
    ...: time_ax_spec = 'time', ['0015', '0615', '1215', '1815']
    ...: t = DataArray(np.arange(4*5).reshape(4,5), [time_ax_spec, cap_ax_spec])
    ...: t.axis.capitals[['paris', 'london']]
    ...: 
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
/home/fperez/research/code/datarray/datarray/ in ()
      2 time_ax_spec = 'time', ['0015', '0615', '1215', '1815']
      3 t = DataArray(np.arange(4*5).reshape(4,5), [time_ax_spec, cap_ax_spec])
----> 4 t.axis.capitals[['paris', 'london']]

/home/fperez/research/code/datarray/datarray/datarray.py in __getitem__(self, key)
    218         # XXX We don't handle fancy indexing at the moment

    219         if isinstance(key, (np.ndarray, list)):
--> 220             raise NotImplementedError('We do not handle fancy indexing yet')
    221         parent_arr = self.parent_arr # local for speed
    222         parent_arr_ndim = parent_arr.ndim

NotImplementedError: We do not handle fancy indexing yet
@fperez
Copy link
Collaborator Author

fperez commented Apr 8, 2011

As a preliminary plan, we can try to:

  • do the equivalent of asarray(t)[fancy_indexing] but return a DataArray instance, just that it has all its axes unnamed and unlabeled.
  • once the above is working, we can try to define for which cases the semantics of what axes/labels survive the indexing operation are, and implement those.

@fperez
Copy link
Collaborator Author

fperez commented Apr 9, 2011

An example where you manually pick out elements, for example, will necessarily drop dimensions, and something like this can't really preserve any labels/axes, since the output's geometry has nothing to do with the input:

In [110]: a  = arange(12).reshape(3,4)
     ...: b = a[[(1,2,1),(0,1,3)]]
     ...: print a
     ...: print b
[[ 0  1  2  3]
 [ 4  5  6  7]
 [ 8  9 10 11]]
[4 9 7]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant