Deedle icon indicating copy to clipboard operation
Deedle copied to clipboard

Allowing indexing series/frame by strings

Open hmansell opened this issue 12 years ago • 5 comments

I've found myself using classes for series keys and frame keys fairly often. One inconvenience there is that I have to construct the right instance of the class in order to index. One convenient hack for exploration would be to allow indexing using the ToString() of the object. For example, suppose I have a series that looks like this:

val prices: Series<DataProperty, double> = 
MSFT.price => 123
GOOG.price => 123

Where DataProperty is some class that defines a property from our market data system.

It would be nice to be able to index using prices.["MSFT.price"], which currently does not type-check, of course. It would have to index using the ToString() version of the object.

Anyone vomiting in their mouths at that suggestion?

hmansell avatar Nov 27 '13 00:11 hmansell

This sounds like a reasonable suggestion - after all, we are trying to make the library as convenient as possible, as long as it does not cause any headaches to the usability of the API.

I think we can only do this if F# & C# can reasonably resolve between two overloads when we have Series<string, float>:

get_Item : 'TKey -> 'TValue   (where 'TKey = string)
get_Item : string -> 'TValue

I'm not entirely sure how to best do this, though. We would probably need to keep two look up tables in the index (one based on the original objects, another based on the formatted strings) - to avoid simply iterating over all items. I suppose we can also assume that this string-based lookup is never sorted.

tpetricek avatar Nov 27 '13 14:11 tpetricek

Yes, I thought of the ambiguity issue but my sense is that it should work, and will pick the string->'TValue over the generic. But I haven't checked the spec.

On Wed, Nov 27, 2013 at 9:23 AM, Tomas Petricek [email protected]:

This sounds like a reasonable suggestion - after all, we are trying to make the library as convenient, as long as it does not cause any headaches to the usability of the API.

I'm not entirely sure how to best do this, though. We would probably need to keep two look up tables in the index (one based on the original objects, another based on the formatted strings) - to avoid simply iterating over all items. I suppose we can also assume that this string-based lookup is never sorted.

Also, we can only do this if F# & C# can reasonably resolve between two overloads when we have Series<string, float>:

get_Item : 'TKey -> 'TValue (where 'TKey = string) get_Item : string -> 'TValue

— Reply to this email directly or view it on GitHubhttps://github.com/BlueMountainCapital/Deedle/issues/80#issuecomment-29387541 .

hmansell avatar Dec 02 '13 16:12 hmansell

Sounds more like a deficiency in the implementation of equality on your DataProperty.

JeffreySax avatar Dec 13 '13 18:12 JeffreySax

I tend to agree with @JeffreySax that this is a bit odd use-case - I think DataProperty should let you index using prices.[DataProperty("MSFT", "price")]. But pragmatically speaking, this is ugly and long, so I see your point here...

tpetricek avatar May 22 '14 00:05 tpetricek

It does like you index like that, of course.

And it's clearly not correct for the Equals implementation in DataProperty to return true for a string.

hmansell avatar May 22 '14 12:05 hmansell