-
Notifications
You must be signed in to change notification settings - Fork 6
Mixing slices and individual labels to select along the same axis #429
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
Comments
this is basically a duplicate of #360. There is a reason but I have no time to explain that now. |
That reason is technical or philosophical? (this issue comes from the demand of one our current user) |
I would say neither. It is because it has many syntax implications on other stuff and I never had both the time AND a clear enough mind to think this through. It is related to #23 and the whole constellation of related issues and how to make our API future-proof. >>> a = Axis('a=a0..a4')
>>> # when using the string syntax, it seems natural that:
>>> a['a0:a2,a4']
a[['a0', 'a1', 'a2', 'a4']]
>>> # and
>>> a['a0:a2;a4']
(a['a0':'a2'], a['a4'])
>>> # BUT I want to have a way to do it easily using the non string syntax AND keep both syntaxes consistent
>>> a['a0':'a2', 'a4']
a[['a0', 'a1', 'a2', 'a4']]
OR?
(a['a0':'a2'], a['a4']) and I have been leaning on the second one because we can easily add something to go from multiple groups to a single group, but not the opposite. But given the inconsistency with the string syntax, this yielded a deadlock. The question is thus: is there an alternative to make creating several groups containing slices on the same axis easily? FWIW, for non slices, this is a non-issue: >>> a[['a0', 'a1', 'a2'], ['a4']]
(a['a0', 'a1', 'a2'], a['a4'])
>>> a[['a0', 'a1', 'a2', 'a4']]
a[['a0', 'a1', 'a2', 'a4']] |
One alternative would be to use a "slice builder" (e.g S) and move subgroups in lists, but this feels too hard/unatural to my tastes: >>> a[[S['a0':'a2']], ['a4']]
(a['a0':'a2'], a['a4'])
>>> a['a0':'a2', 'a4']
a[['a0', 'a1', 'a2', 'a4']] |
Assuming we keep the >>> a['a0':'a2', 'a4']
a[['a0', 'a1', 'a2', 'a4']] We have a few options: >>> # in the worst case, we can use the following syntax. We will get it "for free" because :
>>> # * we need anyway to implement G[] to easily create groups without axis,
>>> # * we need to keep `axis[several, group]` returning `(axis[several], axis[group])`
>>> a[G['a0':'a2'], G['a4']]
(a['a0':'a2'], a['a4'])
>>> # but we could implement this too:
>>> a.groups['a0':'a2', 'a4']
(a['a0':'a2'], a['a4'])
>>> # unsure what we should return in that case though (maybe raise an exception?):
>>> a[G['a0':'a2'], 'a4'] FWIW: here is one of my use cases in MOSES: >>> # current code
>>> clength_groups = (x.clength[1:15], x.clength[16:25], x.clength[26:30], x.clength[31:35], x.clength[36:40], x.clength[41:50])
>>> # potential improvements
>>> clength_groups = x.clength[G[1:15], G[15:25], G[26:30], G[31:35], G[36:40], G[41:50]]
>>> clength_groups = x.clength.groups[1:15, 15:25, 26:30, 31:35, 36:40, 41:50] |
so basically, we can start implementing this. |
release 0.27? |
If you feel like so. My comment was just meant as "it is no longer blocked by my hesitation for indirect consequences of this". |
I met this need in planet |
With the current LArray version, the easiest workaround is to use "union": arr[a["a0:a2"].union(a["a4"])] |
As I understand, >>> a = Axis('a=a0..a4')
>>> a.groups['a0':'a2', 'a4']
(a['a0':'a2'], a['a4']) BUT that would generate anonymous groups leading to ugly automatic labels when performing an aggregation. Furthermore, that doesn't solve the problem when the user actually wants to create a unique group with labels given by mixing a slice and a list of individual labels. This my understanding of |
Axis.groups[] does not exist yet AFAIK, it was just an idea to support the use case where users want to create several groups on the same axis "quickly" if we make Axis[slice, slice] return a single group. |
Uh oh!
There was an error while loading. Please reload this page.
The idea is to be able to select a subset as follow:
Is there any good reason why it doesn't work up to now?
Current workaround is:
The text was updated successfully, but these errors were encountered: