kwgoodman / la

Meet larry, the labeled numpy array
http://pypi.python.org/pypi/la
Other
44 stars 20 forks source link

boolean 1d larry indexing for getting items. #61

Closed stroxler closed 12 years ago

stroxler commented 12 years ago

At least for 1d larrys, it makes sense to allow users to get a subset using a larry for indexing. I believe this functionality actually exists already for setting items. So if larry is 1d, the following could be legal:

>>> larry[larry < 0].sum()

At the moment, this will crash; instead you have to do

>>> larry[larry.x < 0].sum()

We could be very strict about this and only allow 1d larrys where the indexing larry is a perfect match in terms of labels. If we were ambitious we could flatten higher-d larrys (that's what numpy does), but dealing with the labels could make that too confusing to justify the convenience.

kwgoodman commented 12 years ago

First step is done in commit 49ff728d47: refactor the larry.getitem unit tests. Next step would be to add unit tests for bool 1d larry indexing.

kwgoodman commented 12 years ago

I did a quick fix to add this feature. Give it a try to make sure it behaves as you expect.

stroxler commented 12 years ago

Looks great to me!