-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Names type to allow selecting elements by excluding others #1
Conversation
Add a simple immutable Names type storing a vector of names and a boolean indicating whether these names should be retained or excluded when indexing. Add support for this type in getindex().
BTW, is the fact that names can be set to any type, not only strings, intended? julia> setnames!(n, [1:4], 2)
[4=>4,2=>2,3=>3,1=>1]
julia> xdump(n)
NamedArray{Float64,2}
array: Array(Float64,(2,4)) 2x4 Array{Float64,2}:
0.911343 0.60882 0.453109 0.272036
0.148594 0.12549 0.336926 0.518748
names: Array(Array{T,1},(2,)) [["one","two"],[1,2,3,4]]
dimnames: Array(ASCIIString,(2,)) ["A","B"]
dicts: Array(Dict{K,V},(2,)) [["one"=>1,"two"=>2],[4=>4,2=>2,3=>3,1=>1]] I think this could be useful in some situations, but this requires some type checking (as I do in the commit), and at the moment I see no way to index using names that are not strings. My proposal would also allow that. |
Add Names type to allow selecting elements by excluding others
Thanks! |
Hi Milan, I simplified the code a bit, realising there is not really a need for So there now only is a NoNames type, whose only function is to be What do you think? I also have some support for negative indexes, you you can also say n[:,-2] now. It doesn't always work, because n[2,-2] is dispatched through another Then the next question is: should we change the syntax !(String) to ---david Will this email be delivered? And will it be stored on Github? No idea... On Sun, Nov 17, 2013 at 8:37 PM, Milan Bouchet-Valat <
David van Leeuwen |
I don't really like using NoNames rather than Names, for a few reasons:
Regarding whether As for indexing with negative integers, I'm all for it, but I think it should go into the standard Array object first. Else the inconsistency will be confusing. |
Hi, On Mon, Nov 18, 2013 at 10:14 AM, Milan Bouchet-Valat
I don't really understand what Names() does, except making its
My idea was to not export NoNames or Names once NamedArray is in a Also, I think that claiming Names as a general type might be a bit
There is the potential ambiguity if I would want to use, say, a Range 1:5 => 1 etc. Pretty hairy, but OK. so what then does n[1:5] refer to? Is this what your Names type tries to be of help? i.e., n[1:5] # traditional meaning I'll revert back if this is the case. Still, I wouldn't mind if there would be a shorter version for Names,
But if the wise people from Base come up with an implementation for Cheers, ---david
I don't seem to be able to find these mails on github... David van Leeuwen |
Non-string indexes would only be supported by using Names, or whatever we call it, for any ambiguous case (Integer and Range, mainly). But I think the need to export or not Names/NoNames really depends on what Julia developers think is reasonable, since the ultimate goal is to get NamedArrays in base Julia or in a blessed package. If they accept the Anyway, it will be interesting to follow the design of NegatedIndex from JuliaLang/julia#1032 : NoNames is really NegatedNames. And the implementation looks very similar. The choice of |
OK, We'll leave the implementation as a hybrid ! or -, we can later cut out the I put Names() back. I tried using it with a Range1 type, but that was very ---david On Mon, Nov 18, 2013 at 1:34 PM, Milan Bouchet-Valat <
David van Leeuwen |
Here's a first stab at the kind of convenience syntax I spoke about on the mailing list. Comments welcome.
This allows things like:
To save more typing, the type could be renamed to e.g. N.