Skip to content

Select several items from a category axis #296

@henryiii

Description

@henryiii

We currently have slice and single item selection (implemented internally as a slice + single item sum), but there is no way to select a list of items from a category axes. Basically this:

If I have a run_number axis with {1,2,5,7}, I would like to be able to select 1, or {1, 5}. The latter will require new syntax in UHI (probably [0,2]::bh.sum or bh.loc([1,5])::bh.sum, for consistency with numpy). There's actually a fairly easy workaround for summing; you can just do:

from functools import reduce
from operator import add

reduce(add, (hist[bh.loc(item)] for item in {1, 5}) )

We need some way to select a subset category. So select 2 and 7, but not 4, for example. It would return a new, smaller category axis. Once we get full UHI, this could be implemented through a UHI object. Or we could come up with a new syntax, like [2,7]::bh.sum or something like that. Note that in Numpy, this would be a list, but there's no need to combine lists and slices, but we would often like to combine lists and actions.

This is easy to implement if it is supported upstream - is it @HDembinski? Basically a way to give a new category axis that is a subset of an existing one and ask for boost-histogram to copy one to the other would be enough.

Was mentioned in #274, but was not the focus of that issue. Brought up independently on gitter by @paulgessinger.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions