Open gdementen opened 2 years ago
If we implement this, it should also work for multiple axes at once:
>>> arr = ndtest((3, 4))
>>> arr.extract({'a': {'b1': 'a1', 'b2': 'a0'}, 'b': {'a1': 'b1', 'a3': 'b2'}})
Unsure if that would work for existing axes:
>>> b = Axis('b=b1,b2')
>>> arr.extract({'a': {'b1': 'a1', 'b2': 'a0'}, b: {'a1': 'b1', 'a3': 'b2'}})
Our users relatively often need to extract a few labels from an axis as another (possibly existing) axis with different labels. Currently, they usually use set_axes for this, as in:
But given that the axis definition is often far from the set_axes call (even in a different file), there is a high risk (and I have witnessed this actually happening a few times) to get the labels order wrong, which is a pity given it is one of the missions of LArray to prevent that class of errors.
The alternative I recommend is to use set_labels with a map, but then the original labels are specified twice. Unsure if that is the reason, but our users are generally not very enthusiatic about this recommendation.
I wonder if introducing a new "extract" method would help with this:
Here is a quick and dirty implementation I did for testing:
Another option, would be to generalize aggregate methods to be able to explicitly name the new aggregated axis (see #1002), which we probably need to implement anyway.
Currently, the above "extract" test can also be spelled like:
and it would be nice to be able to express it like this instead:
OR (unsure which, or both):
One final option would be to have an extract method using the same syntax than aggregate methods instead of a dict:
In either case, this does not support the existing axis usecase. I have not found a way to express that nicely yet.