larry-discuss team mailing list archive
-
larry-discuss team
-
Mailing list archive
-
Message #00132
Re: Index by label support added to experimental branch
On Tue, Feb 9, 2010 at 7:23 AM, Keith Goodman <kwgoodman@xxxxxxxxx> wrote:
> On Mon, Feb 8, 2010 at 8:42 PM, <josef.pktd@xxxxxxxxx> wrote:
>> I'm just reading the new lix
>>
>> For this case lar.lix[['a']:['b']:2]
>>
>> why do you need the list check? you raise a ValueError if it's not a
>> list. this and the fact that slicing start and stop need to be valid
>> labels, seems to indicate that the list is not necessary, i.e.
>> lar.lix['a':'b':2] , and lar.lix['a':'b':2,...] should be unambiguous
>> for any label type.
>> Do you have an example where this would break? I don't see one right now.
>
> Yes, good point, removing the list requirement for slices should work.
> If, however, we keep the list requirement, then by adding one if
> statement to lix we can also index with integers:
>
> lar.lix[0, ['a', 'b']]
> lar.lix[1:[date1]]
> lar.lix[5, [date1]:-1]
>
> That might make it easier to loop:
>
> for i in range(lar.shape[0]):
> date = datetime.date(2010,1,1) + datetime.timedelta(i)
> y = lar.lix[i, [date]]
>
> And I could even eventually add some tuple support in the form:
>
> lar.lix[([date] - 10):[date]]
>
> Yes, I think that woul be powerful. And the integer support comes for
> free if we keep the list requirement.
>
> What do you think?
To add integer indexing (float too if I wrap the scalar in
int(scalar)) I only need to add these lines:
elif isscalar(idx):
index2.append([idx])
elif isscalar(index):
# Example: lar.lix[0]
return y[index]
References