-
Notifications
You must be signed in to change notification settings - Fork 67
Type error when slicing vector<vector<float>> ObjectArray branch #519
Comments
This is a fundamental issue with Awkward 0's ObjectArray: the elements are Python objects. You're right that the above behavior is not intended, but no behavior is intended for In most cases like this, you encounter some error. Somehow, this example happened to slip through code it wasn't intended for and yield a result—a bizarre one—through sheer happenstance. Perhaps the right thing to do would have been to detect these multidimensional slices in ObjectArray and refuse it upfront: define the behavior to be an error. Awkward 1 is more aggressive about identifying and refusing undefined behavior (because half of it is written in C++, where undefined behavior would be more dangerous). This is the reason that Awkward 1 has no ObjectArray and Uproot 4 is more of a rewrite than an upgrade to take advantage of it. In Uproot 4, Your example works fine in Awkward 1/Uproot 4: >>> import uproot4
>>> t = uproot4.open("issue519.root")["testtree"]
>>> a = t["testbranch"].array()
>>> a
<Array [[[0.129, 0.33, ... 0.0869, 0.197]]] type='10 * var * var * float64'>
>>> a[:, 0]
<Array [[0.129, 0.33, ... 0.0869, 0.197]] type='10 * var * float64'>
>>> import awkward1 as ak
>>> ak.num(a) # most of these sublists have only one element
<Array [2, 2, 2, 2, 1, 1, 1, 1, 1, 1] type='10 * int64'>
>>> a[:, -1] # so hey, let's look at the last in each
<Array [[0.355], ... 0.458, 0.0869, 0.197]] type='10 * var * float64'> It's already the case that Awkward 1 is more mature than Awkward 0, and it's better documented. I've been recommending Awkward 1 since March with ak.from_awkward0/ak.to_awkward0 for brief forays into the new library/new interface, so that it can be minimally adopted without breaking existing scripts. Uproot 4 is lacking documentation and the file-writing feature, so I've been cautiously recommending it on a trial basis. I'm working on the documentation now, and when that's done, I'll be recommending Uproot 4 more forcefully. When the file-writing feature is also done, Uproot 4 will have feature parity with Uproot 3 and I'll actually move the GitHub and PyPI names:
so that On the point of ROOT deserialization, Uproot 4 is already more capable than Uproot 3, so unless you're interested in file-writing or don't want to change interface yet, you'll probably prefer Uproot 4. |
Hi,
I encountered some unexpected behaviour when trying to slice a branch of type
vector<vector<float>>
, containing vectors of variable length. Getting the array returns the correct result:... but slicing seems to convert the entries to uints:
Surely, this is not intentional.
cheers,
Alex
arraybug.zip
The text was updated successfully, but these errors were encountered: