diff --git a/src/uproot/_util.py b/src/uproot/_util.py index 3cca69ecb..d4652bdff 100644 --- a/src/uproot/_util.py +++ b/src/uproot/_util.py @@ -550,29 +550,29 @@ def awkward_form(model, file, context): if model not in _primitive_awkward_form: if model == numpy.dtype(numpy.bool_) or model == numpy.dtype(bool): - _primitive_awkward_form[model] = awkward.forms.Form.fromjson('"bool"') + _primitive_awkward_form[model] = awkward._v2.forms.from_json('"bool"') elif model == numpy.dtype(numpy.int8): - _primitive_awkward_form[model] = awkward.forms.Form.fromjson('"int8"') + _primitive_awkward_form[model] = awkward._v2.forms.from_json('"int8"') elif model == numpy.dtype(numpy.uint8): - _primitive_awkward_form[model] = awkward.forms.Form.fromjson('"uint8"') + _primitive_awkward_form[model] = awkward._v2.forms.from_json('"uint8"') elif model == numpy.dtype(numpy.int16): - _primitive_awkward_form[model] = awkward.forms.Form.fromjson('"int16"') + _primitive_awkward_form[model] = awkward._v2.forms.from_json('"int16"') elif model == numpy.dtype(numpy.uint16): - _primitive_awkward_form[model] = awkward.forms.Form.fromjson('"uint16"') + _primitive_awkward_form[model] = awkward._v2.forms.from_json('"uint16"') elif model == numpy.dtype(numpy.int32): - _primitive_awkward_form[model] = awkward.forms.Form.fromjson('"int32"') + _primitive_awkward_form[model] = awkward._v2.forms.from_json('"int32"') elif model == numpy.dtype(numpy.uint32): - _primitive_awkward_form[model] = awkward.forms.Form.fromjson('"uint32"') + _primitive_awkward_form[model] = awkward._v2.forms.from_json('"uint32"') elif model == numpy.dtype(numpy.int64): - _primitive_awkward_form[model] = awkward.forms.Form.fromjson('"int64"') + _primitive_awkward_form[model] = awkward._v2.forms.from_json('"int64"') elif model == numpy.dtype(numpy.uint64): - _primitive_awkward_form[model] = awkward.forms.Form.fromjson('"uint64"') + _primitive_awkward_form[model] = awkward._v2.forms.from_json('"uint64"') elif model == numpy.dtype(numpy.float32): - _primitive_awkward_form[model] = awkward.forms.Form.fromjson( + _primitive_awkward_form[model] = awkward._v2.forms.from_json( '"float32"' ) elif model == numpy.dtype(numpy.float64): - _primitive_awkward_form[model] = awkward.forms.Form.fromjson( + _primitive_awkward_form[model] = awkward._v2.forms.from_json( '"float64"' ) else: @@ -590,101 +590,95 @@ def awkward_form_remove_uproot(awkward, form): """ parameters = dict(form.parameters) parameters.pop("uproot", None) - if isinstance(form, awkward.forms.BitMaskedForm): - return awkward.forms.BitMaskedForm( + if isinstance(form, awkward._v2.forms.BitMaskedForm): + return awkward._v2.forms.BitMaskedForm( form.mask, awkward_form_remove_uproot(awkward, form.content), form.valid_when, form.lsb_order, - form.has_identities, + form.has_identifiers, parameters, ) - elif isinstance(form, awkward.forms.ByteMaskedForm): - return awkward.forms.ByteMaskedForm( + elif isinstance(form, awkward._v2.forms.ByteMaskedForm): + return awkward._v2.forms.ByteMaskedForm( form.mask, awkward_form_remove_uproot(awkward, form.content), form.valid_when, - form.has_identities, + form.has_identifiers, parameters, ) - elif isinstance(form, awkward.forms.EmptyForm): - return awkward.forms.EmptyForm( - form.has_identities, + elif isinstance(form, awkward._v2.forms.EmptyForm): + return awkward._v2.forms.EmptyForm( + form.has_identifiers, parameters, ) - elif isinstance(form, awkward.forms.IndexedForm): - return awkward.forms.IndexedForm( + elif isinstance(form, awkward._v2.forms.IndexedForm): + return awkward._v2.forms.IndexedForm( form.index, awkward_form_remove_uproot(awkward, form.content), - form.has_identities, + form.has_identifiers, parameters, ) - elif isinstance(form, awkward.forms.IndexedOptionForm): - return awkward.forms.IndexedOptionForm( + elif isinstance(form, awkward._v2.forms.IndexedOptionForm): + return awkward._v2.forms.IndexedOptionForm( form.index, awkward_form_remove_uproot(awkward, form.content), - form.has_identities, + form.has_identifiers, parameters, ) - elif isinstance(form, awkward.forms.ListForm): - return awkward.forms.ListForm( + elif isinstance(form, awkward._v2.forms.ListForm): + return awkward._v2.forms.ListForm( form.starts, form.stops, awkward_form_remove_uproot(awkward, form.content), - form.has_identities, + form.has_identifiers, parameters, ) - elif isinstance(form, awkward.forms.ListOffsetForm): - return awkward.forms.ListOffsetForm( + elif isinstance(form, awkward._v2.forms.ListOffsetForm): + return awkward._v2.forms.ListOffsetForm( form.offsets, awkward_form_remove_uproot(awkward, form.content), - form.has_identities, + form.has_identifiers, parameters, ) - elif isinstance(form, awkward.forms.NumpyForm): - return awkward.forms.NumpyForm( + elif isinstance(form, awkward._v2.forms.NumpyForm): + return awkward._v2.forms.NumpyForm( + form.primitive, form.inner_shape, - form.itemsize, - form.format, - form.has_identities, - parameters, + form.has_identifier, + form.parameters, ) - elif isinstance(form, awkward.forms.RecordForm): - return awkward.forms.RecordForm( - { - k: awkward_form_remove_uproot(awkward, v) - for k, v in form.contents.items() - if not k.startswith("@") - }, - form.has_identities, + elif isinstance(form, awkward._v2.forms.RecordForm): + contents = { + k: awkward_form_remove_uproot(awkward, v) + for k, v in form.contents.items() + if not k.startswith("@") + } + return awkward._v2.forms.RecordForm( + list(contents.values()), + list(contents.keys()), + form.has_identifiers, parameters, ) - elif isinstance(form, awkward.forms.RegularForm): - return awkward.forms.RegularForm( + elif isinstance(form, awkward._v2.forms.RegularForm): + return awkward._v2.forms.RegularForm( awkward_form_remove_uproot(awkward, form.content), form.size, - form.has_identities, + form.has_identifiers, parameters, ) - elif isinstance(form, awkward.forms.UnionForm): - return awkward.forms.UnionForm( + elif isinstance(form, awkward._v2.forms.UnionForm): + return awkward._v2.forms.UnionForm( form.tags, form.index, [awkward_form_remove_uproot(awkward, x) for x in form.contents], - form.has_identities, + form.has_identifiers, parameters, ) - elif isinstance(form, awkward.forms.UnmaskedForm): - return awkward.forms.UnmaskedForm( + elif isinstance(form, awkward._v2.forms.UnmaskedForm): + return awkward._v2.forms.UnmaskedForm( awkward_form_remove_uproot(awkward, form.content), - form.has_identities, - parameters, - ) - elif isinstance(form, awkward.forms.VirtualForm): - return awkward.forms.VirtualForm( - awkward_form_remove_uproot(awkward, form.form), - form.has_length, - form.has_identities, + form.has_identifiers, parameters, ) else: @@ -708,9 +702,10 @@ def recursively_fix_awkward_form_of_iter(awkward, interpretation, form): fixed[key] = recursively_fix_awkward_form_of_iter( awkward, subinterpretation, form.content(key) ) - return awkward.forms.RecordForm( - fixed, - form.has_identities, + return awkward._v2.forms.RecordForm( + list(fixed.values()), + list(fixed.keys()), + form.has_identifiers, form.parameters, ) elif isinstance(interpretation, uproot.interpretation.objects.AsObjects): @@ -728,107 +723,103 @@ def awkward_form_of_iter(awkward, form): (It might have been read with a different numeric type.) """ - if isinstance(form, awkward.forms.BitMaskedForm): - return awkward.forms.BitMaskedForm( + if isinstance(form, awkward._v2.forms.BitMaskedForm): + return awkward._v2.forms.BitMaskedForm( form.mask, awkward_form_of_iter(awkward, form.content), form.valid_when, form.lsb_order, - form.has_identities, + form.has_identifiers, form.parameters, ) - elif isinstance(form, awkward.forms.ByteMaskedForm): - return awkward.forms.ByteMaskedForm( + elif isinstance(form, awkward._v2.forms.ByteMaskedForm): + return awkward._v2.forms.ByteMaskedForm( form.mask, awkward_form_of_iter(awkward, form.content), form.valid_when, - form.has_identities, + form.has_identifiers, form.parameters, ) - elif isinstance(form, awkward.forms.EmptyForm): - return awkward.forms.EmptyForm( - form.has_identities, + elif isinstance(form, awkward._v2.forms.EmptyForm): + return awkward._v2.forms.EmptyForm( + form.has_identifiers, form.parameters, ) - elif isinstance(form, awkward.forms.IndexedForm): - return awkward.forms.IndexedForm( + elif isinstance(form, awkward._v2.forms.IndexedForm): + return awkward._v2.forms.IndexedForm( form.index, awkward_form_of_iter(awkward, form.content), - form.has_identities, + form.has_identifiers, form.parameters, ) - elif isinstance(form, awkward.forms.IndexedOptionForm): - return awkward.forms.IndexedOptionForm( + elif isinstance(form, awkward._v2.forms.IndexedOptionForm): + return awkward._v2.forms.IndexedOptionForm( form.index, awkward_form_of_iter(awkward, form.content), - form.has_identities, + form.has_identifiers, form.parameters, ) - elif isinstance(form, awkward.forms.ListForm): - return awkward.forms.ListForm( + elif isinstance(form, awkward._v2.forms.ListForm): + return awkward._v2.forms.ListForm( form.starts, form.stops, awkward_form_of_iter(awkward, form.content), - form.has_identities, + form.has_identifiers, form.parameters, ) - elif isinstance(form, awkward.forms.ListOffsetForm): - return awkward.forms.ListOffsetForm( + elif isinstance(form, awkward._v2.forms.ListOffsetForm): + return awkward._v2.forms.ListOffsetForm( form.offsets, awkward_form_of_iter(awkward, form.content), - form.has_identities, + form.has_identifiers, form.parameters, ) - elif isinstance(form, awkward.forms.NumpyForm): + elif isinstance(form, awkward._v2.forms.NumpyForm): if form.parameter("__array__") in ("char", "byte"): f = form else: - d = form.to_numpy() + d = awkward._v2.types.numpytype.primitive_to_dtype(form.primitive) if issubclass(d.type, numpy.integer): d = numpy.dtype(numpy.int64) elif issubclass(d.type, numpy.floating): d = numpy.dtype(numpy.float64) - f = awkward.forms.Form.from_numpy(d) - out = awkward.forms.NumpyForm( + f = awkward._v2.forms.numpyform.from_dtype(d) + out = awkward._v2.forms.NumpyForm( + f.primitive, form.inner_shape, - f.itemsize, - f.format, - form.has_identities, + form.has_identifier, form.parameters, ) return out - elif isinstance(form, awkward.forms.RecordForm): - return awkward.forms.RecordForm( - {k: awkward_form_of_iter(awkward, v) for k, v in form.contents.items()}, - form.has_identities, + elif isinstance(form, awkward._v2.forms.RecordForm): + contents = { + k: awkward_form_of_iter(awkward, v) for k, v in form.contents.items() + } + return awkward._v2.forms.RecordForm( + list(contents.values()), + list(contents.keys()), + form.has_identifiers, form.parameters, ) - elif isinstance(form, awkward.forms.RegularForm): - return awkward.forms.RegularForm( + elif isinstance(form, awkward._v2.forms.RegularForm): + return awkward._v2.forms.RegularForm( awkward_form_of_iter(awkward, form.content), form.size, - form.has_identities, + form.has_identifiers, form.parameters, ) - elif isinstance(form, awkward.forms.UnionForm): - return awkward.forms.UnionForm( + elif isinstance(form, awkward._v2.forms.UnionForm): + return awkward._v2.forms.UnionForm( form.tags, form.index, [awkward_form_of_iter(awkward, x) for x in form.contents], - form.has_identities, + form.has_identifiers, form.parameters, ) - elif isinstance(form, awkward.forms.UnmaskedForm): - return awkward.forms.UnmaskedForm( + elif isinstance(form, awkward._v2.forms.UnmaskedForm): + return awkward._v2.forms.UnmaskedForm( awkward_form_of_iter(awkward, form.content), - form.has_identities, - form.parameters, - ) - elif isinstance(form, awkward.forms.VirtualForm): - return awkward.forms.VirtualForm( - awkward_form_of_iter(awkward, form.form), - form.has_length, - form.has_identities, + form.has_identifiers, form.parameters, ) else: @@ -1079,3 +1070,15 @@ def regularize_object_path( if allow_missing and object_path not in file: return None return file[object_path] + + +def _content_cls_from_name(awkward, name): + if name.endswith("32") or name.endswith("64"): + name = name[-2:] + elif name.endswith("U32"): + name = name[-3:] + elif name.endswith("8_32") or name.endswith("8_64"): + name = name[-4:] + elif name.endswith("8_U32"): + name = name[-5:] + return getattr(awkward._v2.contents, name) diff --git a/src/uproot/containers.py b/src/uproot/containers.py index 6534e3722..42cca6cc5 100644 --- a/src/uproot/containers.py +++ b/src/uproot/containers.py @@ -287,7 +287,7 @@ def awkward_form(self, file, context): if self._model is None: raise uproot.interpretation.objects.CannotBeAwkward("dynamic type") else: - return awkward.forms.ListOffsetForm( + return awkward._v2.forms.ListOffsetForm( context["index_format"], uproot._util.awkward_form(self._model, file, context), parameters={"uproot": {"as": "array", "header": self._header}}, @@ -412,9 +412,9 @@ def typename(self): def awkward_form(self, file, context): awkward = uproot.extras.awkward() - return awkward.forms.ListOffsetForm( + return awkward._v2.forms.ListOffsetForm( context["index_format"], - awkward.forms.NumpyForm((), 1, "B", parameters={"__array__": "char"}), + awkward._v2.forms.NumpyForm("uint8", parameters={"__array__": "char"}), parameters={ "__array__": "string", "uproot": { @@ -452,14 +452,14 @@ def read(self, chunk, cursor, context, file, selffile, parent, header=True): out = cursor.string(chunk, context) if helper_obj.is_forth(): helper_obj.add_to_pre( - f"stream !B-> stack dup 255 = if drop stream !I-> stack then dup part0-node{offsets_num}-offsets +<- stack stream #!B-> part0-node{data_num}-data \n" + f"stream !B-> stack dup 255 = if drop stream !I-> stack then dup node{offsets_num}-offsets +<- stack stream #!B-> node{data_num}-data \n" ) elif self._length_bytes == "4": length = cursor.field(chunk, _stl_container_size, context) out = cursor.string_with_length(chunk, context, length) if helper_obj.is_forth(): helper_obj.add_to_pre( - f"stream I-> stack dup part0-node{offsets_num}-offsets <- stack stream #B-> part0-node{data_num}-data\n" + f"stream I-> stack dup node{offsets_num}-offsets <- stack stream #B-> node{data_num}-data\n" ) else: raise AssertionError(repr(self._length_bytes)) @@ -485,15 +485,15 @@ def read(self, chunk, cursor, context, file, selffile, parent, header=True): forth_obj.add_form(json.loads(temp_aform)) form_keys = [ - f"part0-node{data_num}-data", - f"part0-node{offsets_num}-offsets", + f"node{data_num}-data", + f"node{offsets_num}-offsets", ] for elem in form_keys: forth_obj.add_form_key(elem) helper_obj.add_to_header( - f"output part0-node{offsets_num}-offsets int64\noutput part0-node{data_num}-data uint8\n" + f"output node{offsets_num}-offsets int64\noutput node{data_num}-data uint8\n" ) - helper_obj.add_to_init(f"0 part0-node{offsets_num}-offsets <- stack\n") + helper_obj.add_to_init(f"0 node{offsets_num}-offsets <- stack\n") temp_form = forth_obj.add_node( f"node{offsets_num}", helper_obj.get_pre(), @@ -658,8 +658,8 @@ def awkward_form(self, file, context): awkward = uproot.extras.awkward() values_form = uproot._util.awkward_form(self._values, file, context) for dim in reversed(self.inner_shape): - values_form = awkward.forms.RegularForm(values_form, dim) - return awkward.forms.ListOffsetForm( + values_form = awkward._v2.forms.RegularForm(values_form, dim) + return awkward._v2.forms.ListOffsetForm( context["index_format"], values_form, parameters={ @@ -741,17 +741,15 @@ def read(self, chunk, cursor, context, file, selffile, parent, header=True): if helper_obj.is_forth(): helper_obj.add_to_header( - f"output part0-node{offsets_num}-offsets int64\n" - ) - form_key = f"part0-node{offsets_num}-offsets" - helper_obj.add_to_init( - f"0 part0-node{offsets_num}-offsets <- stack\n" + f"output node{offsets_num}-offsets int64\n" ) + form_key = f"node{offsets_num}-offsets" + helper_obj.add_to_init(f"0 node{offsets_num}-offsets <- stack\n") helper_obj.add_to_pre( "0 bytestops I-> stack \nbegin\ndup stream pos <>\nwhile\nswap 1 + swap\n" ) helper_obj.add_to_post( - f"repeat\nswap part0-node{offsets_num}-offsets +<- stack drop\n" + f"repeat\nswap node{offsets_num}-offsets +<- stack drop\n" ) if forth_obj.should_add_form(): forth_obj.add_form_key(form_key) @@ -836,7 +834,7 @@ def typename(self): def awkward_form(self, file, context): awkward = uproot.extras.awkward() - return awkward.forms.ListOffsetForm( + return awkward._v2.forms.ListOffsetForm( context["index_format"], uproot._util.awkward_form(self._values, file, context), parameters={"uproot": {"as": "RVec", "header": self._header}}, @@ -984,7 +982,7 @@ def typename(self): def awkward_form(self, file, context): awkward = uproot.extras.awkward() - return awkward.forms.ListOffsetForm( + return awkward._v2.forms.ListOffsetForm( context["index_format"], uproot._util.awkward_form(self._values, file, context), parameters={"uproot": {"as": "vector", "header": self._header}}, @@ -1072,11 +1070,11 @@ def read(self, chunk, cursor, context, file, selffile, parent, header=True): if helper_obj.is_forth(): key = forth_obj.get_keys(1) - form_key = f"part0-node{key}-offsets" - helper_obj.add_to_header(f"output part0-node{key}-offsets int64\n") - helper_obj.add_to_init(f"0 part0-node{key}-offsets <- stack\n") + form_key = f"node{key}-offsets" + helper_obj.add_to_header(f"output node{key}-offsets int64\n") + helper_obj.add_to_init(f"0 node{key}-offsets <- stack\n") helper_obj.add_to_pre( - f"stream !I-> stack\ndup part0-node{key}-offsets +<- stack\n0 do \n" + f"stream !I-> stack\ndup node{key}-offsets +<- stack\n0 do \n" ) helper_obj.add_to_post("loop\n") if forth_obj.should_add_form(): @@ -1190,7 +1188,7 @@ def typename(self): def awkward_form(self, file, context): awkward = uproot.extras.awkward() - return awkward.forms.ListOffsetForm( + return awkward._v2.forms.ListOffsetForm( context["index_format"], uproot._util.awkward_form(self._keys, file, context), parameters={ @@ -1341,13 +1339,14 @@ def typename(self): def awkward_form(self, file, context): awkward = uproot.extras.awkward() - return awkward.forms.ListOffsetForm( + return awkward._v2.forms.ListOffsetForm( context["index_format"], - awkward.forms.RecordForm( + awkward._v2.forms.RecordForm( ( uproot._util.awkward_form(self._keys, file, context), uproot._util.awkward_form(self._values, file, context), - ) + ), + None, ), parameters={ "__array__": "sorted_map", diff --git a/src/uproot/interpretation/grouped.py b/src/uproot/interpretation/grouped.py index 5b8ac4b35..32cc016f9 100644 --- a/src/uproot/interpretation/grouped.py +++ b/src/uproot/interpretation/grouped.py @@ -103,7 +103,7 @@ def awkward_form( if y is not None: names.append(x) fields.append(y.awkward_form(file, context)) - return awkward.forms.RecordForm(fields, names) + return awkward._v2.forms.RecordForm(fields, names) def basket_array( self, data, byte_offsets, basket, branch, context, cursor_offset, library diff --git a/src/uproot/interpretation/jagged.py b/src/uproot/interpretation/jagged.py index 80260a56d..afc01d896 100644 --- a/src/uproot/interpretation/jagged.py +++ b/src/uproot/interpretation/jagged.py @@ -117,7 +117,7 @@ def awkward_form( context, index_format, header, tobject_header, breadcrumbs ) awkward = uproot.extras.awkward() - return awkward.forms.ListOffsetForm( + return awkward._v2.forms.ListOffsetForm( context["index_format"], uproot._util.awkward_form(self._content, file, context), parameters={"uproot": {"as": "jagged", "header_bytes": self._header_bytes}}, diff --git a/src/uproot/interpretation/library.py b/src/uproot/interpretation/library.py index 1cd49a9d5..dc208b97a 100644 --- a/src/uproot/interpretation/library.py +++ b/src/uproot/interpretation/library.py @@ -271,7 +271,7 @@ def _strided_to_awkward(awkward, path, interpretation, data): contents.append(_strided_to_awkward(awkward, p, member, data)) else: contents.append( - awkward.from_numpy( + awkward._v2.from_numpy( numpy.array(data[p]), regulararray=True, highlevel=False ) ) @@ -280,9 +280,11 @@ def _strided_to_awkward(awkward, path, interpretation, data): "__record__": uproot.model.classname_decode(interpretation.model.__name__)[0] } length = len(data) if len(contents) == 0 else None - out = awkward.layout.RecordArray(contents, names, length, parameters=parameters) + out = awkward._v2.contents.RecordArray( + contents, names, length, parameters=parameters + ) for dim in reversed(interpretation.inner_shape): - out = awkward.layout.RegularArray(out, dim) + out = awkward._v2.contents.RegularArray(out, dim) return out @@ -338,26 +340,26 @@ def _awkward_p(form): def _awkward_offsets(awkward, form, array): - if isinstance(array, awkward.layout.EmptyArray): + if isinstance(array, awkward._v2.contents.EmptyArray): if form["offsets"] == "i32": - return awkward.layout.Index32(numpy.zeros(1, dtype=numpy.int32)) + return awkward._v2.index.Index32(numpy.zeros(1, dtype=numpy.int32)) elif form["offsets"] == "u32": - return awkward.layout.IndexU32(numpy.zeros(1, dtype=numpy.uint32)) + return awkward._v2.index.IndexU32(numpy.zeros(1, dtype=numpy.uint32)) elif form["offsets"] == "i64": - return awkward.layout.Index64(numpy.zeros(1, dtype=numpy.int64)) + return awkward._v2.index.Index64(numpy.zeros(1, dtype=numpy.int64)) else: raise AssertionError(form["offsets"]) else: if form["offsets"] == "i32": - return awkward.layout.Index32( + return awkward._v2.index.Index32( numpy.asarray(array.offsets, dtype=numpy.int32) ) elif form["offsets"] == "u32": - return awkward.layout.IndexU32( + return awkward._v2.index.IndexU32( numpy.asarray(array.offsets, dtype=numpy.uint32) ) elif form["offsets"] == "i64": - return awkward.layout.Index64( + return awkward._v2.index.Index64( numpy.asarray(array.offsets, dtype=numpy.int64) ) else: @@ -366,9 +368,10 @@ def _awkward_offsets(awkward, form, array): def _awkward_json_to_array(awkward, form, array): if form["class"] == "NumpyArray": - if isinstance(array, awkward.layout.EmptyArray): - dtype = awkward.forms.Form.fromjson(json.dumps(form)).to_numpy() - return awkward.layout.NumpyArray(numpy.empty(0, dtype=dtype)) + if isinstance(array, awkward._v2.contents.EmptyArray): + form = awkward._v2.forms.from_json(json.dumps(form)) + dtype = awkward._v2.types.numpytype.primitive_to_dtype(form.primitive) + return awkward._v2.contents.NumpyArray(numpy.empty(0, dtype=dtype)) else: return array @@ -377,7 +380,7 @@ def _awkward_json_to_array(awkward, form, array): names = [] for name, subform in form["contents"].items(): if not name.startswith("@"): - if isinstance(array, awkward.layout.EmptyArray): + if isinstance(array, awkward._v2.contents.EmptyArray): contents.append(_awkward_json_to_array(awkward, subform, array)) else: contents.append( @@ -385,19 +388,19 @@ def _awkward_json_to_array(awkward, form, array): ) names.append(name) length = len(array) if len(contents) == 0 else None - return awkward.layout.RecordArray( + return awkward._v2.contents.RecordArray( contents, names, length, parameters=_awkward_p(form) ) elif form["class"][:15] == "ListOffsetArray": if form["parameters"].get("__array__") == "string": - if isinstance(array, awkward.layout.EmptyArray): - content = awkward.layout.NumpyArray( + if isinstance(array, awkward._v2.contents.EmptyArray): + content = awkward._v2.contents.NumpyArray( numpy.empty(0, dtype=numpy.uint8), parameters=_awkward_p(form["content"]), ) - return awkward.layout.ListOffsetArray64( - awkward.layout.Index64(numpy.array([0], dtype=numpy.uint8)), + return awkward._v2.contents.ListOffsetArray( + awkward._v2.index.Index64(numpy.array([0], dtype=numpy.uint8)), content, parameters=_awkward_p(form), ) @@ -411,10 +414,10 @@ def _awkward_json_to_array(awkward, form, array): offsets = _awkward_offsets(awkward, form, array) key_form = form["content"]["contents"][0] value_form = form["content"]["contents"][1] - if isinstance(array, awkward.layout.EmptyArray): + if isinstance(array, awkward._v2.contents.EmptyArray): keys = _awkward_json_to_array(awkward, key_form, array) values = _awkward_json_to_array(awkward, value_form, array) - content = awkward.layout.RecordArray( + content = awkward._v2.contents.RecordArray( (keys, values), None, 0, @@ -424,32 +427,32 @@ def _awkward_json_to_array(awkward, form, array): keys = _awkward_json_to_array(awkward, key_form, array.content["0"]) values = _awkward_json_to_array(awkward, value_form, array.content["1"]) length = len(array.content) if len(keys) == 0 else None - content = awkward.layout.RecordArray( + content = awkward._v2.contents.RecordArray( (keys, values), None, length, parameters=_awkward_p(form["content"]), ) - cls = getattr(awkward.layout, form["class"]) + cls = uproot._util._content_cls_from_name(awkward, form["class"]) return cls(offsets, content, parameters=_awkward_p(form)) else: offsets = _awkward_offsets(awkward, form, array) - if isinstance(array, awkward.layout.EmptyArray): + if isinstance(array, awkward._v2.contents.EmptyArray): content = _awkward_json_to_array(awkward, form["content"], array) else: content = _awkward_json_to_array( awkward, form["content"], array.content ) - cls = getattr(awkward.layout, form["class"]) + cls = uproot._util._content_cls_from_name(awkward, form["class"]) return cls(offsets, content, parameters=_awkward_p(form)) elif form["class"] == "RegularArray": - if isinstance(array, awkward.layout.EmptyArray): + if isinstance(array, awkward._v2.contents.EmptyArray): content = _awkward_json_to_array(awkward, form["content"], array) else: content = _awkward_json_to_array(awkward, form["content"], array.content) - return awkward.layout.RegularArray( + return awkward._v2.contents.RegularArray( content, form["size"], parameters=_awkward_p(form) ) @@ -493,11 +496,11 @@ def imported(self): def finalize(self, array, branch, interpretation, entry_start, entry_stop): awkward = self.imported - if isinstance(array, awkward.layout.Content): - return awkward.Array(array) + if isinstance(array, awkward._v2.contents.Content): + return awkward._v2.Array(array) elif isinstance(array, uproot.interpretation.objects.StridedObjectArray): - return awkward.Array( + return awkward._v2.Array( _strided_to_awkward(awkward, "", array.interpretation, array.array) ) @@ -508,55 +511,53 @@ def finalize(self, array, branch, interpretation, entry_start, entry_stop): awkward, "", array.content.interpretation, array.content.array ) if issubclass(array.offsets.dtype.type, numpy.int32): - offsets = awkward.layout.Index32(array.offsets) - layout = awkward.layout.ListOffsetArray32(offsets, content) + offsets = awkward._v2.index.Index32(array.offsets) + layout = awkward._v2.contents.ListOffsetArray32(offsets, content) else: - offsets = awkward.layout.Index64(array.offsets) - layout = awkward.layout.ListOffsetArray64(offsets, content) - return awkward.Array(layout) + offsets = awkward._v2.index.Index64(array.offsets) + layout = awkward._v2.contents.ListOffsetArray(offsets, content) + return awkward._v2.Array(layout) elif isinstance(array, uproot.interpretation.jagged.JaggedArray): - content = awkward.from_numpy( + content = awkward._v2.from_numpy( array.content, regulararray=True, highlevel=False ) if issubclass(array.offsets.dtype.type, numpy.int32): - offsets = awkward.layout.Index32(array.offsets) - layout = awkward.layout.ListOffsetArray32(offsets, content) + offsets = awkward._v2.index.Index32(array.offsets) + layout = awkward._v2.contents.ListOffsetArray32(offsets, content) else: - offsets = awkward.layout.Index64(array.offsets) - layout = awkward.layout.ListOffsetArray64(offsets, content) - return awkward.Array(layout) + offsets = awkward._v2.index.Index64(array.offsets) + layout = awkward._v2.contents.ListOffsetArray(offsets, content) + return awkward._v2.Array(layout) elif isinstance(array, uproot.interpretation.strings.StringArray): - content = awkward.layout.NumpyArray( + content = awkward._v2.contents.NumpyArray( numpy.frombuffer(array.content, dtype=numpy.dtype(numpy.uint8)), parameters={"__array__": "char"}, ) if issubclass(array.offsets.dtype.type, numpy.int32): - offsets = awkward.layout.Index32(array.offsets) - layout = awkward.layout.ListOffsetArray32( + offsets = awkward._v2.index.Index32(array.offsets) + layout = awkward._v2.contents.ListOffsetArray32( offsets, content, parameters={"__array__": "string"} ) elif issubclass(array.offsets.dtype.type, numpy.uint32): - offsets = awkward.layout.IndexU32(array.offsets) - layout = awkward.layout.ListOffsetArrayU32( + offsets = awkward._v2.index.IndexU32(array.offsets) + layout = awkward._v2.contents.ListOffsetArrayU32( offsets, content, parameters={"__array__": "string"} ) elif issubclass(array.offsets.dtype.type, numpy.int64): - offsets = awkward.layout.Index64(array.offsets) - layout = awkward.layout.ListOffsetArray64( + offsets = awkward._v2.index.Index64(array.offsets) + layout = awkward._v2.contents.ListOffsetArray( offsets, content, parameters={"__array__": "string"} ) else: raise AssertionError(repr(array.offsets.dtype)) - return awkward.Array(layout) + return awkward._v2.Array(layout) elif isinstance(interpretation, uproot.interpretation.objects.AsObjects): try: form = json.loads( - interpretation.awkward_form(interpretation.branch.file).tojson( - verbose=True - ) + interpretation.awkward_form(interpretation.branch.file).to_json() ) except uproot.interpretation.objects.CannotBeAwkward as err: raise ValueError( @@ -575,10 +576,10 @@ def finalize(self, array, branch, interpretation, entry_start, entry_stop): ) ) - unlabeled = awkward.from_iter( + unlabeled = awkward._v2.from_iter( (_object_to_awkward_json(form, x) for x in array), highlevel=False ) - return awkward.Array(_awkward_json_to_array(awkward, form, unlabeled)) + return awkward._v2.Array(_awkward_json_to_array(awkward, form, unlabeled)) elif array.dtype.names is not None: length, shape = array.shape[0], array.shape[1:] @@ -586,19 +587,19 @@ def finalize(self, array, branch, interpretation, entry_start, entry_stop): contents = [] for name in array.dtype.names: contents.append( - awkward.from_numpy( + awkward._v2.from_numpy( numpy.array(array[name]), regulararray=True, highlevel=False ) ) if len(contents) != 0: length = None - out = awkward.layout.RecordArray(contents, array.dtype.names, length) + out = awkward._v2.contents.RecordArray(contents, array.dtype.names, length) for size in shape[::-1]: - out = awkward.layout.RegularArray(out, size) - return awkward.Array(out) + out = awkward._v2.contents.RegularArray(out, size) + return awkward._v2.Array(out) else: - return awkward.from_numpy(array, regulararray=True) + return awkward._v2.from_numpy(array, regulararray=True) def group(self, arrays, expression_context, how): awkward = self.imported @@ -611,9 +612,11 @@ def group(self, arrays, expression_context, how): return {_rename(name, c): arrays[name] for name, c in expression_context} elif how is None: if len(expression_context) == 0: - return awkward.Array(awkward.layout.RecordArray([], keys=[])) + return awkward._v2.Array( + awkward._v2.contents.RecordArray([], fields=[], length=0) + ) else: - return awkward.Array( + return awkward._v2.Array( {_rename(name, c): arrays[name] for name, c in expression_context} ) elif how == "zip": @@ -625,14 +628,7 @@ def group(self, arrays, expression_context, how): array = renamed_arrays[_rename(name, context)] = arrays[name] if context["is_jagged"]: if ( - isinstance( - array.layout, - ( - awkward.layout.ListArray32, - awkward.layout.ListArrayU32, - awkward.layout.ListArray64, - ), - ) + isinstance(array.layout, awkward._v2.contents.ListArray) or array.layout.offsets[0] != 0 ): array_layout = array.layout.toListOffsetArray64(True) @@ -655,9 +651,11 @@ def group(self, arrays, expression_context, how): out = None if len(nonjagged) != 0: if len(nonjagged) == 0: - out = awkward.Array(awkward.layout.RecordArray([], keys=[])) + out = awkward._v2.Array( + awkward._v2.contents.RecordArray([], fields=[], length=0) + ) else: - out = awkward.Array( + out = awkward._v2.Array( {name: renamed_arrays[name] for name in nonjagged}, ) for number, jagged in enumerate(jaggeds): @@ -674,36 +672,36 @@ def group(self, arrays, expression_context, how): if ( out is not None and cut != 0 - and jagged[0][:cut].strip("_./") in awkward.fields(out) + and jagged[0][:cut].strip("_./") in awkward._v2.fields(out) ): cut = 0 if cut == 0: common = f"jagged{number}" if len(jagged) == 0: - subarray = awkward.Array( - awkward.layout.RecordArray([], keys=[]) + subarray = awkward._v2.Array( + awkward._v2.contents.RecordArray([], fields=[], length=0) ) else: - subarray = awkward.zip( + subarray = awkward._v2.zip( {name: renamed_arrays[name] for name in jagged} ) else: common = jagged[0][:cut].strip("_./") if len(jagged) == 0: - subarray = awkward.Array( - awkward.layout.RecordArray([], keys=[]) + subarray = awkward._v2.Array( + awkward._v2.contents.RecordArray([], fields=[], length=0) ) else: - subarray = awkward.zip( + subarray = awkward._v2.zip( { name[cut:].strip("_./"): renamed_arrays[name] for name in jagged } ) if out is None: - out = awkward.Array({common: subarray}) + out = awkward._v2.Array({common: subarray}) else: - out = awkward.with_field(out, subarray, common) + out = awkward._v2.with_field(out, subarray, common) return out else: @@ -724,14 +722,14 @@ def concatenate(self, all_arrays): elif isinstance(all_arrays[0], dict): keys = list(all_arrays[0]) else: - return awkward.concatenate(all_arrays) + return awkward._v2.concatenate(all_arrays) to_concatenate = {k: [] for k in keys} for arrays in all_arrays: for k in keys: to_concatenate[k].append(arrays[k]) - concatenated = {k: awkward.concatenate(to_concatenate[k]) for k in keys} + concatenated = {k: awkward._v2.concatenate(to_concatenate[k]) for k in keys} if isinstance(all_arrays[0], tuple): return tuple(concatenated[k] for k in keys) diff --git a/src/uproot/interpretation/numerical.py b/src/uproot/interpretation/numerical.py index efc7423e7..14d8f0dd6 100644 --- a/src/uproot/interpretation/numerical.py +++ b/src/uproot/interpretation/numerical.py @@ -265,7 +265,7 @@ def awkward_form( d, s = _dtype_shape(self._to_dtype) out = uproot._util.awkward_form(d, file, context) for size in s[::-1]: - out = awkward.forms.RegularForm(out, size) + out = awkward._v2.forms.RegularForm(out, size) return out @property @@ -648,10 +648,8 @@ def awkward_form( context, index_format, header, tobject_header, breadcrumbs ) awkward = uproot.extras.awkward() - out = awkward.forms.NumpyForm( - (), - 8, - "d", + out = awkward._v2.forms.NumpyForm( + "float64", parameters={ "uproot": { "as": "Double32", @@ -662,7 +660,7 @@ def awkward_form( }, ) for size in self._to_dims[::-1]: - out = awkward.forms.RegularForm(out, size) + out = awkward._v2.forms.RegularForm(out, size) return out @@ -718,10 +716,8 @@ def awkward_form( context, index_format, header, tobject_header, breadcrumbs ) awkward = uproot.extras.awkward() - out = awkward.forms.NumpyForm( - (), - 4, - "f", + out = awkward._v2.forms.NumpyForm( + "float32", parameters={ "uproot": { "as": "Float16", @@ -732,5 +728,5 @@ def awkward_form( }, ) for size in self._to_dims[::-1]: - out = awkward.forms.RegularForm(out, size) + out = awkward._v2.forms.RegularForm(out, size) return out diff --git a/src/uproot/interpretation/objects.py b/src/uproot/interpretation/objects.py index eaeea8815..efe4d090b 100644 --- a/src/uproot/interpretation/objects.py +++ b/src/uproot/interpretation/objects.py @@ -27,23 +27,6 @@ import uproot._awkward_forth -def awkward_can_optimize(interpretation, form): - """ - If True, the Awkward Array library can convert data of a given - :doc:`uproot.interpretation.Interpretation` and ``ak.forms.Form`` into - arrays without resorting to ``ak.from_iter`` (i.e. rapidly). - - If ``awkward._connect._uproot`` cannot be imported, this function always - returns False. - """ - try: - import awkward._connect._uproot - except ModuleNotFoundError: - return False - else: - return awkward._connect._uproot.can_optimize(interpretation, form) - - class AsObjects(uproot.interpretation.Interpretation): """ Args: @@ -147,29 +130,9 @@ def basket_array( data, byte_offsets, basket, branch, context, cursor_offset, library ) else: - - output = None - if isinstance(library, uproot.interpretation.library.Awkward): - form = self.awkward_form(branch.file) - - if awkward_can_optimize(self, form): - import awkward._connect._uproot - - extra = { - "interpretation": self, - "basket": basket, - "branch": branch, - "context": context, - "cursor_offset": cursor_offset, - } - output = awkward._connect._uproot.basket_array( - form, data, byte_offsets, extra - ) - - if output is None: - output = ObjectArray( - self._model, branch, context, byte_offsets, data, cursor_offset - ).to_numpy() + output = ObjectArray( + self._model, branch, context, byte_offsets, data, cursor_offset + ).to_numpy() self.hook_after_basket_array( data=data, @@ -216,19 +179,6 @@ def basket_array_forth( "breadcrumbs": (), }, ) - if awkward_can_optimize(self, self._form): - import awkward._connect._uproot - - extra = { - "interpretation": self, - "basket": basket, - "branch": branch, - "context": context, - "cursor_offset": cursor_offset, - } - output = awkward._connect._uproot.basket_array( - self._form, data, byte_offsets, extra - ) if not self._forth_vm_set: if not self._prereaddone: @@ -292,7 +242,9 @@ def basket_array_forth( container[elem] = self._forth_vm.vm.output_Index64(elem) else: container[elem] = self._forth_vm.vm.output_NumpyArray(elem) - output = awkward.from_buffers(self._form, len(byte_offsets) - 1, container) + output = awkward._v2.from_buffers( + self._form, len(byte_offsets) - 1, container + ) self.hook_after_basket_array( data=data, byte_offsets=byte_offsets, @@ -362,7 +314,7 @@ def final_array( ): assert isinstance(library, uproot.interpretation.library.Awkward) awkward = library.imported - output = awkward.concatenate(trimmed, mergebool=False, highlevel=False) + output = awkward._v2.concatenate(trimmed, mergebool=False, highlevel=False) else: output = numpy.concatenate(trimmed) @@ -500,7 +452,11 @@ def _strided_awkward_form(awkward, classname, members, file, context): ) else: contents[name] = uproot._util.awkward_form(member, file, context) - return awkward.forms.RecordForm(contents, parameters={"__record__": classname}) + return awkward._v2.forms.RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": classname}, + ) class AsStridedObjects(uproot.interpretation.numerical.AsDtype): @@ -598,7 +554,7 @@ def awkward_form( cname = uproot.model.classname_decode(self._model.__name__)[0] form = _strided_awkward_form(awkward, cname, self._members, file, context) for dim in reversed(self.inner_shape): - form = awkward.forms.RegularForm(form, dim) + form = awkward._v2.forms.RegularForm(form, dim) return form @property diff --git a/src/uproot/interpretation/strings.py b/src/uproot/interpretation/strings.py index dd64d38aa..cd509abc1 100644 --- a/src/uproot/interpretation/strings.py +++ b/src/uproot/interpretation/strings.py @@ -163,9 +163,9 @@ def awkward_form( context, index_format, header, tobject_header, breadcrumbs ) awkward = uproot.extras.awkward() - return awkward.forms.ListOffsetForm( + return awkward._v2.forms.ListOffsetForm( context["index_format"], - awkward.forms.NumpyForm((), 1, "B", parameters={"__array__": "char"}), + awkward._v2.forms.NumpyForm("uint8", parameters={"__array__": "char"}), parameters={ "__array__": "string", "uproot": { @@ -217,10 +217,10 @@ def basket_array( ) self._threadlocal.forth_vm.reset() - return awkward.Array( - awkward.layout.ListOffsetArray64( - awkward.layout.Index64(offsets), - awkward.layout.NumpyArray( + return awkward._v2.Array( + awkward._v2.contents.ListOffsetArray( + awkward._v2.index.Index64(offsets), + awkward._v2.contents.NumpyArray( data, parameters={"__array__": "char"} ), parameters={"__array__": "string"}, @@ -342,7 +342,9 @@ def final_array( ): assert isinstance(library, uproot.interpretation.library.Awkward) awkward = library.imported - output = awkward.concatenate(trimmed, mergebool=False, highlevel=False) + output = awkward._v2.concatenate( + trimmed, mergebool=False, highlevel=False + ) self.hook_before_library_finalize( basket_arrays=basket_arrays, diff --git a/src/uproot/models/TArray.py b/src/uproot/models/TArray.py index 32ebdd3fd..c9c9a26f1 100644 --- a/src/uproot/models/TArray.py +++ b/src/uproot/models/TArray.py @@ -76,7 +76,7 @@ def tojson(self): @classmethod def awkward_form(cls, file, context): awkward = uproot.extras.awkward() - return awkward.forms.ListOffsetForm( + return awkward._v2.forms.ListOffsetForm( context["index_format"], uproot._util.awkward_form(cls.dtype, file, context), parameters={"uproot": {"as": "TArray"}}, diff --git a/src/uproot/models/TAtt.py b/src/uproot/models/TAtt.py index d0443bee6..b5fd600d0 100644 --- a/src/uproot/models/TAtt.py +++ b/src/uproot/models/TAtt.py @@ -68,7 +68,11 @@ def awkward_form(cls, file, context): contents["fLineWidth"] = uproot._util.awkward_form( numpy.dtype("i2"), file, context ) - return awkward.forms.RecordForm(contents, parameters={"__record__": "TAttLine"}) + return awkward._v2.forms.RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TAttLine"}, + ) base_names_versions = [] member_names = ["fLineColor", "fLineStyle", "fLineWidth"] @@ -130,7 +134,11 @@ def awkward_form(cls, file, context): contents["fLineWidth"] = uproot._util.awkward_form( numpy.dtype("i2"), file, context ) - return awkward.forms.RecordForm(contents, parameters={"__record__": "TAttLine"}) + return awkward._v2.forms.RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TAttLine"}, + ) writable = True @@ -216,7 +224,11 @@ def awkward_form(cls, file, context): contents["fFillStyle"] = uproot._util.awkward_form( numpy.dtype("i2"), file, context ) - return awkward.forms.RecordForm(contents, parameters={"__record__": "TAttFill"}) + return awkward._v2.forms.RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TAttFill"}, + ) base_names_versions = [] member_names = ["fFillColor", "fFillStyle"] @@ -272,7 +284,11 @@ def awkward_form(cls, file, context): contents["fFillStyle"] = uproot._util.awkward_form( numpy.dtype("i2"), file, context ) - return awkward.forms.RecordForm(contents, parameters={"__record__": "TAttFill"}) + return awkward._v2.forms.RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TAttFill"}, + ) writable = True @@ -362,8 +378,10 @@ def awkward_form(cls, file, context): contents["fMarkerSize"] = uproot._util.awkward_form( numpy.dtype("f4"), file, context ) - return awkward.forms.RecordForm( - contents, parameters={"__record__": "TAttMarker"} + return awkward._v2.forms.RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TAttMarker"}, ) writable = True @@ -501,7 +519,7 @@ def strided_interpretation( @classmethod def awkward_form(cls, file, context): - from awkward.forms import RecordForm + from awkward._v2.forms import RecordForm if cls in context["breadcrumbs"]: raise uproot.interpretation.objects.CannotBeAwkward( @@ -549,7 +567,11 @@ def awkward_form(cls, file, context): contents["fTitleFont"] = uproot._util.awkward_form( numpy.dtype(">i2"), file, context ) - return RecordForm(contents, parameters={"__record__": "TAttAxis"}) + return RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TAttAxis"}, + ) _format0 = struct.Struct(">ihhhfffffhh") _format_memberwise0 = struct.Struct(">i") @@ -650,7 +672,7 @@ def strided_interpretation( @classmethod def awkward_form(cls, file, context): - from awkward.forms import RecordForm + from awkward._v2.forms import RecordForm if cls in context["breadcrumbs"]: raise uproot.interpretation.objects.CannotBeAwkward( @@ -667,7 +689,11 @@ def awkward_form(cls, file, context): contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, context ) - return RecordForm(contents, parameters={"__record__": "TAtt3D"}) + return RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TAtt3D"}, + ) base_names_versions = [] member_names = [] diff --git a/src/uproot/models/TDatime.py b/src/uproot/models/TDatime.py index 32ad47ef6..a9d4daafb 100644 --- a/src/uproot/models/TDatime.py +++ b/src/uproot/models/TDatime.py @@ -53,7 +53,11 @@ def awkward_form(cls, file, context): contents["fDatime"] = uproot._util.awkward_form( numpy.dtype(">u4"), file, context ) - return awkward.forms.RecordForm(contents, parameters={"__record__": "TDatime"}) + return awkward._v2.forms.RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TDatime"}, + ) base_names_versions = [] member_names = ["fDatime"] diff --git a/src/uproot/models/TGraph.py b/src/uproot/models/TGraph.py index 7f02e8c60..56f183656 100644 --- a/src/uproot/models/TGraph.py +++ b/src/uproot/models/TGraph.py @@ -242,7 +242,7 @@ def strided_interpretation( @classmethod def awkward_form(cls, file, context): - from awkward.forms import ListOffsetForm, RecordForm + from awkward._v2.forms import ListOffsetForm, RecordForm if cls in context["breadcrumbs"]: raise uproot.interpretation.objects.CannotBeAwkward( @@ -257,18 +257,14 @@ def awkward_form(cls, file, context): contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, context ) - contents.update( - file.class_named("TNamed", 1).awkward_form(file, context).contents - ) - contents.update( - file.class_named("TAttLine", 2).awkward_form(file, context).contents - ) - contents.update( - file.class_named("TAttFill", 2).awkward_form(file, context).contents - ) - contents.update( - file.class_named("TAttMarker", 2).awkward_form(file, context).contents - ) + tmp_awkward_form = file.class_named("TNamed", 1).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + tmp_awkward_form = file.class_named("TAttLine", 2).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + tmp_awkward_form = file.class_named("TAttFill", 2).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + tmp_awkward_form = file.class_named("TAttMarker", 2).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) contents["fNpoints"] = uproot._util.awkward_form( numpy.dtype(">u4"), file, context ) @@ -292,7 +288,11 @@ def awkward_form(cls, file, context): contents["fMaximum"] = uproot._util.awkward_form( numpy.dtype(">f8"), file, context ) - return RecordForm(contents, parameters={"__record__": "TGraph"}) + return RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TGraph"}, + ) _format0 = struct.Struct(">I") _format1 = struct.Struct(">dd") @@ -454,7 +454,7 @@ def strided_interpretation( @classmethod def awkward_form(cls, file, context): - from awkward.forms import ListOffsetForm, RecordForm + from awkward._v2.forms import ListOffsetForm, RecordForm if cls in context["breadcrumbs"]: raise uproot.interpretation.objects.CannotBeAwkward( @@ -469,9 +469,8 @@ def awkward_form(cls, file, context): contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, context ) - contents.update( - file.class_named("TGraph", 4).awkward_form(file, context).contents - ) + tmp_awkward_form = file.class_named("TGraph", 4).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) contents["fEX"] = ListOffsetForm( context["index_format"], uproot._util.awkward_form(cls._dtype0, file, context), @@ -486,7 +485,11 @@ def awkward_form(cls, file, context): "uproot": {"as": "TStreamerBasicPointer", "count_name": "fNpoints"} }, ) - return RecordForm(contents, parameters={"__record__": "TGraphErrors"}) + return RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TGraphErrors"}, + ) _dtype0 = numpy.dtype(">f8") _dtype1 = numpy.dtype(">f8") @@ -668,7 +671,7 @@ def strided_interpretation( @classmethod def awkward_form(cls, file, context): - from awkward.forms import ListOffsetForm, RecordForm + from awkward._v2.forms import ListOffsetForm, RecordForm if cls in context["breadcrumbs"]: raise uproot.interpretation.objects.CannotBeAwkward( @@ -683,9 +686,8 @@ def awkward_form(cls, file, context): contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, context ) - contents.update( - file.class_named("TGraph", 4).awkward_form(file, context).contents - ) + tmp_awkward_form = file.class_named("TGraph", 4).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) contents["fEXlow"] = ListOffsetForm( context["index_format"], uproot._util.awkward_form(cls._dtype0, file, context), @@ -714,7 +716,11 @@ def awkward_form(cls, file, context): "uproot": {"as": "TStreamerBasicPointer", "count_name": "fNpoints"} }, ) - return RecordForm(contents, parameters={"__record__": "TGraphAsymmErrors"}) + return RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TGraphAsymmErrors"}, + ) _dtype0 = numpy.dtype(">f8") _dtype1 = numpy.dtype(">f8") diff --git a/src/uproot/models/TH.py b/src/uproot/models/TH.py index f2adf7637..c382aa119 100644 --- a/src/uproot/models/TH.py +++ b/src/uproot/models/TH.py @@ -331,7 +331,7 @@ def strided_interpretation( @classmethod def awkward_form(cls, file, context): - from awkward.forms import RecordForm + from awkward._v2.forms import RecordForm if cls in context["breadcrumbs"]: raise uproot.interpretation.objects.CannotBeAwkward( @@ -346,12 +346,10 @@ def awkward_form(cls, file, context): contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, context ) - contents.update( - file.class_named("TNamed", 1).awkward_form(file, context).contents - ) - contents.update( - file.class_named("TAttAxis", 4).awkward_form(file, context).contents - ) + tmp_awkward_form = file.class_named("TNamed", 1).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + tmp_awkward_form = file.class_named("TAttAxis", 4).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) contents["fNbins"] = uproot._util.awkward_form( numpy.dtype(">i4"), file, context ) @@ -373,7 +371,11 @@ def awkward_form(cls, file, context): contents["fTimeFormat"] = file.class_named("TString", "max").awkward_form( file, context ) - return RecordForm(contents, parameters={"__record__": "TAxis"}) + return RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TAxis"}, + ) _format0 = struct.Struct(">idd") _format1 = struct.Struct(">iiH?") @@ -805,7 +807,7 @@ def strided_interpretation( @classmethod def awkward_form(cls, file, context): - from awkward.forms import ListOffsetForm, RecordForm + from awkward._v2.forms import ListOffsetForm, RecordForm if cls in context["breadcrumbs"]: raise uproot.interpretation.objects.CannotBeAwkward( @@ -820,18 +822,14 @@ def awkward_form(cls, file, context): contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, context ) - contents.update( - file.class_named("TNamed", 1).awkward_form(file, context).contents - ) - contents.update( - file.class_named("TAttLine", 2).awkward_form(file, context).contents - ) - contents.update( - file.class_named("TAttFill", 2).awkward_form(file, context).contents - ) - contents.update( - file.class_named("TAttMarker", 2).awkward_form(file, context).contents - ) + tmp_awkward_form = file.class_named("TNamed", 1).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + tmp_awkward_form = file.class_named("TAttLine", 2).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + tmp_awkward_form = file.class_named("TAttFill", 2).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + tmp_awkward_form = file.class_named("TAttMarker", 2).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) contents["fNcells"] = uproot._util.awkward_form( numpy.dtype(">i4"), file, context ) @@ -902,7 +900,11 @@ def awkward_form(cls, file, context): contents["fStatOverflows"] = uproot._util.awkward_form( numpy.dtype(">i4"), file, context ) - return RecordForm(contents, parameters={"__record__": "TH1"}) + return RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TH1"}, + ) _format0 = struct.Struct(">i") _format1 = struct.Struct(">hhdddddddd") @@ -1113,7 +1115,7 @@ def strided_interpretation( @classmethod def awkward_form(cls, file, context): - from awkward.forms import RecordForm + from awkward._v2.forms import RecordForm if cls in context["breadcrumbs"]: raise uproot.interpretation.objects.CannotBeAwkward( @@ -1128,7 +1130,8 @@ def awkward_form(cls, file, context): contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, context ) - contents.update(file.class_named("TH1", 8).awkward_form(file, context).contents) + tmp_awkward_form = file.class_named("TH1", 8).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) contents["fScalefactor"] = uproot._util.awkward_form( numpy.dtype(">f8"), file, context ) @@ -1141,7 +1144,11 @@ def awkward_form(cls, file, context): contents["fTsumwxy"] = uproot._util.awkward_form( numpy.dtype(">f8"), file, context ) - return RecordForm(contents, parameters={"__record__": "TH2"}) + return RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TH2"}, + ) _format0 = struct.Struct(">dddd") _format_memberwise0 = struct.Struct(">d") @@ -1317,7 +1324,7 @@ def strided_interpretation( @classmethod def awkward_form(cls, file, context): - from awkward.forms import RecordForm + from awkward._v2.forms import RecordForm if cls in context["breadcrumbs"]: raise uproot.interpretation.objects.CannotBeAwkward( @@ -1332,10 +1339,10 @@ def awkward_form(cls, file, context): contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, context ) - contents.update(file.class_named("TH1", 8).awkward_form(file, context).contents) - contents.update( - file.class_named("TAtt3D", 1).awkward_form(file, context).contents - ) + tmp_awkward_form = file.class_named("TH1", 8).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + tmp_awkward_form = file.class_named("TAtt3D", 1).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) contents["fTsumwy"] = uproot._util.awkward_form( numpy.dtype(">f8"), file, context ) @@ -1357,7 +1364,11 @@ def awkward_form(cls, file, context): contents["fTsumwyz"] = uproot._util.awkward_form( numpy.dtype(">f8"), file, context ) - return RecordForm(contents, parameters={"__record__": "TH3"}) + return RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TH3"}, + ) _format0 = struct.Struct(">ddddddd") _format_memberwise0 = struct.Struct(">d") @@ -1502,7 +1513,7 @@ def strided_interpretation( @classmethod def awkward_form(cls, file, context): - from awkward.forms import RecordForm + from awkward._v2.forms import RecordForm if cls in context["breadcrumbs"]: raise uproot.interpretation.objects.CannotBeAwkward( @@ -1517,11 +1528,15 @@ def awkward_form(cls, file, context): contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, context ) - contents.update(file.class_named("TH1", 8).awkward_form(file, context).contents) - contents.update( - file.class_named("TArrayC", 1).awkward_form(file, context).contents + tmp_awkward_form = file.class_named("TH1", 8).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + tmp_awkward_form = file.class_named("TArrayC", 1).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + return RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TH1C"}, ) - return RecordForm(contents, parameters={"__record__": "TH1C"}) base_names_versions = [("TH1", 8), ("TArrayC", 1)] member_names = [] @@ -1660,7 +1675,7 @@ def strided_interpretation( @classmethod def awkward_form(cls, file, context): - from awkward.forms import RecordForm + from awkward._v2.forms import RecordForm if cls in context["breadcrumbs"]: raise uproot.interpretation.objects.CannotBeAwkward( @@ -1675,11 +1690,15 @@ def awkward_form(cls, file, context): contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, context ) - contents.update(file.class_named("TH1", 8).awkward_form(file, context).contents) - contents.update( - file.class_named("TArrayD", 1).awkward_form(file, context).contents + tmp_awkward_form = file.class_named("TH1", 8).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + tmp_awkward_form = file.class_named("TArrayD", 1).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + return RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TH1D"}, ) - return RecordForm(contents, parameters={"__record__": "TH1D"}) base_names_versions = [("TH1", 8), ("TArrayD", 1)] member_names = [] @@ -1813,7 +1832,7 @@ def strided_interpretation( @classmethod def awkward_form(cls, file, context): - from awkward.forms import RecordForm + from awkward._v2.forms import RecordForm if cls in context["breadcrumbs"]: raise uproot.interpretation.objects.CannotBeAwkward( @@ -1828,11 +1847,15 @@ def awkward_form(cls, file, context): contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, context ) - contents.update(file.class_named("TH1", 8).awkward_form(file, context).contents) - contents.update( - file.class_named("TArrayF", 1).awkward_form(file, context).contents + tmp_awkward_form = file.class_named("TH1", 8).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + tmp_awkward_form = file.class_named("TArrayF", 1).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + return RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TH1F"}, ) - return RecordForm(contents, parameters={"__record__": "TH1F"}) base_names_versions = [("TH1", 8), ("TArrayF", 1)] member_names = [] @@ -1966,7 +1989,7 @@ def strided_interpretation( @classmethod def awkward_form(cls, file, context): - from awkward.forms import RecordForm + from awkward._v2.forms import RecordForm if cls in context["breadcrumbs"]: raise uproot.interpretation.objects.CannotBeAwkward( @@ -1981,11 +2004,15 @@ def awkward_form(cls, file, context): contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, context ) - contents.update(file.class_named("TH1", 8).awkward_form(file, context).contents) - contents.update( - file.class_named("TArrayI", 1).awkward_form(file, context).contents + tmp_awkward_form = file.class_named("TH1", 8).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + tmp_awkward_form = file.class_named("TArrayI", 1).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + return RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TH1I"}, ) - return RecordForm(contents, parameters={"__record__": "TH1I"}) base_names_versions = [("TH1", 8), ("TArrayI", 1)] member_names = [] @@ -2124,7 +2151,7 @@ def strided_interpretation( @classmethod def awkward_form(cls, file, context): - from awkward.forms import RecordForm + from awkward._v2.forms import RecordForm if cls in context["breadcrumbs"]: raise uproot.interpretation.objects.CannotBeAwkward( @@ -2139,11 +2166,15 @@ def awkward_form(cls, file, context): contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, context ) - contents.update(file.class_named("TH1", 8).awkward_form(file, context).contents) - contents.update( - file.class_named("TArrayS", 1).awkward_form(file, context).contents + tmp_awkward_form = file.class_named("TH1", 8).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + tmp_awkward_form = file.class_named("TArrayS", 1).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + return RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TH1S"}, ) - return RecordForm(contents, parameters={"__record__": "TH1S"}) base_names_versions = [("TH1", 8), ("TArrayS", 1)] member_names = [] @@ -2282,7 +2313,7 @@ def strided_interpretation( @classmethod def awkward_form(cls, file, context): - from awkward.forms import RecordForm + from awkward._v2.forms import RecordForm if cls in context["breadcrumbs"]: raise uproot.interpretation.objects.CannotBeAwkward( @@ -2297,11 +2328,15 @@ def awkward_form(cls, file, context): contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, context ) - contents.update(file.class_named("TH2", 5).awkward_form(file, context).contents) - contents.update( - file.class_named("TArrayC", 1).awkward_form(file, context).contents + tmp_awkward_form = file.class_named("TH2", 5).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + tmp_awkward_form = file.class_named("TArrayC", 1).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + return RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TH2C"}, ) - return RecordForm(contents, parameters={"__record__": "TH2C"}) base_names_versions = [("TH2", 5), ("TArrayC", 1)] member_names = [] @@ -2441,7 +2476,7 @@ def strided_interpretation( @classmethod def awkward_form(cls, file, context): - from awkward.forms import RecordForm + from awkward._v2.forms import RecordForm if cls in context["breadcrumbs"]: raise uproot.interpretation.objects.CannotBeAwkward( @@ -2456,11 +2491,15 @@ def awkward_form(cls, file, context): contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, context ) - contents.update(file.class_named("TH2", 5).awkward_form(file, context).contents) - contents.update( - file.class_named("TArrayD", 1).awkward_form(file, context).contents + tmp_awkward_form = file.class_named("TH2", 5).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + tmp_awkward_form = file.class_named("TArrayD", 1).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + return RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TH2D"}, ) - return RecordForm(contents, parameters={"__record__": "TH2D"}) base_names_versions = [("TH2", 5), ("TArrayD", 1)] member_names = [] @@ -2595,7 +2634,7 @@ def strided_interpretation( @classmethod def awkward_form(cls, file, context): - from awkward.forms import RecordForm + from awkward._v2.forms import RecordForm if cls in context["breadcrumbs"]: raise uproot.interpretation.objects.CannotBeAwkward( @@ -2610,11 +2649,15 @@ def awkward_form(cls, file, context): contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, context ) - contents.update(file.class_named("TH2", 5).awkward_form(file, context).contents) - contents.update( - file.class_named("TArrayF", 1).awkward_form(file, context).contents + tmp_awkward_form = file.class_named("TH2", 5).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + tmp_awkward_form = file.class_named("TArrayF", 1).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + return RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TH2F"}, ) - return RecordForm(contents, parameters={"__record__": "TH2F"}) base_names_versions = [("TH2", 5), ("TArrayF", 1)] member_names = [] @@ -2754,7 +2797,7 @@ def strided_interpretation( @classmethod def awkward_form(cls, file, context): - from awkward.forms import RecordForm + from awkward._v2.forms import RecordForm if cls in context["breadcrumbs"]: raise uproot.interpretation.objects.CannotBeAwkward( @@ -2769,11 +2812,15 @@ def awkward_form(cls, file, context): contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, context ) - contents.update(file.class_named("TH2", 5).awkward_form(file, context).contents) - contents.update( - file.class_named("TArrayI", 1).awkward_form(file, context).contents + tmp_awkward_form = file.class_named("TH2", 5).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + tmp_awkward_form = file.class_named("TArrayI", 1).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + return RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TH2I"}, ) - return RecordForm(contents, parameters={"__record__": "TH2I"}) base_names_versions = [("TH2", 5), ("TArrayI", 1)] member_names = [] @@ -2913,7 +2960,7 @@ def strided_interpretation( @classmethod def awkward_form(cls, file, context): - from awkward.forms import RecordForm + from awkward._v2.forms import RecordForm if cls in context["breadcrumbs"]: raise uproot.interpretation.objects.CannotBeAwkward( @@ -2928,11 +2975,15 @@ def awkward_form(cls, file, context): contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, context ) - contents.update(file.class_named("TH2", 5).awkward_form(file, context).contents) - contents.update( - file.class_named("TArrayS", 1).awkward_form(file, context).contents + tmp_awkward_form = file.class_named("TH2", 5).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + tmp_awkward_form = file.class_named("TArrayS", 1).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + return RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TH2S"}, ) - return RecordForm(contents, parameters={"__record__": "TH2S"}) base_names_versions = [("TH2", 5), ("TArrayS", 1)] member_names = [] @@ -3072,7 +3123,7 @@ def strided_interpretation( @classmethod def awkward_form(cls, file, context): - from awkward.forms import RecordForm + from awkward._v2.forms import RecordForm if cls in context["breadcrumbs"]: raise uproot.interpretation.objects.CannotBeAwkward( @@ -3087,11 +3138,15 @@ def awkward_form(cls, file, context): contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, context ) - contents.update(file.class_named("TH3", 6).awkward_form(file, context).contents) - contents.update( - file.class_named("TArrayC", 1).awkward_form(file, context).contents + tmp_awkward_form = file.class_named("TH3", 6).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + tmp_awkward_form = file.class_named("TArrayC", 1).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + return RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TH3C"}, ) - return RecordForm(contents, parameters={"__record__": "TH3C"}) base_names_versions = [("TH3", 6), ("TArrayC", 1)] member_names = [] @@ -3232,7 +3287,7 @@ def strided_interpretation( @classmethod def awkward_form(cls, file, context): - from awkward.forms import RecordForm + from awkward._v2.forms import RecordForm if cls in context["breadcrumbs"]: raise uproot.interpretation.objects.CannotBeAwkward( @@ -3247,11 +3302,15 @@ def awkward_form(cls, file, context): contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, context ) - contents.update(file.class_named("TH3", 6).awkward_form(file, context).contents) - contents.update( - file.class_named("TArrayD", 1).awkward_form(file, context).contents + tmp_awkward_form = file.class_named("TH3", 6).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + tmp_awkward_form = file.class_named("TArrayD", 1).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + return RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TH3D"}, ) - return RecordForm(contents, parameters={"__record__": "TH3D"}) base_names_versions = [("TH3", 6), ("TArrayD", 1)] member_names = [] @@ -3387,7 +3446,7 @@ def strided_interpretation( @classmethod def awkward_form(cls, file, context): - from awkward.forms import RecordForm + from awkward._v2.forms import RecordForm if cls in context["breadcrumbs"]: raise uproot.interpretation.objects.CannotBeAwkward( @@ -3402,11 +3461,15 @@ def awkward_form(cls, file, context): contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, context ) - contents.update(file.class_named("TH3", 6).awkward_form(file, context).contents) - contents.update( - file.class_named("TArrayF", 1).awkward_form(file, context).contents + tmp_awkward_form = file.class_named("TH3", 6).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + tmp_awkward_form = file.class_named("TArrayF", 1).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + return RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TH3F"}, ) - return RecordForm(contents, parameters={"__record__": "TH3F"}) base_names_versions = [("TH3", 6), ("TArrayF", 1)] member_names = [] @@ -3547,7 +3610,7 @@ def strided_interpretation( @classmethod def awkward_form(cls, file, context): - from awkward.forms import RecordForm + from awkward._v2.forms import RecordForm if cls in context["breadcrumbs"]: raise uproot.interpretation.objects.CannotBeAwkward( @@ -3562,11 +3625,15 @@ def awkward_form(cls, file, context): contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, context ) - contents.update(file.class_named("TH3", 6).awkward_form(file, context).contents) - contents.update( - file.class_named("TArrayI", 1).awkward_form(file, context).contents + tmp_awkward_form = file.class_named("TH3", 6).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + tmp_awkward_form = file.class_named("TArrayI", 1).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + return RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TH3I"}, ) - return RecordForm(contents, parameters={"__record__": "TH3I"}) base_names_versions = [("TH3", 6), ("TArrayI", 1)] member_names = [] @@ -3707,7 +3774,7 @@ def strided_interpretation( @classmethod def awkward_form(cls, file, context): - from awkward.forms import RecordForm + from awkward._v2.forms import RecordForm if cls in context["breadcrumbs"]: raise uproot.interpretation.objects.CannotBeAwkward( @@ -3722,11 +3789,15 @@ def awkward_form(cls, file, context): contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, context ) - contents.update(file.class_named("TH3", 6).awkward_form(file, context).contents) - contents.update( - file.class_named("TArrayS", 1).awkward_form(file, context).contents + tmp_awkward_form = file.class_named("TH3", 6).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + tmp_awkward_form = file.class_named("TArrayS", 1).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) + return RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TH3S"}, ) - return RecordForm(contents, parameters={"__record__": "TH3S"}) base_names_versions = [("TH3", 6), ("TArrayS", 1)] member_names = [] @@ -3903,7 +3974,7 @@ def strided_interpretation( @classmethod def awkward_form(cls, file, context): - from awkward.forms import RecordForm + from awkward._v2.forms import RecordForm if cls in context["breadcrumbs"]: raise uproot.interpretation.objects.CannotBeAwkward( @@ -3918,9 +3989,8 @@ def awkward_form(cls, file, context): contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, context ) - contents.update( - file.class_named("TH1D", 3).awkward_form(file, context).contents - ) + tmp_awkward_form = file.class_named("TH1D", 3).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) contents["fBinEntries"] = file.class_named("TArrayD", "max").awkward_form( file, context ) @@ -3938,7 +4008,11 @@ def awkward_form(cls, file, context): contents["fBinSumw2"] = file.class_named("TArrayD", "max").awkward_form( file, context ) - return RecordForm(contents, parameters={"__record__": "TProfile"}) + return RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TProfile"}, + ) _format0 = struct.Struct(">idddd") _format_memberwise0 = struct.Struct(">i") @@ -4139,7 +4213,7 @@ def strided_interpretation( @classmethod def awkward_form(cls, file, context): - from awkward.forms import RecordForm + from awkward._v2.forms import RecordForm if cls in context["breadcrumbs"]: raise uproot.interpretation.objects.CannotBeAwkward( @@ -4154,9 +4228,8 @@ def awkward_form(cls, file, context): contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, context ) - contents.update( - file.class_named("TH2D", 4).awkward_form(file, context).contents - ) + tmp_awkward_form = file.class_named("TH2D", 4).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) contents["fBinEntries"] = file.class_named("TArrayD", "max").awkward_form( file, context ) @@ -4174,7 +4247,11 @@ def awkward_form(cls, file, context): contents["fBinSumw2"] = file.class_named("TArrayD", "max").awkward_form( file, context ) - return RecordForm(contents, parameters={"__record__": "TProfile2D"}) + return RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TProfile2D"}, + ) _format0 = struct.Struct(">idddd") _format_memberwise0 = struct.Struct(">i") @@ -4377,7 +4454,7 @@ def strided_interpretation( @classmethod def awkward_form(cls, file, context): - from awkward.forms import RecordForm + from awkward._v2.forms import RecordForm if cls in context["breadcrumbs"]: raise uproot.interpretation.objects.CannotBeAwkward( @@ -4392,9 +4469,8 @@ def awkward_form(cls, file, context): contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, context ) - contents.update( - file.class_named("TH3D", 4).awkward_form(file, context).contents - ) + tmp_awkward_form = file.class_named("TH3D", 4).awkward_form(file, context) + contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents)) contents["fBinEntries"] = file.class_named("TArrayD", "max").awkward_form( file, context ) @@ -4412,7 +4488,11 @@ def awkward_form(cls, file, context): contents["fBinSumw2"] = file.class_named("TArrayD", "max").awkward_form( file, context ) - return RecordForm(contents, parameters={"__record__": "TProfile3D"}) + return RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TProfile3D"}, + ) _format0 = struct.Struct(">idddd") _format_memberwise0 = struct.Struct(">i") diff --git a/src/uproot/models/TNamed.py b/src/uproot/models/TNamed.py index b6cb5d1de..0da670995 100644 --- a/src/uproot/models/TNamed.py +++ b/src/uproot/models/TNamed.py @@ -63,8 +63,9 @@ def awkward_form(cls, file, context): contents["fTitle"] = uproot.containers.AsString( False, typename="TString" ).awkward_form(file, context) - return awkward.forms.RecordForm( - contents, + return awkward._v2.forms.RecordForm( + list(contents.values()), + list(contents.keys()), parameters={"__record__": "TNamed"}, ) diff --git a/src/uproot/models/TObjString.py b/src/uproot/models/TObjString.py index c596c6c17..544dc7faf 100644 --- a/src/uproot/models/TObjString.py +++ b/src/uproot/models/TObjString.py @@ -89,9 +89,9 @@ def __repr__(self): @classmethod def awkward_form(cls, file, context): awkward = uproot.extras.awkward() - return awkward.forms.ListOffsetForm( + return awkward._v2.forms.ListOffsetForm( context["index_format"], - awkward.forms.NumpyForm((), 1, "B", parameters={"__array__": "char"}), + awkward._v2.forms.NumpyForm("uint8", parameters={"__array__": "char"}), parameters={ "__array__": "string", "uproot": {"as": "TObjString", "header": True, "length_bytes": "1-5"}, diff --git a/src/uproot/models/TObject.py b/src/uproot/models/TObject.py index de9be1b7a..99ae22288 100644 --- a/src/uproot/models/TObject.py +++ b/src/uproot/models/TObject.py @@ -84,7 +84,11 @@ def awkward_form(cls, file, context): contents["@pidf"] = uproot._util.awkward_form( numpy.dtype("u2"), file, context ) - return awkward.forms.RecordForm(contents, parameters={"__record__": "TObject"}) + return awkward._v2.forms.RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TObject"}, + ) def __repr__(self): return "".format( diff --git a/src/uproot/models/TRef.py b/src/uproot/models/TRef.py index 924ce60e4..54129b926 100644 --- a/src/uproot/models/TRef.py +++ b/src/uproot/models/TRef.py @@ -80,7 +80,11 @@ def awkward_form(cls, file, context): contents["@other2"] = uproot._util.awkward_form( numpy.dtype("u4"), file, context ) - return awkward.forms.RecordForm(contents, parameters={"__record__": "TRef"}) + return awkward._v2.forms.RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TRef"}, + ) _trefarray_format1 = struct.Struct(">i") @@ -132,21 +136,21 @@ def read_members(self, chunk, cursor, context, file): helper_obj.add_to_pre("10 stream skip\n") helper_obj.add_to_pre( - f"stream !B-> stack dup 255 = if drop stream !I-> stack then dup part0-node{form_keys[1]}-offsets +<- stack stream #!B-> part0-node{form_keys[2]}-data\n" + f"stream !B-> stack dup 255 = if drop stream !I-> stack then dup node{form_keys[1]}-offsets +<- stack stream #!B-> node{form_keys[2]}-data\n" ) helper_obj.add_to_pre( - f"stream !I-> stack dup part0-node{form_keys[3]}-data <- stack\n" + f"stream !I-> stack dup node{form_keys[3]}-data <- stack\n" ) helper_obj.add_to_pre("6 stream skip\n") helper_obj.add_to_pre( - f"dup part0-node{form_keys[4]}-offsets +<- stack stream #!I-> part0-node{form_keys[5]}-data\n" + f"dup node{form_keys[4]}-offsets +<- stack stream #!I-> node{form_keys[5]}-data\n" ) keys = [ - f"part0-node{form_keys[1]}-offsets", - f"part0-node{form_keys[3]}-data", - f"part0-node{form_keys[4]}-offsets", - f"part0-node{form_keys[2]}-data", - f"part0-node{form_keys[5]}-data", + f"node{form_keys[1]}-offsets", + f"node{form_keys[3]}-data", + f"node{form_keys[4]}-offsets", + f"node{form_keys[2]}-data", + f"node{form_keys[5]}-data", ] if forth_obj.should_add_form(): for elem in keys: @@ -155,10 +159,10 @@ def read_members(self, chunk, cursor, context, file): temp_aform = f'{{"class": "RecordArray", "contents": {{"fname": {{"class": "ListOffsetArray", "offsets": "i64", "content": {{"class": "NumpyArray", "primitive": "uint8", "inner_shape": [], "has_identifier": false, "parameters": {{"__array__": "char"}}, "form_key": "node{form_keys[2]}"}}, "has_identifier": false, "parameters": {{"uproot": {{"as": "vector", "header": {temp_bool}}}}}, "form_key": "node{form_keys[1]}"}}, "fSize": {{"class": "NumpyArray", "primitive": "int64", "inner_shape": [], "has_identifier": false, "parameters": {{}}, "form_key": "node{form_keys[3]}"}}, "refs": {{"class": "ListOffsetArray", "offsets": "i64", "content": {{"class": "NumpyArray", "primitive": "int64", "inner_shape": [], "has_identifier": false, "parameters": {{}}, "form_key": "node{form_keys[5]}"}}, "has_identifier": false, "parameters": {{}}, "form_key": "node{form_keys[4]}"}}}}, "has_identifier": false, "parameters": {{}}, "form_key": "node{form_keys[0]}"}}' forth_obj.add_form(json.loads(temp_aform)) helper_obj.add_to_header( - f"output part0-node{form_keys[1]}-offsets int64\noutput part0-node{form_keys[2]}-data uint8\noutput part0-node{form_keys[3]}-data int64\noutput part0-node{form_keys[4]}-offsets int64\noutput part0-node{form_keys[5]}-data int64\n" + f"output node{form_keys[1]}-offsets int64\noutput node{form_keys[2]}-data uint8\noutput node{form_keys[3]}-data int64\noutput node{form_keys[4]}-offsets int64\noutput node{form_keys[5]}-data int64\n" ) helper_obj.add_to_init( - f"0 part0-node{form_keys[1]}-offsets <- stack\n0 part0-node{form_keys[4]}-offsets <- stack\n" + f"0 node{form_keys[1]}-offsets <- stack\n0 node{form_keys[4]}-offsets <- stack\n" ) temp = forth_obj.add_node( f"node{form_keys[0]}", @@ -212,12 +216,14 @@ def awkward_form(cls, file, context): False, typename="TString" ).awkward_form(file, context) contents["fSize"] = uproot._util.awkward_form(numpy.dtype("i4"), file, context) - contents["refs"] = awkward.forms.ListOffsetForm( + contents["refs"] = awkward._v2.forms.ListOffsetForm( context["index_format"], uproot._util.awkward_form(numpy.dtype("i4"), file, context), ) - return awkward.forms.RecordForm( - contents, parameters={"__record__": "TRefArray"} + return awkward._v2.forms.RecordForm( + list(contents.values()), + list(contents.keys()), + parameters={"__record__": "TRefArray"}, ) diff --git a/src/uproot/streamers.py b/src/uproot/streamers.py index 0ee684e51..52205e8e3 100644 --- a/src/uproot/streamers.py +++ b/src/uproot/streamers.py @@ -229,7 +229,7 @@ def class_code(self): awkward_form = [ " @classmethod", " def awkward_form(cls, file, context):", - " from awkward.forms import NumpyForm, ListOffsetForm, RegularForm, RecordForm", + " from awkward._v2.forms import NumpyForm, ListOffsetForm, RegularForm, RecordForm", " if cls in context['breadcrumbs']:", " raise uproot.interpretation.objects.CannotBeAwkward('classes that can contain members of the same type cannot be Awkward Arrays because the depth of instances is unbounded')", " context['breadcrumbs'] = context['breadcrumbs'] + (cls,)", @@ -280,7 +280,7 @@ def class_code(self): strided_interpretation.append("") awkward_form.append( - f" return RecordForm(contents, parameters={{'__record__': {self.name!r} }})" + f" return RecordForm(list(contents.values()), list(contents.keys()), parameters={{'__record__': {self.name!r} }})" ) awkward_form.append("") @@ -695,7 +695,10 @@ def class_code( f" members.extend(file.class_named({self.name!r}, {self.base_version!r}).strided_interpretation(file, header, tobject_header, breadcrumbs).members)" ) awkward_form.append( - f" contents.update(file.class_named({self.name!r}, {self.base_version!r}).awkward_form(file,context).contents)" + f" tmp_awkward_form = file.class_named({self.name!r}, {self.base_version!r}).awkward_form(file, context)" + ) + awkward_form.append( + " contents.update(zip(tmp_awkward_form.fields, tmp_awkward_form.contents))" ) base_names_versions.append((self.name, self.base_version)) @@ -955,12 +958,12 @@ def class_code( if self.array_length == 0: if self.typename == "Double32_t": awkward_form.append( - f" contents[{self.name!r}] = NumpyForm((), 8, 'd', parameters={{'uproot': {{'as': 'Double32'}}}})" + f" contents[{self.name!r}] = NumpyForm('float64', parameters={{'uproot': {{'as': 'Double32'}}}})" ) elif self.typename == "Float16_t": awkward_form.append( - f" contents[{self.name!r}] = NumpyForm((), 4, 'f', parameters={{'uproot': {{'as': 'Float16'}}}})" + f" contents[{self.name!r}] = NumpyForm('float32', parameters={{'uproot': {{'as': 'Float16'}}}})" ) else: diff --git a/src/uproot/writing/_cascadetree.py b/src/uproot/writing/_cascadetree.py index 8bce03ff2..cdc9f7f16 100644 --- a/src/uproot/writing/_cascadetree.py +++ b/src/uproot/writing/_cascadetree.py @@ -132,21 +132,23 @@ def __init__( raise TypeError( f"not a NumPy dtype and 'awkward' cannot be imported: {branch_type!r}" ) from err - if isinstance(branch_type, awkward.types.Type): + if isinstance( + branch_type, + (awkward._v2.types.Type, awkward._v2.types.ArrayType), + ): branch_datashape = branch_type else: try: - branch_datashape = awkward.types.from_datashape(branch_type) + branch_datashape = awkward._v2.types.from_datashape( + branch_type, highlevel=False + ) except Exception: raise TypeError( f"not a NumPy dtype or an Awkward datashape: {branch_type!r}" ) - # checking by class name to be Awkward v1/v2 insensitive - if type(branch_datashape).__name__ == "ArrayType": - if hasattr(branch_datashape, "content"): - branch_datashape = branch_datashape.content - else: - branch_datashape = branch_datashape.type + if isinstance(branch_datashape, awkward._v2.types.ArrayType): + branch_datashape = branch_datashape.content + branch_dtype = self._branch_ak_to_np(branch_datashape) if branch_dict is not None: @@ -193,12 +195,9 @@ def __init__( elif parameters.get("__array__") == "bytes": raise NotImplementedError("array of bytes") - # checking by class name to be Awkward v1/v2 insensitive + # 'awkward' is not in namespace elif type(branch_datashape).__name__ == "ListType": - if hasattr(branch_datashape, "content"): - content = branch_datashape.content - else: - content = branch_datashape.type + content = branch_datashape.content counter_name = self._counter_name(branch_name) counter_dtype = numpy.dtype(numpy.int32) @@ -216,7 +215,7 @@ def __init__( contents = content.contents else: contents = content.fields() - keys = content.keys + keys = content.fields if callable(keys): keys = keys() if keys is None: @@ -266,7 +265,7 @@ def __init__( contents = branch_datashape.contents else: contents = branch_datashape.fields() - keys = branch_datashape.keys + keys = branch_datashape.fields if callable(keys): keys = keys() if keys is None: @@ -325,16 +324,12 @@ def __init__( self._key = None def _branch_ak_to_np(self, branch_datashape): - # checking by class name to be Awkward v1/v2 insensitive if type(branch_datashape).__name__ == "NumpyType": return numpy.dtype(branch_datashape.primitive) elif type(branch_datashape).__name__ == "PrimitiveType": return numpy.dtype(branch_datashape.dtype) elif type(branch_datashape).__name__ == "RegularType": - if hasattr(branch_datashape, "content"): - content = self._branch_ak_to_np(branch_datashape.content) - else: - content = self._branch_ak_to_np(branch_datashape.type) + content = self._branch_ak_to_np(branch_datashape.content) if content is None: return None elif content.subdtype is None: @@ -524,16 +519,16 @@ def extend(self, file, sink, data): f"an Awkward Array was provided, but 'awkward' cannot be imported: {data!r}" ) from err - if isinstance(data, awkward.Array): + if isinstance(data, awkward._v2.Array): if data.ndim > 1 and not data.layout.purelist_isregular: provided = { self._counter_name(""): numpy.asarray( - awkward.num(data, axis=1), dtype=">u4" + awkward._v2.num(data, axis=1), dtype=">u4" ) } else: provided = {} - for k, v in zip(awkward.fields(data), awkward.unzip(data)): + for k, v in zip(awkward._v2.fields(data), awkward._v2.unzip(data)): provided[k] = v if isinstance(data, numpy.ndarray) and data.dtype.fields is not None: @@ -568,7 +563,7 @@ def extend(self, file, sink, data): raise TypeError( f"NumPy dtype would be dtype('O'), so we won't use NumPy, but 'awkward' cannot be imported: {k}: {type(v)}" ) from err - v = awkward.from_iter(v) + v = awkward._v2.from_iter(v) if getattr(v, "dtype", None) == numpy.dtype("O"): try: @@ -577,7 +572,7 @@ def extend(self, file, sink, data): raise TypeError( f"NumPy dtype is dtype('O'), so we won't use NumPy, but 'awkward' cannot be imported: {k}: {type(v)}" ) from err - v = awkward.from_iter(v) + v = awkward._v2.from_iter(v) if uproot._util.from_module(v, "awkward"): try: @@ -587,12 +582,12 @@ def extend(self, file, sink, data): f"an Awkward Array was provided, but 'awkward' cannot be imported: {k}: {type(v)}" ) from err if ( - isinstance(v, awkward.Array) + isinstance(v, awkward._v2.Array) and v.ndim > 1 and not v.layout.purelist_isregular ): kk = self._counter_name(k) - vv = numpy.asarray(awkward.num(v, axis=1), dtype=">u4") + vv = numpy.asarray(awkward._v2.num(v, axis=1), dtype=">u4") if kk in provided: if not numpy.array_equal(vv, provided[kk]): raise ValueError( @@ -702,40 +697,13 @@ def extend(self, file, sink, data): f"a jagged array was provided (possibly as an iterable), but 'awkward' cannot be imported: {branch_name}: {branch_array!r}" ) from err layout = branch_array.layout - while not isinstance( - layout, - ( - awkward.layout.ListOffsetArray32, - awkward.layout.ListOffsetArrayU32, - awkward.layout.ListOffsetArray64, - ), - ): - if isinstance(layout, awkward.partition.PartitionedArray): - layout = awkward.concatenate(layout.partitions, highlevel=False) - - elif isinstance( - layout, - ( - awkward.layout.IndexedArray32, - awkward.layout.IndexedArrayU32, - awkward.layout.IndexedArray64, - ), - ): + while not isinstance(layout, awkward._v2.contents.ListOffsetArray): + if isinstance(layout, awkward._v2.contents.IndexedArray): layout = layout.project() - elif isinstance( - layout, - ( - awkward.layout.ListArray32, - awkward.layout.ListArrayU32, - awkward.layout.ListArray64, - ), - ): + elif isinstance(layout, awkward._v2.contents.ListArray): layout = layout.toListOffsetArray64(False) - elif isinstance(layout, awkward.layout.VirtualArray): - layout = layout.array - else: raise AssertionError( "how did this pass the type check?\n\n" + repr(layout) @@ -751,27 +719,17 @@ def extend(self, file, sink, data): content = content[: offsets[-1]] shape = [len(content)] - while not isinstance(content, awkward.layout.NumpyArray): - if isinstance( - content, - ( - awkward.layout.IndexedArray32, - awkward.layout.IndexedArrayU32, - awkward.layout.IndexedArray64, - ), - ): + while not isinstance(content, awkward._v2.contents.NumpyArray): + if isinstance(content, awkward._v2.contents.IndexedArray): content = content.project() - elif isinstance(content, awkward.layout.EmptyArray): + elif isinstance(content, awkward._v2.contents.EmptyArray): content = content.toNumpyArray() - elif isinstance(content, awkward.layout.RegularArray): + elif isinstance(content, awkward._v2.contents.RegularArray): shape.append(content.size) content = content.content - elif isinstance(layout, awkward.layout.VirtualArray): - content = content.array - else: raise AssertionError( "how did this pass the type check?\n\n" + repr(content) diff --git a/src/uproot/writing/identify.py b/src/uproot/writing/identify.py index c56282fa1..20f4ff378 100644 --- a/src/uproot/writing/identify.py +++ b/src/uproot/writing/identify.py @@ -58,7 +58,7 @@ def add_to_directory(obj, name, directory, streamers): if uproot._util.from_module(obj, "awkward"): import awkward - if isinstance(obj, awkward.Array): + if isinstance(obj, awkward._v2.Array): obj = {"": obj} if isinstance(obj, numpy.ndarray) and obj.dtype.fields is not None: @@ -123,12 +123,12 @@ def add_to_directory(obj, name, directory, streamers): except ImportError: break try: - branch_array = awkward.from_iter(branch_array) + branch_array = awkward._v2.from_iter(branch_array) except Exception: break else: data[branch_name] = branch_array - metadata[branch_name] = awkward.type(branch_array) + metadata[branch_name] = awkward._v2.type(branch_array) else: data[branch_name] = branch_array diff --git a/tests/test_0018-array-fetching-interface.py b/tests/test_0018-array-fetching-interface.py index 47e754bdb..97a700edb 100644 --- a/tests/test_0018-array-fetching-interface.py +++ b/tests/test_0018-array-fetching-interface.py @@ -709,7 +709,7 @@ def test_jagged_awkward(): skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root") )["sample/Ai2"] as branch: result = branch.array(interpretation) - assert awkward.to_list(result) == [ + assert awkward._v2.to_list(result) == [ [], [-15], [-15, -13], diff --git a/tests/test_0033-more-interpretations-2.py b/tests/test_0033-more-interpretations-2.py index 1d3255585..a28732817 100644 --- a/tests/test_0033-more-interpretations-2.py +++ b/tests/test_0033-more-interpretations-2.py @@ -15,7 +15,7 @@ def test_awkward_strings(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - assert awkward.to_list(tree["string"].array(library="ak")) == [ + assert awkward._v2.to_list(tree["string"].array(library="ak")) == [ "one", "two", "three", @@ -60,8 +60,8 @@ def test_leaflist_awkward(): "tree/leaflist" ] as branch: result = branch.array(library="ak") - assert str(awkward.type(result)) == '5 * {"x": float64, "y": int32, "z": int8}' - assert awkward.to_list(result) == [ + assert str(awkward._v2.type(result)) == "5 * {x: float64, y: int32, z: int8}" + assert awkward._v2.to_list(result) == [ {"x": 1.1, "y": 1, "z": 97}, {"x": 2.2, "y": 2, "z": 98}, {"x": 3.3, "y": 3, "z": 99}, @@ -131,7 +131,7 @@ def test_fixed_width_awkward(): with uproot.open( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root") )["sample"] as tree: - assert awkward.to_list(tree["ai4"].array(library="ak")) == [ + assert awkward._v2.to_list(tree["ai4"].array(library="ak")) == [ [i, i + 1, i + 2] for i in range(-14, 16) ] diff --git a/tests/test_0034-generic-objects-in-ttrees.py b/tests/test_0034-generic-objects-in-ttrees.py index cd259e4b9..7727a4d39 100644 --- a/tests/test_0034-generic-objects-in-ttrees.py +++ b/tests/test_0034-generic-objects-in-ttrees.py @@ -237,11 +237,10 @@ def test_strided_awkward(): result = tree["MET"].array(library="ak") assert ( - repr(awkward.type(result)) - == '2421 * TVector2["fX": float64, "fY": float64]' + str(awkward._v2.type(result)) == "2421 * TVector2[fX: float64, fY: float64]" ) - assert awkward.to_list(result["fX"][:10]) == [ + assert awkward._v2.to_list(result["fX"][:10]) == [ 5.912771224975586, 24.76520347595215, -25.78508758544922, @@ -253,7 +252,7 @@ def test_strided_awkward(): 42.416194915771484, -1.9144694805145264, ] - assert awkward.to_list(result["fY"][:10]) == [ + assert awkward._v2.to_list(result["fY"][:10]) == [ 2.5636332035064697, -16.349109649658203, 16.237131118774414, @@ -275,9 +274,9 @@ def test_jagged_strided_awkward(): result = tree["muonp4"].array(library="ak") assert ( - repr(awkward.type(result)) - == '2421 * var * TLorentzVector["fP": TVector3["fX": float64, ' - '"fY": float64, "fZ": float64], "fE": float64]' + str(awkward._v2.type(result)) + == "2421 * var * TLorentzVector[fP: TVector3[fX: float64, " + "fY: float64, fZ: float64], fE: float64]" ) assert result[0, 0, "fE"] == 54.77949905395508 @@ -293,7 +292,7 @@ def test_jagged_awkward_1(): ] as branch: assert branch.interpretation == AsJagged(AsDtype(">u8"), header_bytes=1) result = branch.array(library="ak", entry_stop=6) - assert awkward.to_list(result) == [ + assert awkward._v2.to_list(result) == [ [], [1], [2, 2], @@ -310,7 +309,7 @@ def test_jagged_awkward_2(): ] as branch: assert branch.interpretation == AsJagged(AsDtype(">f8"), header_bytes=10) result = branch.array(library="ak", entry_stop=6) - assert awkward.to_list(result) == [ + assert awkward._v2.to_list(result) == [ [], [1], [2, 2], @@ -332,63 +331,25 @@ def test_general_awkward_form(): "breadcrumbs": (), } assert json.loads( - branch.interpretation.awkward_form(branch.file, context).tojson( - verbose=False - ) + branch.interpretation.awkward_form(branch.file, context).to_json() ) == json.loads( """{ "class": "RecordArray", "contents": { - "ArrayF32": { - "class": "RegularArray", - "content": "float32", - "size": 10 - }, - "ArrayF64": { - "class": "RegularArray", - "content": "float64", - "size": 10 - }, - "ArrayI16": { - "class": "RegularArray", - "content": "int16", - "size": 10 - }, - "ArrayI32": { - "class": "RegularArray", - "content": "int32", - "size": 10 - }, - "ArrayI64": { - "class": "RegularArray", - "content": "int64", - "size": 10 - }, - "ArrayU16": { - "class": "RegularArray", - "content": "uint16", - "size": 10 - }, - "ArrayU32": { - "class": "RegularArray", - "content": "uint32", - "size": 10 - }, - "ArrayU64": { - "class": "RegularArray", - "content": "uint64", - "size": 10 - }, "Beg": { - "class": "ListOffsetArray64", + "class": "ListOffsetArray", "offsets": "i64", "content": { "class": "NumpyArray", - "format": "B", - "itemsize": 1, - "parameters": {"__array__": "char"}, - "primitive": "uint8" + "primitive": "uint8", + "inner_shape": [], + "has_identifier": false, + "parameters": { + "__array__": "char" + }, + "form_key": null }, + "has_identifier": false, "parameters": { "__array__": "string", "uproot": { @@ -396,18 +357,87 @@ def test_general_awkward_form(): "header": false, "length_bytes": "1-5" } - } + }, + "form_key": null }, - "End": { - "class": "ListOffsetArray64", + "I16": { + "class": "NumpyArray", + "primitive": "int16", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "I32": { + "class": "NumpyArray", + "primitive": "int32", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "I64": { + "class": "NumpyArray", + "primitive": "int64", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "U16": { + "class": "NumpyArray", + "primitive": "uint16", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "U32": { + "class": "NumpyArray", + "primitive": "uint32", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "U64": { + "class": "NumpyArray", + "primitive": "uint64", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "F32": { + "class": "NumpyArray", + "primitive": "float32", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "F64": { + "class": "NumpyArray", + "primitive": "float64", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "Str": { + "class": "ListOffsetArray", "offsets": "i64", "content": { "class": "NumpyArray", - "format": "B", - "itemsize": 1, - "parameters": {"__array__": "char"}, - "primitive": "uint8" + "primitive": "uint8", + "inner_shape": [], + "has_identifier": false, + "parameters": { + "__array__": "char" + }, + "form_key": null }, + "has_identifier": false, "parameters": { "__array__": "string", "uproot": { @@ -415,123 +445,345 @@ def test_general_awkward_form(): "header": false, "length_bytes": "1-5" } - } + }, + "form_key": null }, - "F32": "float32", - "F64": "float64", - "I16": "int16", - "I32": "int32", - "I64": "int64", - "N": "uint32", "P3": { "class": "RecordArray", "contents": { - "Px": "int32", - "Py": "float64", - "Pz": "int32" + "Px": { + "class": "NumpyArray", + "primitive": "int32", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "Py": { + "class": "NumpyArray", + "primitive": "float64", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "Pz": { + "class": "NumpyArray", + "primitive": "int32", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + } }, + "has_identifier": false, "parameters": { "__record__": "P3" - } + }, + "form_key": null }, - "SliceF32": { - "class": "ListOffsetArray64", + "ArrayI16": { + "class": "RegularArray", + "size": 10, + "content": { + "class": "NumpyArray", + "primitive": "int16", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "ArrayI32": { + "class": "RegularArray", + "size": 10, + "content": { + "class": "NumpyArray", + "primitive": "int32", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "ArrayI64": { + "class": "RegularArray", + "size": 10, + "content": { + "class": "NumpyArray", + "primitive": "int64", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "ArrayU16": { + "class": "RegularArray", + "size": 10, + "content": { + "class": "NumpyArray", + "primitive": "uint16", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "ArrayU32": { + "class": "RegularArray", + "size": 10, + "content": { + "class": "NumpyArray", + "primitive": "uint32", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "ArrayU64": { + "class": "RegularArray", + "size": 10, + "content": { + "class": "NumpyArray", + "primitive": "uint64", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "ArrayF32": { + "class": "RegularArray", + "size": 10, + "content": { + "class": "NumpyArray", + "primitive": "float32", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "ArrayF64": { + "class": "RegularArray", + "size": 10, + "content": { + "class": "NumpyArray", + "primitive": "float64", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "N": { + "class": "NumpyArray", + "primitive": "uint32", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "SliceI16": { + "class": "ListOffsetArray", "offsets": "i64", - "content": "float32", + "content": { + "class": "NumpyArray", + "primitive": "int16", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "has_identifier": false, "parameters": { "uproot": { "as": "TStreamerBasicPointer", "count_name": "N" } - } + }, + "form_key": null }, - "SliceF64": { - "class": "ListOffsetArray64", + "SliceI32": { + "class": "ListOffsetArray", "offsets": "i64", - "content": "float64", + "content": { + "class": "NumpyArray", + "primitive": "int32", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "has_identifier": false, "parameters": { "uproot": { "as": "TStreamerBasicPointer", "count_name": "N" } - } + }, + "form_key": null }, - "SliceI16": { - "class": "ListOffsetArray64", + "SliceI64": { + "class": "ListOffsetArray", "offsets": "i64", - "content": "int16", + "content": { + "class": "NumpyArray", + "primitive": "int64", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "has_identifier": false, "parameters": { "uproot": { "as": "TStreamerBasicPointer", "count_name": "N" } - } + }, + "form_key": null }, - "SliceI32": { - "class": "ListOffsetArray64", + "SliceU16": { + "class": "ListOffsetArray", "offsets": "i64", - "content": "int32", + "content": { + "class": "NumpyArray", + "primitive": "uint16", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "has_identifier": false, "parameters": { "uproot": { "as": "TStreamerBasicPointer", "count_name": "N" } - } + }, + "form_key": null }, - "SliceI64": { - "class": "ListOffsetArray64", + "SliceU32": { + "class": "ListOffsetArray", "offsets": "i64", - "content": "int64", + "content": { + "class": "NumpyArray", + "primitive": "uint32", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "has_identifier": false, "parameters": { "uproot": { "as": "TStreamerBasicPointer", "count_name": "N" } - } + }, + "form_key": null }, - "SliceU16": { - "class": "ListOffsetArray64", + "SliceU64": { + "class": "ListOffsetArray", "offsets": "i64", - "content": "uint16", + "content": { + "class": "NumpyArray", + "primitive": "uint64", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "has_identifier": false, "parameters": { "uproot": { "as": "TStreamerBasicPointer", "count_name": "N" } - } + }, + "form_key": null }, - "SliceU32": { - "class": "ListOffsetArray64", + "SliceF32": { + "class": "ListOffsetArray", "offsets": "i64", - "content": "uint32", + "content": { + "class": "NumpyArray", + "primitive": "float32", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "has_identifier": false, "parameters": { "uproot": { "as": "TStreamerBasicPointer", "count_name": "N" } - } + }, + "form_key": null }, - "SliceU64": { - "class": "ListOffsetArray64", + "SliceF64": { + "class": "ListOffsetArray", "offsets": "i64", - "content": "uint64", + "content": { + "class": "NumpyArray", + "primitive": "float64", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "has_identifier": false, "parameters": { "uproot": { "as": "TStreamerBasicPointer", "count_name": "N" } - } + }, + "form_key": null }, "StdStr": { - "class": "ListOffsetArray64", + "class": "ListOffsetArray", "offsets": "i64", "content": { "class": "NumpyArray", - "format": "B", - "itemsize": 1, - "parameters": {"__array__": "char"}, - "primitive": "uint8" + "primitive": "uint8", + "inner_shape": [], + "has_identifier": false, + "parameters": { + "__array__": "char" + }, + "form_key": null }, + "has_identifier": false, "parameters": { "__array__": "string", "uproot": { @@ -539,135 +791,219 @@ def test_general_awkward_form(): "header": true, "length_bytes": "1-5" } - } + }, + "form_key": null }, - "StlVecF32": { - "class": "ListOffsetArray64", + "StlVecI16": { + "class": "ListOffsetArray", "offsets": "i64", - "content": "float32", + "content": { + "class": "NumpyArray", + "primitive": "int16", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "has_identifier": false, "parameters": { "uproot": { "as": "vector", "header": true } - } + }, + "form_key": null }, - "StlVecF64": { - "class": "ListOffsetArray64", + "StlVecI32": { + "class": "ListOffsetArray", "offsets": "i64", - "content": "float64", + "content": { + "class": "NumpyArray", + "primitive": "int32", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "has_identifier": false, "parameters": { "uproot": { "as": "vector", "header": true } - } + }, + "form_key": null }, - "StlVecI16": { - "class": "ListOffsetArray64", + "StlVecI64": { + "class": "ListOffsetArray", "offsets": "i64", - "content": "int16", + "content": { + "class": "NumpyArray", + "primitive": "int64", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "has_identifier": false, "parameters": { "uproot": { "as": "vector", "header": true } - } + }, + "form_key": null }, - "StlVecI32": { - "class": "ListOffsetArray64", + "StlVecU16": { + "class": "ListOffsetArray", "offsets": "i64", - "content": "int32", + "content": { + "class": "NumpyArray", + "primitive": "uint16", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "has_identifier": false, "parameters": { "uproot": { "as": "vector", "header": true } - } + }, + "form_key": null }, - "StlVecI64": { - "class": "ListOffsetArray64", + "StlVecU32": { + "class": "ListOffsetArray", "offsets": "i64", - "content": "int64", + "content": { + "class": "NumpyArray", + "primitive": "uint32", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "has_identifier": false, "parameters": { "uproot": { "as": "vector", "header": true } - } + }, + "form_key": null }, - "StlVecStr": { - "class": "ListOffsetArray64", + "StlVecU64": { + "class": "ListOffsetArray", "offsets": "i64", "content": { - "class": "ListOffsetArray64", - "offsets": "i64", - "content": { - "class": "NumpyArray", - "format": "B", - "itemsize": 1, - "parameters": {"__array__": "char"}, - "primitive": "uint8" - }, - "parameters": { - "__array__": "string", - "uproot": { - "as": "string", - "header": false, - "length_bytes": "1-5" - } - } + "class": "NumpyArray", + "primitive": "uint64", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null }, + "has_identifier": false, "parameters": { "uproot": { "as": "vector", "header": true } - } + }, + "form_key": null }, - "StlVecU16": { - "class": "ListOffsetArray64", + "StlVecF32": { + "class": "ListOffsetArray", "offsets": "i64", - "content": "uint16", + "content": { + "class": "NumpyArray", + "primitive": "float32", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "has_identifier": false, "parameters": { "uproot": { "as": "vector", "header": true } - } + }, + "form_key": null }, - "StlVecU32": { - "class": "ListOffsetArray64", + "StlVecF64": { + "class": "ListOffsetArray", "offsets": "i64", - "content": "uint32", + "content": { + "class": "NumpyArray", + "primitive": "float64", + "inner_shape": [], + "has_identifier": false, + "parameters": {}, + "form_key": null + }, + "has_identifier": false, "parameters": { "uproot": { "as": "vector", "header": true } - } + }, + "form_key": null }, - "StlVecU64": { - "class": "ListOffsetArray64", + "StlVecStr": { + "class": "ListOffsetArray", "offsets": "i64", - "content": "uint64", + "content": { + "class": "ListOffsetArray", + "offsets": "i64", + "content": { + "class": "NumpyArray", + "primitive": "uint8", + "inner_shape": [], + "has_identifier": false, + "parameters": { + "__array__": "char" + }, + "form_key": null + }, + "has_identifier": false, + "parameters": { + "__array__": "string", + "uproot": { + "as": "string", + "header": false, + "length_bytes": "1-5" + } + }, + "form_key": null + }, + "has_identifier": false, "parameters": { "uproot": { "as": "vector", "header": true } - } + }, + "form_key": null }, - "Str": { - "class": "ListOffsetArray64", + "End": { + "class": "ListOffsetArray", "offsets": "i64", "content": { "class": "NumpyArray", - "format": "B", - "itemsize": 1, - "parameters": {"__array__": "char"}, - "primitive": "uint8" + "primitive": "uint8", + "inner_shape": [], + "has_identifier": false, + "parameters": { + "__array__": "char" + }, + "form_key": null }, + "has_identifier": false, "parameters": { "__array__": "string", "uproot": { @@ -675,15 +1011,15 @@ def test_general_awkward_form(): "header": false, "length_bytes": "1-5" } - } - }, - "U16": "uint16", - "U32": "uint32", - "U64": "uint64" + }, + "form_key": null + } }, + "has_identifier": false, "parameters": { "__record__": "Event" - } + }, + "form_key": null }""" ) @@ -693,7 +1029,7 @@ def test_jagged_awkward_3(): with uproot.open(skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root"))[ "tree/evt/StlVecStr" ] as branch: - assert awkward.to_list(branch.array(library="ak")[:6, :3]) == [ + assert awkward._v2.to_list(branch.array(library="ak")[:6, :3]) == [ [], ["vec-001"], ["vec-002", "vec-002"], @@ -708,7 +1044,7 @@ def test_awkward_string(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - assert awkward.to_list(tree["string"].array(library="ak")) == [ + assert awkward._v2.to_list(tree["string"].array(library="ak")) == [ "one", "two", "three", @@ -722,7 +1058,7 @@ def test_awkward_tstring(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - assert awkward.to_list(tree["tstring"].array(library="ak")) == [ + assert awkward._v2.to_list(tree["tstring"].array(library="ak")) == [ "one", "two", "three", @@ -736,7 +1072,7 @@ def test_awkward_vector_int32(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - assert awkward.to_list(tree["vector_int32"].array(library="ak")) == [ + assert awkward._v2.to_list(tree["vector_int32"].array(library="ak")) == [ [1], [1, 2], [1, 2, 3], @@ -750,7 +1086,7 @@ def test_awkward_vector_string(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - assert awkward.to_list(tree["vector_string"].array(library="ak")) == [ + assert awkward._v2.to_list(tree["vector_string"].array(library="ak")) == [ ["one"], ["one", "two"], ["one", "two", "three"], @@ -764,7 +1100,7 @@ def test_awkward_vector_tstring(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - assert awkward.to_list(tree["vector_tstring"].array(library="ak")) == [ + assert awkward._v2.to_list(tree["vector_tstring"].array(library="ak")) == [ ["one"], ["one", "two"], ["one", "two", "three"], @@ -778,7 +1114,7 @@ def test_awkward_vector_vector_int32(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - assert awkward.to_list(tree["vector_vector_int32"].array(library="ak")) == [ + assert awkward._v2.to_list(tree["vector_vector_int32"].array(library="ak")) == [ [[1]], [[1], [1, 2]], [[1], [1, 2], [1, 2, 3]], @@ -792,7 +1128,9 @@ def test_awkward_vector_vector_string(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - assert awkward.to_list(tree["vector_vector_string"].array(library="ak")) == [ + assert awkward._v2.to_list( + tree["vector_vector_string"].array(library="ak") + ) == [ [["one"]], [["one"], ["one", "two"]], [["one"], ["one", "two"], ["one", "two", "three"]], @@ -817,15 +1155,15 @@ def test_awkward_map_int32_int16(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - keys, values = awkward.unzip(tree["map_int32_int16"].array(library="ak")) - assert awkward.to_list(keys) == [ + keys, values = awkward._v2.unzip(tree["map_int32_int16"].array(library="ak")) + assert awkward._v2.to_list(keys) == [ [1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [1, 2, 3, 4, 5], ] - assert awkward.to_list(values) == [ + assert awkward._v2.to_list(values) == [ [1], [1, 2], [1, 2, 3], @@ -839,15 +1177,17 @@ def test_awkward_map_int32_vector_int16(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - keys, values = awkward.unzip(tree["map_int32_vector_int16"].array(library="ak")) - assert awkward.to_list(keys) == [ + keys, values = awkward._v2.unzip( + tree["map_int32_vector_int16"].array(library="ak") + ) + assert awkward._v2.to_list(keys) == [ [1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [1, 2, 3, 4, 5], ] - assert awkward.to_list(values) == [ + assert awkward._v2.to_list(values) == [ [[1]], [[1], [1, 2]], [[1], [1, 2], [1, 2, 3]], @@ -861,17 +1201,17 @@ def test_awkward_map_int32_vector_string(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - keys, values = awkward.unzip( + keys, values = awkward._v2.unzip( tree["map_int32_vector_string"].array(library="ak") ) - assert awkward.to_list(keys) == [ + assert awkward._v2.to_list(keys) == [ [1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [1, 2, 3, 4, 5], ] - assert awkward.to_list(values) == [ + assert awkward._v2.to_list(values) == [ [["one"]], [["one"], ["one", "two"]], [["one"], ["one", "two"], ["one", "two", "three"]], @@ -896,15 +1236,15 @@ def test_awkward_map_string_int16(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - keys, values = awkward.unzip(tree["map_string_int16"].array(library="ak")) - assert awkward.to_list(keys) == [ + keys, values = awkward._v2.unzip(tree["map_string_int16"].array(library="ak")) + assert awkward._v2.to_list(keys) == [ ["one"], ["one", "two"], ["one", "three", "two"], ["four", "one", "three", "two"], ["five", "four", "one", "three", "two"], ] - assert awkward.to_list(values) == [ + assert awkward._v2.to_list(values) == [ [1], [1, 2], [1, 3, 2], @@ -918,17 +1258,17 @@ def test_awkward_map_string_vector_string(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - keys, values = awkward.unzip( + keys, values = awkward._v2.unzip( tree["map_string_vector_string"].array(library="ak") ) - assert awkward.to_list(keys) == [ + assert awkward._v2.to_list(keys) == [ ["one"], ["one", "two"], ["one", "three", "two"], ["four", "one", "three", "two"], ["five", "four", "one", "three", "two"], ] - assert awkward.to_list(values) == [ + assert awkward._v2.to_list(values) == [ [["one"]], [["one"], ["one", "two"]], [["one"], ["one", "two", "three"], ["one", "two"]], @@ -953,17 +1293,17 @@ def test_awkward_map_int32_vector_vector_int16(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - keys, values = awkward.unzip( + keys, values = awkward._v2.unzip( tree["map_int32_vector_vector_int16"].array(library="ak") ) - assert awkward.to_list(keys) == [ + assert awkward._v2.to_list(keys) == [ [1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [1, 2, 3, 4, 5], ] - assert awkward.to_list(values) == [ + assert awkward._v2.to_list(values) == [ [[[1]]], [[[1]], [[1], [1, 2]]], [[[1]], [[1], [1, 2]], [[1], [1, 2], [1, 2, 3]]], @@ -988,15 +1328,15 @@ def test_awkward_map_string_string(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - keys, values = awkward.unzip(tree["map_string_string"].array(library="ak")) - assert awkward.to_list(keys) == [ + keys, values = awkward._v2.unzip(tree["map_string_string"].array(library="ak")) + assert awkward._v2.to_list(keys) == [ ["one"], ["one", "two"], ["one", "three", "two"], ["four", "one", "three", "two"], ["five", "four", "one", "three", "two"], ] - assert awkward.to_list(values) == [ + assert awkward._v2.to_list(values) == [ ["ONE"], ["ONE", "TWO"], ["ONE", "THREE", "TWO"], @@ -1010,15 +1350,15 @@ def test_awkward_map_string_tstring(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - keys, values = awkward.unzip(tree["map_string_tstring"].array(library="ak")) - assert awkward.to_list(keys) == [ + keys, values = awkward._v2.unzip(tree["map_string_tstring"].array(library="ak")) + assert awkward._v2.to_list(keys) == [ ["one"], ["one", "two"], ["one", "three", "two"], ["four", "one", "three", "two"], ["five", "four", "one", "three", "two"], ] - assert awkward.to_list(values) == [ + assert awkward._v2.to_list(values) == [ ["ONE"], ["ONE", "TWO"], ["ONE", "THREE", "TWO"], @@ -1038,13 +1378,10 @@ def test_awkward_map_int_struct(): ) result = branch.array(library="ak") assert ( - repr(awkward.type(result)) - == '1 * [var * (int64, struct[["charge", "mass", "name"], ' - '[int64, float64, string], parameters={"__record__": ' - '"BDSOutputROOTGeant4Data::ParticleInfo"}]), ' - 'parameters={"__array__": "sorted_map"}]' + str(awkward._v2.type(result)) + == '1 * [var * (int64, struct[{name: string, charge: int64, mass: float64}, parameters={"__record__": "BDSOutputROOTGeant4Data::ParticleInfo"}]), parameters={"__array__": "sorted_map"}]' ) - assert awkward.to_list(result[0, "0"]) == [ + assert awkward._v2.to_list(result[0, "0"]) == [ -1000020040, -1000020030, -1000010030, @@ -1076,7 +1413,7 @@ def test_awkward_map_int_struct(): 1000020030, 1000020040, ] - assert awkward.to_list(result[0, "1", "name"]) == [ + assert awkward._v2.to_list(result[0, "1", "name"]) == [ "anti_alpha", "anti_He3", "anti_triton", @@ -1108,7 +1445,7 @@ def test_awkward_map_int_struct(): "He3", "alpha", ] - assert awkward.to_list(result[0, "1", "charge"]) == [ + assert awkward._v2.to_list(result[0, "1", "charge"]) == [ -2, -2, -1, @@ -1140,7 +1477,7 @@ def test_awkward_map_int_struct(): 2, 2, ] - assert awkward.to_list(result[0, "1", "mass"]) == [ + assert awkward._v2.to_list(result[0, "1", "mass"]) == [ 3.727379, 2.808391, 2.808921, @@ -1180,54 +1517,54 @@ def test_awkward_nosplit_file(): "tree/evt" ] as branch: result = branch.array(library="ak", entry_stop=5) - assert awkward.to_list(result["Beg"]) == [ + assert awkward._v2.to_list(result["Beg"]) == [ "beg-000", "beg-001", "beg-002", "beg-003", "beg-004", ] - assert awkward.to_list(result["I16"]) == [0, 1, 2, 3, 4] - assert awkward.to_list(result["F32"]) == [0.0, 1.0, 2.0, 3.0, 4.0] - assert awkward.to_list(result["Str"]) == [ + assert awkward._v2.to_list(result["I16"]) == [0, 1, 2, 3, 4] + assert awkward._v2.to_list(result["F32"]) == [0.0, 1.0, 2.0, 3.0, 4.0] + assert awkward._v2.to_list(result["Str"]) == [ "evt-000", "evt-001", "evt-002", "evt-003", "evt-004", ] - assert awkward.to_list(result["P3", "Px"]) == [-1, 0, 1, 2, 3] - assert awkward.to_list(result["P3", "Py"]) == [0.0, 1.0, 2.0, 3.0, 4.0] - assert awkward.to_list(result["P3", "Pz"]) == [-1, 0, 1, 2, 3] - assert awkward.to_list(result["ArrayI32"]) == [ + assert awkward._v2.to_list(result["P3", "Px"]) == [-1, 0, 1, 2, 3] + assert awkward._v2.to_list(result["P3", "Py"]) == [0.0, 1.0, 2.0, 3.0, 4.0] + assert awkward._v2.to_list(result["P3", "Pz"]) == [-1, 0, 1, 2, 3] + assert awkward._v2.to_list(result["ArrayI32"]) == [ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [3, 3, 3, 3, 3, 3, 3, 3, 3, 3], [4, 4, 4, 4, 4, 4, 4, 4, 4, 4], ] - assert awkward.to_list(result["StdStr"]) == [ + assert awkward._v2.to_list(result["StdStr"]) == [ "std-000", "std-001", "std-002", "std-003", "std-004", ] - assert awkward.to_list(result["SliceI64"]) == [ + assert awkward._v2.to_list(result["SliceI64"]) == [ [], [1], [2, 2], [3, 3, 3], [4, 4, 4, 4], ] - assert awkward.to_list(result["StlVecStr"]) == [ + assert awkward._v2.to_list(result["StlVecStr"]) == [ [], ["vec-001"], ["vec-002", "vec-002"], ["vec-003", "vec-003", "vec-003"], ["vec-004", "vec-004", "vec-004", "vec-004"], ] - assert awkward.to_list(result["End"]) == [ + assert awkward._v2.to_list(result["End"]) == [ "end-000", "end-001", "end-002", @@ -1278,7 +1615,7 @@ def test_map_string_TVector3(): "Model/Model.scoringMeshTranslation" ] as branch: result = branch.array(library="ak") - assert awkward.to_list(result["0"]) == [ + assert awkward._v2.to_list(result["0"]) == [ [ "global_mesh", "mesh_foil1", @@ -1301,7 +1638,7 @@ def test_map_string_TVector3(): "mesh_t7", ] ] - assert awkward.to_list(result["1"]) == [ + assert awkward._v2.to_list(result["1"]) == [ [ {"fX": 0.0, "fY": 0.0, "fZ": 0.074}, {"fX": 0.0, "fY": 0.04, "fZ": 0.048509515}, @@ -1331,24 +1668,24 @@ def test_gohep_output_file(): with uproot.open(skhep_testdata.data_path("uproot-issue413.root"))[ "mytree" ] as tree: - assert awkward.to_list(tree["I32"].array()) == [0, 1, 2, 3, 4] - assert awkward.to_list(tree["F64"].array()) == [0.0, 1.0, 2.0, 3.0, 4.0] - assert awkward.to_list(tree["Str"].array()) == [ + assert awkward._v2.to_list(tree["I32"].array()) == [0, 1, 2, 3, 4] + assert awkward._v2.to_list(tree["F64"].array()) == [0.0, 1.0, 2.0, 3.0, 4.0] + assert list(tree["Str"].array()) == [ "evt-0", "evt-1", "evt-2", "evt-3", "evt-4", ] - assert awkward.to_list(tree["ArrF64"].array()) == [ + assert awkward._v2.to_list(tree["ArrF64"].array()) == [ [0.0, 1.0, 2.0, 3.0, 4.0], [1.0, 2.0, 3.0, 4.0, 5.0], [2.0, 3.0, 4.0, 5.0, 6.0], [3.0, 4.0, 5.0, 6.0, 7.0], [4.0, 5.0, 6.0, 7.0, 8.0], ] - assert awkward.to_list(tree["N"].array()) == [0, 1, 2, 3, 4] - assert awkward.to_list(tree["SliF64"].array()) == [ + assert awkward._v2.to_list(tree["N"].array()) == [0, 1, 2, 3, 4] + assert awkward._v2.to_list(tree["SliF64"].array()) == [ [], [1.0], [2.0, 3.0], diff --git a/tests/test_0044-concatenate-function.py b/tests/test_0044-concatenate-function.py index 811953aea..869b79a20 100644 --- a/tests/test_0044-concatenate-function.py +++ b/tests/test_0044-concatenate-function.py @@ -22,8 +22,8 @@ def test_concatenate_awkward(): "6.20.04", "*" ) arrays = uproot.concatenate({files: "sample"}, ["i8", "f8"], library="ak") - assert isinstance(arrays, awkward.Array) - assert set(awkward.fields(arrays)) == {"i8", "f8"} + assert isinstance(arrays, awkward._v2.Array) + assert set(awkward._v2.fields(arrays)) == {"i8", "f8"} assert len(arrays) == 420 diff --git a/tests/test_0126-turn-unknown-emptyarrays-into-known-types.py b/tests/test_0126-turn-unknown-emptyarrays-into-known-types.py index 2d4d85345..1d8cb9ae7 100644 --- a/tests/test_0126-turn-unknown-emptyarrays-into-known-types.py +++ b/tests/test_0126-turn-unknown-emptyarrays-into-known-types.py @@ -11,4 +11,4 @@ def test(): awkward = pytest.importorskip("awkward") with uproot.open(skhep_testdata.data_path("uproot-vectorVectorDouble.root")) as f: array = f["t/x"].array(entry_stop=2) - assert str(awkward.type(array)) == "2 * var * var * float64" + assert str(awkward._v2.type(array)) == "2 * var * var * float64" diff --git a/tests/test_0303-empty-jagged-array.py b/tests/test_0303-empty-jagged-array.py index 6e4278db5..1c5a48837 100644 --- a/tests/test_0303-empty-jagged-array.py +++ b/tests/test_0303-empty-jagged-array.py @@ -20,5 +20,5 @@ def test_awkward(): with uproot.open(skhep_testdata.data_path("uproot-HZZ.root")) as f: a = f["events/Muon_Px"].array(entry_start=1, entry_stop=1) - assert isinstance(a, awkward.Array) + assert isinstance(a, awkward._v2.Array) assert len(a) == 0 diff --git a/tests/test_0414-write-jagged-arrays.py b/tests/test_0414-write-jagged-arrays.py index 47633eaa3..29cf24053 100644 --- a/tests/test_0414-write-jagged-arrays.py +++ b/tests/test_0414-write-jagged-arrays.py @@ -21,10 +21,12 @@ def test_awkward_as_numpy(tmp_path): fout.mktree( "tree", { - "b1": awkward.types.from_datashape("int32"), - "b2": awkward.types.from_datashape("2 * float64"), - "b3": awkward.types.from_datashape("2 * 3 * float64"), - "b4": awkward.Array([1.1, 2.2, 3.3]).type, + "b1": awkward._v2.types.from_datashape("int32", highlevel=False), + "b2": awkward._v2.types.from_datashape("2 * float64", highlevel=False), + "b3": awkward._v2.types.from_datashape( + "2 * 3 * float64", highlevel=False + ), + "b4": awkward._v2.Array([1.1, 2.2, 3.3]).type, }, ) @@ -43,7 +45,9 @@ def test_awkward_record(tmp_path): "tree", { "b1": "int32", - "b2": awkward.types.from_datashape('{"x": float64, "y": 3 * float64}'), + "b2": awkward._v2.types.from_datashape( + '{"x": float64, "y": 3 * float64}', highlevel=False + ), }, ) @@ -58,7 +62,9 @@ def test_awkward_record_data(tmp_path): with uproot.recreate(newfile, compression=None) as fout: b1 = np.array([1, 2, 3], np.int32) - b2 = awkward.Array([{"x": 1.1, "y": 4}, {"x": 2.2, "y": 5}, {"x": 3.3, "y": 6}]) + b2 = awkward._v2.Array( + [{"x": 1.1, "y": 4}, {"x": 2.2, "y": 5}, {"x": 3.3, "y": 6}] + ) fout.mktree("tree", {"b1": b1.dtype, "b2": b2.type}) fout["tree"].extend({"b1": b1, "b2": b2}) @@ -152,8 +158,8 @@ def test_awkward_record_pandas(tmp_path): def test_top_level(tmp_path): newfile = os.path.join(tmp_path, "newfile.root") - df1 = awkward.Array({"x": [1, 2, 3], "y": [1.1, 2.2, 3.3]}) - df2 = awkward.Array({"x": [4, 5, 6], "y": [4.4, 5.5, 6.6]}) + df1 = awkward._v2.Array({"x": [1, 2, 3], "y": [1.1, 2.2, 3.3]}) + df2 = awkward._v2.Array({"x": [4, 5, 6], "y": [4.4, 5.5, 6.6]}) with uproot.recreate(newfile, compression=None) as fout: fout["tree"] = df1 @@ -186,7 +192,9 @@ def test_awkward_jagged_metadata(tmp_path): "tree", { "b1": "int64", - "b2": awkward.types.from_datashape("var * float64"), + "b2": awkward._v2.types.from_datashape( + "var * float64", highlevel=False + ), }, ) @@ -222,7 +230,9 @@ def test_awkward_jagged_record_metadata(tmp_path): "tree", { "b1": "int64", - "b2": awkward.types.from_datashape('var * {"x": float64, "y": int8}'), + "b2": awkward._v2.types.from_datashape( + 'var * {"x": float64, "y": int8}', highlevel=False + ), }, ) @@ -261,7 +271,7 @@ def test_awkward_jagged_data_1(tmp_path): with uproot.recreate(newfile, compression=None) as fout: b1 = np.array([1, 2, 3, 4, 5], np.int64) - b2 = awkward.Array( + b2 = awkward._v2.Array( [[0.0, 1.1, 2.2], [], [3.3, 4.4], [5.5], [6.6, 7.7, 8.8, 9.9]] ) fout.mktree("tree", {"b1": b1.dtype, "b2": b2.type}) @@ -299,7 +309,7 @@ def test_awkward_jagged_data_2(tmp_path): with uproot.recreate(newfile, compression=None) as fout: b1 = np.array([1, 2, 3, 4, 5], np.int64) - b2 = awkward.Array( + b2 = awkward._v2.Array( [[0.0, 1.1, 2.2], [], [3.3, 4.4], [5.5], [6.6, 7.7, 8.8, 9.9]] ) fout["tree"] = {"b1": b1, "b2": b2} @@ -342,7 +352,7 @@ def test_awkward_jagged_data_3(tmp_path): newfile = os.path.join(tmp_path, "newfile.root") with uproot.recreate(newfile, compression=None) as fout: - big = awkward.Array( + big = awkward._v2.Array( [[0.0, 1.1, 2.2], [], [3.3, 4.4], [5.5], [6.6, 7.7, 8.8, 9.9]] * 300 ) fout["tree"] = {"big": big} @@ -381,7 +391,7 @@ def test_awkward_jagged_record_1(tmp_path): newfile = os.path.join(tmp_path, "newfile.root") with uproot.recreate(newfile, compression=None) as fout: - array = awkward.Array( + array = awkward._v2.Array( [ [{"x": 1, "y": 1.1}, {"x": 2, "y": 2.2}, {"x": 3, "y": 3.3}], [], @@ -411,7 +421,7 @@ def test_awkward_jagged_record_2(tmp_path): newfile = os.path.join(tmp_path, "newfile.root") with uproot.recreate(newfile, compression=None) as fout: - fout["tree"] = awkward.Array( + fout["tree"] = awkward._v2.Array( [ [{"x": 1, "y": 1.1}, {"x": 2, "y": 2.2}, {"x": 3, "y": 3.3}], [], @@ -419,7 +429,7 @@ def test_awkward_jagged_record_2(tmp_path): ] ) fout["tree"].extend( - awkward.Array( + awkward._v2.Array( [ [{"x": 1, "y": 1.1}, {"x": 2, "y": 2.2}, {"x": 3, "y": 3.3}], [], diff --git a/tests/test_0416-writing-compressed-data.py b/tests/test_0416-writing-compressed-data.py index 74e55d104..e9005a895 100644 --- a/tests/test_0416-writing-compressed-data.py +++ b/tests/test_0416-writing-compressed-data.py @@ -266,8 +266,8 @@ def test_jaggedtree_ZLIB(tmp_path): newfile = os.path.join(tmp_path, "newfile.root") - branch1 = ak.Array([[1, 2, 3], [], [4, 5]] * 10) - branch2 = ak.Array([[1.1, 2.2, 3.3], [], [4.4, 5.5]] * 10) + branch1 = ak._v2.Array([[1, 2, 3], [], [4, 5]] * 10) + branch2 = ak._v2.Array([[1.1, 2.2, 3.3], [], [4.4, 5.5]] * 10) with uproot.recreate(newfile, compression=uproot.ZLIB(5)) as fout: fout["tree"] = {"branch1": branch1, "branch2": branch2} @@ -290,8 +290,8 @@ def test_jaggedtree_LZMA(tmp_path): newfile = os.path.join(tmp_path, "newfile.root") - branch1 = ak.Array([[1, 2, 3], [], [4, 5]] * 10) - branch2 = ak.Array([[1.1, 2.2, 3.3], [], [4.4, 5.5]] * 10) + branch1 = ak._v2.Array([[1, 2, 3], [], [4, 5]] * 10) + branch2 = ak._v2.Array([[1.1, 2.2, 3.3], [], [4.4, 5.5]] * 10) with uproot.recreate(newfile, compression=uproot.LZMA(5)) as fout: fout["tree"] = {"branch1": branch1, "branch2": branch2} @@ -314,8 +314,8 @@ def test_jaggedtree_LZ4(tmp_path): newfile = os.path.join(tmp_path, "newfile.root") - branch1 = ak.Array([[1, 2, 3], [], [4, 5]] * 10) - branch2 = ak.Array([[1.1, 2.2, 3.3], [], [4.4, 5.5]] * 10) + branch1 = ak._v2.Array([[1, 2, 3], [], [4, 5]] * 10) + branch2 = ak._v2.Array([[1.1, 2.2, 3.3], [], [4.4, 5.5]] * 10) with uproot.recreate(newfile, compression=uproot.LZ4(5)) as fout: fout["tree"] = {"branch1": branch1, "branch2": branch2} @@ -338,8 +338,8 @@ def test_jaggedtree_ZSTD(tmp_path): newfile = os.path.join(tmp_path, "newfile.root") - branch1 = ak.Array([[1, 2, 3], [], [4, 5]] * 10) - branch2 = ak.Array([[1.1, 2.2, 3.3], [], [4.4, 5.5]] * 10) + branch1 = ak._v2.Array([[1, 2, 3], [], [4, 5]] * 10) + branch2 = ak._v2.Array([[1.1, 2.2, 3.3], [], [4.4, 5.5]] * 10) with uproot.recreate(newfile, compression=uproot.ZSTD(5)) as fout: fout["tree"] = {"branch1": branch1, "branch2": branch2} diff --git a/tests/test_0439-check-awkward-before-numpy.py b/tests/test_0439-check-awkward-before-numpy.py index 4cdafce1e..5735cd764 100644 --- a/tests/test_0439-check-awkward-before-numpy.py +++ b/tests/test_0439-check-awkward-before-numpy.py @@ -14,7 +14,7 @@ def test(tmp_path): filename = os.path.join(str(tmp_path), "whatever.root") with uproot.recreate(filename) as file: - file["tree"] = {"branch": ak.Array([[1, 2, 3], [4, 5, 6]])} + file["tree"] = {"branch": ak._v2.Array([[1, 2, 3], [4, 5, 6]])} with uproot.open(filename) as file: assert isinstance(file["tree/branch"].interpretation, uproot.AsJagged) diff --git a/tests/test_0442-regular-TClonesArray.py b/tests/test_0442-regular-TClonesArray.py index 84bd240d0..6c0f361a4 100644 --- a/tests/test_0442-regular-TClonesArray.py +++ b/tests/test_0442-regular-TClonesArray.py @@ -31,7 +31,7 @@ def test_read_delphes_ak(delphes_tree): branch = delphes_tree["Jet/Jet.SoftDroppedP4[5]"] array = branch.array(library="ak") assert array[0, 0, 0].fE == 126.46277691787493 - assert awkward.all(awkward.num(array, axis=2) == 5) + assert awkward._v2.all(awkward._v2.num(array, axis=2) == 5) branch = delphes_tree["GenJet04/GenJet04.Constituents"] array = branch.array(library="ak") diff --git a/tests/test_610-awkward-form.py b/tests/test_610-awkward-form.py index 5e64fde6f..2385cbe73 100644 --- a/tests/test_610-awkward-form.py +++ b/tests/test_610-awkward-form.py @@ -17,7 +17,7 @@ def test_awkward_strings(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - assert awkward.to_list(tree["string"].array(library="ak")) == [ + assert awkward._v2.to_list(tree["string"].array(library="ak")) == [ "one", "two", "three", @@ -31,7 +31,7 @@ def test_awkward_tstring(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - assert awkward.to_list(tree["tstring"].array(library="ak")) == [ + assert awkward._v2.to_list(tree["tstring"].array(library="ak")) == [ "one", "two", "three", @@ -45,7 +45,7 @@ def test_awkward_vector_int32(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - assert awkward.to_list(tree["vector_int32"].array(library="ak")) == [ + assert awkward._v2.to_list(tree["vector_int32"].array(library="ak")) == [ [1], [1, 2], [1, 2, 3], @@ -59,7 +59,7 @@ def test_awkward_vector_string(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - assert awkward.to_list(tree["vector_string"].array(library="ak")) == [ + assert awkward._v2.to_list(tree["vector_string"].array(library="ak")) == [ ["one"], ["one", "two"], ["one", "two", "three"], @@ -75,7 +75,7 @@ def test_awkward_vector_string_forth(): ] as tree: temp_branch = tree["vector_string"] temp_branch.interpretation._forth = True - assert awkward.to_list(temp_branch.array(library="ak")) == [ + assert awkward._v2.to_list(temp_branch.array(library="ak")) == [ ["one"], ["one", "two"], ["one", "two", "three"], @@ -105,7 +105,7 @@ def test_awkward_vector_tstring(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - assert awkward.to_list(tree["vector_tstring"].array(library="ak")) == [ + assert awkward._v2.to_list(tree["vector_tstring"].array(library="ak")) == [ ["one"], ["one", "two"], ["one", "two", "three"], @@ -119,7 +119,7 @@ def test_awkward_vector_vector_int32(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - assert awkward.to_list(tree["vector_vector_int32"].array(library="ak")) == [ + assert awkward._v2.to_list(tree["vector_vector_int32"].array(library="ak")) == [ [[1]], [[1], [1, 2]], [[1], [1, 2], [1, 2, 3]], @@ -133,7 +133,9 @@ def test_awkward_vector_vector_string(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - assert awkward.to_list(tree["vector_vector_string"].array(library="ak")) == [ + assert awkward._v2.to_list( + tree["vector_vector_string"].array(library="ak") + ) == [ [["one"]], [["one"], ["one", "two"]], [["one"], ["one", "two"], ["one", "two", "three"]], @@ -158,7 +160,9 @@ def test_awkward_vector_vector_tstring(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - assert awkward.to_list(tree["vector_vector_tstring"].array(library="ak")) == [ + assert awkward._v2.to_list( + tree["vector_vector_tstring"].array(library="ak") + ) == [ [["one"]], [["one"], ["one", "two"]], [["one"], ["one", "two"], ["one", "two", "three"]], @@ -183,7 +187,7 @@ def test_awkward_set_int32(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - assert awkward.to_list(tree["set_int32"].array(library="ak")) == [ + assert awkward._v2.to_list(tree["set_int32"].array(library="ak")) == [ [1], [1, 2], [1, 2, 3], @@ -197,7 +201,7 @@ def test_awkward_vector_set_int32(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - assert awkward.to_list(tree["vector_set_int32"].array(library="ak")) == [ + assert awkward._v2.to_list(tree["vector_set_int32"].array(library="ak")) == [ [[1]], [[1], [1, 2]], [[1], [1, 2], [1, 2, 3]], @@ -211,7 +215,7 @@ def test_awkward_vector_set_string(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - assert awkward.to_list(tree["vector_set_string"].array(library="ak")) == [ + assert awkward._v2.to_list(tree["vector_set_string"].array(library="ak")) == [ [["one"]], [["one"], ["one", "two"]], [["one"], ["one", "two"], ["one", "three", "two"]], @@ -236,7 +240,7 @@ def test_awkward_set_string(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - assert awkward.to_list(tree["set_string"].array(library="ak")) == [ + assert awkward._v2.to_list(tree["set_string"].array(library="ak")) == [ ["one"], ["one", "two"], ["one", "three", "two"], @@ -250,15 +254,15 @@ def test_awkward_map_int32_int16(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - keys, values = awkward.unzip(tree["map_int32_int16"].array(library="ak")) - assert awkward.to_list(keys) == [ + keys, values = awkward._v2.unzip(tree["map_int32_int16"].array(library="ak")) + assert awkward._v2.to_list(keys) == [ [1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [1, 2, 3, 4, 5], ] - assert awkward.to_list(values) == [ + assert awkward._v2.to_list(values) == [ [1], [1, 2], [1, 2, 3], @@ -272,15 +276,17 @@ def test_awkward_map_int32_vector_int16(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - keys, values = awkward.unzip(tree["map_int32_vector_int16"].array(library="ak")) - assert awkward.to_list(keys) == [ + keys, values = awkward._v2.unzip( + tree["map_int32_vector_int16"].array(library="ak") + ) + assert awkward._v2.to_list(keys) == [ [1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [1, 2, 3, 4, 5], ] - assert awkward.to_list(values) == [ + assert awkward._v2.to_list(values) == [ [[1]], [[1], [1, 2]], [[1], [1, 2], [1, 2, 3]], @@ -294,17 +300,17 @@ def test_awkward_map_int32_vector_string(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - keys, values = awkward.unzip( + keys, values = awkward._v2.unzip( tree["map_int32_vector_string"].array(library="ak") ) - assert awkward.to_list(keys) == [ + assert awkward._v2.to_list(keys) == [ [1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [1, 2, 3, 4, 5], ] - assert awkward.to_list(values) == [ + assert awkward._v2.to_list(values) == [ [["one"]], [["one"], ["one", "two"]], [["one"], ["one", "two"], ["one", "two", "three"]], @@ -329,15 +335,17 @@ def test_awkward_map_int32_set_int16(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - keys, values = awkward.unzip(tree["map_int32_set_int16"].array(library="ak")) - assert awkward.to_list(keys) == [ + keys, values = awkward._v2.unzip( + tree["map_int32_set_int16"].array(library="ak") + ) + assert awkward._v2.to_list(keys) == [ [1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [1, 2, 3, 4, 5], ] - assert awkward.to_list(values) == [ + assert awkward._v2.to_list(values) == [ [[1]], [[1], [1, 2]], [[1], [1, 2], [1, 2, 3]], @@ -351,15 +359,17 @@ def test_awkward_map_int32_set_string(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - keys, values = awkward.unzip(tree["map_int32_set_string"].array(library="ak")) - assert awkward.to_list(keys) == [ + keys, values = awkward._v2.unzip( + tree["map_int32_set_string"].array(library="ak") + ) + assert awkward._v2.to_list(keys) == [ [1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [1, 2, 3, 4, 5], ] - assert awkward.to_list(values) == [ + assert awkward._v2.to_list(values) == [ [["one"]], [["one"], ["one", "two"]], [["one"], ["one", "two"], ["one", "three", "two"]], @@ -384,15 +394,15 @@ def test_awkward_map_string_int16(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - keys, values = awkward.unzip(tree["map_string_int16"].array(library="ak")) - assert awkward.to_list(keys) == [ + keys, values = awkward._v2.unzip(tree["map_string_int16"].array(library="ak")) + assert awkward._v2.to_list(keys) == [ ["one"], ["one", "two"], ["one", "three", "two"], ["four", "one", "three", "two"], ["five", "four", "one", "three", "two"], ] - assert awkward.to_list(values) == [ + assert awkward._v2.to_list(values) == [ [1], [1, 2], [1, 3, 2], @@ -406,17 +416,17 @@ def test_awkward_map_string_vector_int16(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - keys, values = awkward.unzip( + keys, values = awkward._v2.unzip( tree["map_string_vector_int16"].array(library="ak") ) - assert awkward.to_list(keys) == [ + assert awkward._v2.to_list(keys) == [ ["one"], ["one", "two"], ["one", "three", "two"], ["four", "one", "three", "two"], ["five", "four", "one", "three", "two"], ] - assert awkward.to_list(values) == [ + assert awkward._v2.to_list(values) == [ [[1]], [[1], [1, 2]], [[1], [1, 2, 3], [1, 2]], @@ -430,17 +440,17 @@ def test_awkward_map_string_vector_string(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - keys, values = awkward.unzip( + keys, values = awkward._v2.unzip( tree["map_string_vector_string"].array(library="ak") ) - assert awkward.to_list(keys) == [ + assert awkward._v2.to_list(keys) == [ ["one"], ["one", "two"], ["one", "three", "two"], ["four", "one", "three", "two"], ["five", "four", "one", "three", "two"], ] - assert awkward.to_list(values) == [ + assert awkward._v2.to_list(values) == [ [["one"]], [["one"], ["one", "two"]], [["one"], ["one", "two", "three"], ["one", "two"]], @@ -465,15 +475,17 @@ def test_awkward_map_string_set_int16(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - keys, values = awkward.unzip(tree["map_string_set_int16"].array(library="ak")) - assert awkward.to_list(keys) == [ + keys, values = awkward._v2.unzip( + tree["map_string_set_int16"].array(library="ak") + ) + assert awkward._v2.to_list(keys) == [ ["one"], ["one", "two"], ["one", "three", "two"], ["four", "one", "three", "two"], ["five", "four", "one", "three", "two"], ] - assert awkward.to_list(values) == [ + assert awkward._v2.to_list(values) == [ [[1]], [[1], [1, 2]], [[1], [1, 2, 3], [1, 2]], @@ -487,15 +499,17 @@ def test_awkward_map_string_set_string(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - keys, values = awkward.unzip(tree["map_string_set_string"].array(library="ak")) - assert awkward.to_list(keys) == [ + keys, values = awkward._v2.unzip( + tree["map_string_set_string"].array(library="ak") + ) + assert awkward._v2.to_list(keys) == [ ["one"], ["one", "two"], ["one", "three", "two"], ["four", "one", "three", "two"], ["five", "four", "one", "three", "two"], ] - assert awkward.to_list(values) == [ + assert awkward._v2.to_list(values) == [ [["one"]], [["one"], ["one", "two"]], [["one"], ["one", "three", "two"], ["one", "two"]], @@ -520,17 +534,17 @@ def test_awkward_map_int32_vector_vector_int16(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - keys, values = awkward.unzip( + keys, values = awkward._v2.unzip( tree["map_int32_vector_vector_int16"].array(library="ak") ) - assert awkward.to_list(keys) == [ + assert awkward._v2.to_list(keys) == [ [1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [1, 2, 3, 4, 5], ] - assert awkward.to_list(values) == [ + assert awkward._v2.to_list(values) == [ [[[1]]], [[[1]], [[1], [1, 2]]], [[[1]], [[1], [1, 2]], [[1], [1, 2], [1, 2, 3]]], @@ -555,15 +569,15 @@ def test_awkward_map_string_string(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - keys, values = awkward.unzip(tree["map_string_string"].array(library="ak")) - assert awkward.to_list(keys) == [ + keys, values = awkward._v2.unzip(tree["map_string_string"].array(library="ak")) + assert awkward._v2.to_list(keys) == [ ["one"], ["one", "two"], ["one", "three", "two"], ["four", "one", "three", "two"], ["five", "four", "one", "three", "two"], ] - assert awkward.to_list(values) == [ + assert awkward._v2.to_list(values) == [ ["ONE"], ["ONE", "TWO"], ["ONE", "THREE", "TWO"], @@ -577,15 +591,15 @@ def test_awkward_map_string_tstring(): with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - keys, values = awkward.unzip(tree["map_string_tstring"].array(library="ak")) - assert awkward.to_list(keys) == [ + keys, values = awkward._v2.unzip(tree["map_string_tstring"].array(library="ak")) + assert awkward._v2.to_list(keys) == [ ["one"], ["one", "two"], ["one", "three", "two"], ["four", "one", "three", "two"], ["five", "four", "one", "three", "two"], ] - assert awkward.to_list(values) == [ + assert awkward._v2.to_list(values) == [ ["ONE"], ["ONE", "TWO"], ["ONE", "THREE", "TWO"],