-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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 range indexing for NamedTuple #31423
base: master
Are you sure you want to change the base?
Conversation
Co-Authored-By: eulerkochy <kc99.kol@gmail.com>
This is not what I expected. I feel it makes sense for the output container to match the type and keys of the indexer, for various reasons. |
Sorry @eulerkochy I didn't have much time to elaborate in more detail yesterday, so I suspect what I wrote was confusing! Basically, I'd like to see us preserve a certain relationship that we current have with (possibly offset) array indexing as we introduce non-scalar indexing for more containers. Firstly, if For more context may I point you at #24019 and Indexing.jl for some examples. (I may have written more details elsewhere, I can't remember... I also might have mentioned this at JuliaCon 2018). Anyway, choosing the output container type is a semantic choice. We should also allow indexing of named tuples with arrays if you want the output to be an array. I feel there should be a full set of indexing relationships in Finally, due to some ambiguities in dictionaries (and |
Regarding the last point, the pertinent issue is #30845 |
What do you propose for this |
Possibly |
@andyferris using the map implementation, we can achieve that, but it doesn't seem quite intuitive |
What would you intuit, @eulerkochy? |
I couldn't quite understand the need to make the outer container to be of the same type of the inner one, ofc there's no harm in doing that, but returning a |
The keys, yes, I agree. But I'm not as certain on the type of the indexer as a general rule. Should this return an array or a tuple? Currently, indexing a tuple by a vector returns a tuple. It's a bit of a trap as it's type-unstable without using static arrays, but that may improve with constant propagation in the future (#31138). I think I'd expect NamedTuples to behave like Tuples here. Even if we do decide that |
@mbauman I feel there is much to be gained by giving the power to decide to the user. We currently need to support things like
and it would be useful to generalize the pattern such that
in which case the user is able to decide. If the user requires, for some reason, to get a tuple out they can just index with a tuple. And so-on. If they need something else they can use that. For the user to be empowered I think the pattern needs to be consistent. There are loads of cool stuff you can do with indexing - one of my favorite examples is indexing tables with other tables with a foreign key relationship to perform a relational inner join (using structures like At the moment we support non-scalar indexing with arrays and kind-of, slightly, a little bit with tuples. (IIRC you can do (In practice for 1D containers we possibly only need the surface syntax |
Yes, I agree with the end goal, but I just see a lot of breakage getting there. Thus:
This is just one more method that'd need to be deprecated and an easy transition (especially compared to everything else). |
Maybe I wasn't clear - I really don't want to see any breakage. :)
My view is that we should avoid adding any new non-scalar indexing behavior to |
Fixes #27021 .