Want to write TTree with an Awkward record array, rather than a dict of non-record arrays
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.
I'm running into this error as well (in ServiceX). I'd expect this to do the same thing as output_file['tree'] = {'a': ak.Array([[1.1, 2.2, 3.3], [], [4.4, 5.5]]), 'b': ak.Array([[1.1, 2.2, 3.3], [], [4.4, 5.5]]), 'c': ak.Array([1, 2, 3])} (which does work).
Noted: this is an important user-expectation. I think I've answered this question on Gitter, too.