← Back to team overview

larry-discuss team mailing list archive

Re: A new proposal for indexing with labels

 

On Sat, Feb 6, 2010 at 6:53 PM,  <josef.pktd@xxxxxxxxx> wrote:
> On Sat, Feb 6, 2010 at 9:48 PM, Keith Goodman <kwgoodman@xxxxxxxxx> wrote:
>> On Sat, Feb 6, 2010 at 5:38 PM, Keith Goodman <kwgoodman@xxxxxxxxx> wrote:
>>> In a blueprint titled "index-by-label" I proposed a way to index
>>> larrys by lists of label elements. Here's a simpler, but less
>>> versatile, proposal. On the whole, due to its simplicity, I think it
>>> is more powerful.
>>
>> I commit this proposal in r187. Please give it a try.
>
> I will try it tomorrow and look at the implementation.
> My first reaction: very convenient but potentially fragile for arbitrary labels.

The rule is simple for indexing with a string S:

1. Look for string S in the label. If found you are done. If not found...
2. Map the labels to strings and look again

Although the rule is simple, the result can be unexpected in corner
cases. For example, you may try to index with str(1) to access the
label integer 1 but the label could also contain string '1'. So in
that case you'd get an unexpected result even though the rule is
simple.

I could add a check: len(set(strlabel)) == len(set(label)). And raise
an IndexError (or is that ValueError?) if they are not equal. That
will slow things down but only for indexing by strings.

Would that address your fragile comment? Or do you have something else in mind?



Follow ups

References