Skip to content

ak.to_packed does not remove OptionType if there are no Nones #3939

Description

@lauridsj

Version of Awkward Array

2.9.0

Description and code to reproduce

ak.to_packed does not seem to remove OptionType from an array of records even if there are no more Nones in the array. This is a problem e.g. when writing to TTree with uproot, since TTree has no concept of option types.

Minimal reproducer:

# jagged array of records where a record is None
arr = ak.Array([[
    {"pt": 100., "eta": 0.5},
    {"pt": 200., "eta": 1.0},
    {"pt": 300., "eta": 1.5}
], [
    {"pt": 150., "eta": -0.5},
    {"pt": 250., "eta": -1.0},
    None
]])

# type is ListType(OptionType(...)) since there is a None
print("arr type:", repr(arr.type.content))

# Remove the event where there is a None
arr = arr[:1]
print("has nones:", ak.is_none(arr))

# type still has OptionType
print("arr type:", repr(arr.type.content))

# to_packed does not fix it
arr = ak.to_packed(arr)
print("arr type:", repr(arr.type.content))

# it is fixed when we explicitly drop nones from the array
arr = ak.drop_none(arr)
print("arr type:", repr(arr.type.content))

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug (unverified)The problem described would be a bug, but needs to be triaged

    Type

    No type

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions