-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Writing Awkward Arrays of type unknown #822
Comments
More generally, how can I specify a type for my array of zero length? b = ak.ArrayBuilder()
b.begin_list()
for _ in []:
b.begin_record()
b.field("x")
b.begin_list()
b.null()
b.end_list()
b.end_record()
raise RuntimeException("should not be reached")
b.end_list()
# b.snapshot()["x"] # ValueError: cannot slice EmptyArray by field name
b.snapshot().type
The same principle of building a "full" element and slicing it away applies, but would be nice to have a better way. The docs don't seem to mention anything about manual construction/specification of types. |
ArrayBuilder doesn't build pre-defined types. LayoutBuilder does, although that's in C++. I think there will someday be a LayoutBuilder implemented in Numba, with a pure-Python implementation for testing workflows in Numba. We've talked about having a general-purpose function for making any array conform to any specified type, but in the meantime, there are specialized functions for it, like ak.arrays_astype. >>> array = ak.Array([[]])
>>> array
<Array [[]] type='1 * var * unknown'>
>>> ak.values_astype(array, np.float32, including_unknown=True)
<Array [[]] type='1 * var * float32'> The above would turn all leaf-type nodes (unknown and numerical) to |
There's also a brief discussion of this in the user-guide, with a suggestion to append a dummy element of the correct type. |
Link to LayoutBuilder API docs: https://github.com/scikit-hep/awkward/blob/main/docs/user-guide/how-to-use-header-only-layoutbuilder.md |
So it does not cover the dynamic type case? |
This is an oversight in the implementation (both Uproot and Awkward). The policy is that
unknown
should becomefloat64
if it needs to be an array, becausemakes an array of
np.float64
. This issue is to say that Uproot should do that automatically, and there will be an issue on Awkward to say thatnp.values_astype(empty_array, np.float64)
should turn theEmptyArrays
intoNumpyArrays
with the specified type.Discussed in scikit-hep/awkward#2186
Originally posted by fleble February 1, 2023
Dear experts,
I am writing ROOT files using uproot. One problem I face is when a branch is empty, thus having unknown type, which cannot be written down with uproot.
This script
terminates with the following error:
And:
Is it possible to give a type to empty to empty awkward array?
Clever! But we'll fix it anyway.
The text was updated successfully, but these errors were encountered: