Skip to content

Want to write TTree with an Awkward record array, rather than a dict of non-record arrays #777

@laf070810

Description

@laf070810

I'm a newbie to uproot and encountered some problems when trying to use uproot. Sorry for possible misunderstandings of the usage, though I think my expectation might be reasonable.

Create a jagged array

import uproot
import awkward as ak
array = ak.Array({'a': [[1.1, 2.2, 3.3], [], [4.4, 5.5]], 'b': [[1.1, 2.2, 3.3], [], [4.4, 5.5]], 'c': [1, 2, 3]})

and save it to a ROOT file

with uproot.recreate('data.root') as output_file:
    output_file['tree'] = array

I expect that the saved tree has 3 branches

name | typename | interpretation
---------------------+--------------------------+-------------------------------
a | double[] | AsJagged(AsDtype('>f8'))
b | double[] | AsJagged(AsDtype('>f8'))
c | int64_t | AsDtype('>i8')

but actually I got errors

TypeError: fields of a record must be NumPy types, though the record itself may be in a jagged array

field 'a' has type var * float64

This situation easily happens when reading a TTree with variable length arrays and then saving it back after some manipulations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or request

    Type

    No type

    Projects

    Status

    Stretch goals

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions