Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed arguments for awkward_form (→ main-v4) #618

Merged
merged 2 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if here you meant:

         context["index_format"] = index_format
etc...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're right. One moment...

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