Skip to content

Nested Array type inspection, best practices #3049

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

You must be logged in to vote

Awkward Arrays have three levels of type information:

  1. Types ("this is a ragged list", "this is a regular dimension", "this is an option", ...)
  2. Forms ("this is a ragged list with starts and stops", ...)
  3. Contents ("this is a ragged list with starts and stops whose values are ...", ...)

It sounds like you only care about the first one, ak.Array.type.

We would write this kind of test using recursion, e.g.

import awkward as ak


def assert_valid(type_):
    if isinstance(type_, ak.types.ArrayType):
        return assert_valid(type_.content)
    elif isinstance(type_, ak.types.ScalarType):
        raise TypeError("Expected ArrayType or its content")

    assert not isinstance(
        type_,
…

Replies: 1 comment 2 replies

Comment options

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

@agoose77
Comment options

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