IndexedTables.jl
IndexedTables.jl copied to clipboard
Allow a default value?
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
andouterjoin
become equivalent since keys can be found in either table.
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.
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.
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).