IndexedTables.jl icon indicating copy to clipboard operation
IndexedTables.jl copied to clipboard

Allow a default value?

Open shashi opened this issue 7 years ago • 3 comments

Missing indices now return a KeyError. Let's track the arguments for and against allowing a default value (such as 0) in NDSparse, so that it can behave something like an Array.

Pros:

  • More consistency with arrays

Cons:

  • Indices then are essentially unbounded (is this a problem in practice?)

Unclear:

  • What should join operations do? innerjoin and outerjoin become equivalent since keys can be found in either table.

shashi avatar Dec 03 '17 17:12 shashi

I know this is an old issue but I just had need for this feature in my project. I'm looking up a key which may not exist. If it doesn't exist, I would like to obtain missing.

I tried to just implement this manually, but it doesn't seem like haskey is implemented for NDSparse. Was this intentional? I could submit a PR for it.

aaowens avatar Mar 03 '19 23:03 aaowens

We should have a haskey method. A PR would be great!

I lean towards get and get! methods over default values. Those should be straightforward to implement as well if you're up for it. Otherwise I'll add them when I can.

joshday avatar Mar 04 '19 13:03 joshday

haskey is nice but I agree that get and get! methods sounds like the ideal solution (as well as get with a function argument to be run only if the value is not found, which we could even use to implement getindex, to avoid code duplication).

piever avatar Mar 05 '19 09:03 piever