Skip to content

Generic way to detect a tuple structure? #1349

Answered by agoose77
masonproffitt asked this question in Q&A
Discussion options

You must be logged in to vote

Right now, I we don't expose this information at the top-level. ak.Array has the fields attribute which returns ak.operations.describe.fields(self), but we don't yet have an equivalent for istuple.

In v2, we are a bit better at making tuples and records behave predictably with respect to numeric (albeit in string form) fields, but there is still no function to test the entire layout for any tuple. #1351 is one solution for this.

For now, you can do this with a layout visitor:

def is_tuple(array):
    layout = ak.to_layout(array, allow_record=True)

    def visitor(layout):
        if isinstance(layout, (ak.layout.Record, ak.layout.RecordArray)):
            return layout.istuple
        elif

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@jpivarski
Comment options

@jpivarski
Comment options

Answer selected by jpivarski
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants