Skip to content

Commit

Permalink
changed arguments for awkward_form (→ main-v4) (#618)
Browse files Browse the repository at this point in the history
* changed arguments for awkward_form

* incorporated review suggestions

Co-authored-by: Aryan Roy <aryanroy5678@gmail.com>
  • Loading branch information
jpivarski and aryan26roy authored Jun 21, 2022
1 parent e60db1c commit badcaa5
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 7 deletions.
11 changes: 11 additions & 0 deletions src/uproot/interpretation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ def numpy_dtype(self):
"""
raise AssertionError

@staticmethod
def _make_context(context, index_format, header, tobject_header, breadcrumbs):
if context is None:
context = {}
context["index_format"] = "i64"
context["header"] = False
context["tobject_header"] = True
context["breadcrumbs"] = ()

return context

def awkward_form(self, file, context):
"""
Args:
Expand Down
13 changes: 12 additions & 1 deletion src/uproot/interpretation/grouped.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,18 @@ def typename(self):
)
)

def awkward_form(self, file, context):
def awkward_form(
self,
file,
context=None,
index_format="i64",
header=False,
tobject_header=True,
breadcrumbs=(),
):
context = self._make_context(
context, index_format, header, tobject_header, breadcrumbs
)
awkward = uproot.extras.awkward()
names = []
fields = []
Expand Down
39 changes: 36 additions & 3 deletions src/uproot/interpretation/numerical.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,18 @@ def inner_shape(self):
def numpy_dtype(self):
return self._to_dtype

def awkward_form(self, file, context):
def awkward_form(
self,
file,
context=None,
index_format="i64",
header=False,
tobject_header=True,
breadcrumbs=(),
):
context = self._make_context(
context, index_format, header, tobject_header, breadcrumbs
)
awkward = uproot.extras.awkward()
d, s = _dtype_shape(self._to_dtype)
out = uproot._util.awkward_form(d, file, context)
Expand Down Expand Up @@ -624,7 +635,18 @@ def to_dtype(self):
def typename(self):
return "Double32_t" + "".join("[" + str(dim) + "]" for dim in self._to_dims)

def awkward_form(self, file, context):
def awkward_form(
self,
file,
context=None,
index_format="i64",
header=False,
tobject_header=True,
breadcrumbs=(),
):
context = self._make_context(
context, index_format, header, tobject_header, breadcrumbs
)
awkward = uproot.extras.awkward()
out = awkward.forms.NumpyForm(
(),
Expand Down Expand Up @@ -683,7 +705,18 @@ def to_dtype(self):
def typename(self):
return "Float16_t" + "".join("[" + str(dim) + "]" for dim in self._to_dims)

def awkward_form(self, file, context):
def awkward_form(
self,
file,
context=None,
index_format="i64",
header=False,
tobject_header=True,
breadcrumbs=(),
):
context = self._make_context(
context, index_format, header, tobject_header, breadcrumbs
)
awkward = uproot.extras.awkward()
out = awkward.forms.NumpyForm(
(),
Expand Down
26 changes: 24 additions & 2 deletions src/uproot/interpretation/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,18 @@ def typename(self):
else:
return uproot.model.classname_decode(self._model.__name__)[0]

def awkward_form(self, file, context):
def awkward_form(
self,
file,
context=None,
index_format="i64",
header=False,
tobject_header=True,
breadcrumbs=(),
):
context = self._make_context(
context, index_format, header, tobject_header, breadcrumbs
)
if isinstance(self._model, type):
return self._model.awkward_form(self._branch.file, context)
else:
Expand Down Expand Up @@ -425,7 +436,18 @@ def __eq__(self, other):
def numpy_dtype(self):
return numpy.dtype(object)

def awkward_form(self, file, context):
def awkward_form(
self,
file,
context=None,
index_format="i64",
header=False,
tobject_header=True,
breadcrumbs=(),
):
context = self._make_context(
context, index_format, header, tobject_header, breadcrumbs
)
awkward = uproot.extras.awkward()
cname = uproot.model.classname_decode(self._model.__name__)[0]
form = _strided_awkward_form(awkward, cname, self._members, file, context)
Expand Down
13 changes: 12 additions & 1 deletion src/uproot/interpretation/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,18 @@ def typename(self):
def numpy_dtype(self):
return numpy.dtype(object)

def awkward_form(self, file, context):
def awkward_form(
self,
file,
context=None,
index_format="i64",
header=False,
tobject_header=True,
breadcrumbs=(),
):
context = self._make_context(
context, index_format, header, tobject_header, breadcrumbs
)
awkward = uproot.extras.awkward()
return awkward.forms.ListOffsetForm(
context["index_format"],
Expand Down

0 comments on commit badcaa5

Please sign in to comment.