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

fix: show untyped fields and make keys compatible with coffea #1376

Merged
merged 5 commits into from
Feb 7, 2025
Merged
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
39 changes: 24 additions & 15 deletions src/uproot/models/RNTuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,31 +195,30 @@ def _keys(self):
keys = []
field_records = self.field_records
for i, fr in enumerate(field_records):
if fr.parent_field_id == i and fr.type_name != "":
if fr.parent_field_id == i and not fr.field_name.startswith("_"):
keys.append(fr.field_name)
return keys

# TODO: this is still missing a lot of functionality
def keys(
self,
*,
filter_name=None,
filter_typename=None,
filter_field=None,
recursive=False,
full_paths=True,
# TODO: some arguments might be missing when compared with TTree. Solve when blocker is present in dask/coffea.
**_, # For compatibility reasons we just ignore other kwargs
):
if filter_name:
# Return keys from the filter_name list:
return [key for key in self._keys if key in filter_name]
else:
return self._keys
filter_name = uproot._util.regularize_filter(filter_name)
return [key for key in self._keys if filter_name(key)]

@property
def _key_indices(self):
indices = []
field_records = self.field_records
for i, fr in enumerate(field_records):
if fr.parent_field_id == i and fr.type_name != "":
if fr.parent_field_id == i and not fr.field_name.startswith("_"):
indices.append(i)
return indices

Expand All @@ -228,7 +227,7 @@ def _key_to_index(self):
d = {}
field_records = self.field_records
for i, fr in enumerate(field_records):
if fr.parent_field_id == i and fr.type_name != "":
if fr.parent_field_id == i and not fr.field_name.startswith("_"):
d[fr.field_name] = i
return d

Expand Down Expand Up @@ -684,7 +683,7 @@ def to_akform(self):
for i in range(len(field_records)):
if i not in seen:
ff = self.field_form(i, seen)
if field_records[i].type_name != "":
if not field_records[i].field_name.startswith("_"):
recordlist.append(ff)

form = ak.forms.RecordForm(recordlist, topnames, form_key="toplevel")
Expand Down Expand Up @@ -1249,15 +1248,25 @@ def _keys(self):
continue
if (
fr.parent_field_id == self.index
and fr.type_name != ""
and not fr.field_name.startswith("_")
and not fr.field_name.startswith(":_")
):
keys.append(fr.field_name)
return keys

def keys(self):
return self._keys
# TODO: this is still missing a lot of functionality
def keys(
self,
*,
filter_name=None,
filter_typename=None,
filter_field=None,
recursive=False,
full_paths=True,
**_, # For compatibility reasons we just ignore other kwargs
):
filter_name = uproot._util.regularize_filter(filter_name)
return [key for key in self._keys if filter_name(key)]

@property
def name(self):
Expand All @@ -1282,7 +1291,7 @@ def _key_indices(self):
indices = []
field_records = self.ntuple.field_records
for i, fr in enumerate(field_records):
if fr.parent_field_id == self.index and fr.type_name != "":
if fr.parent_field_id == self.index and not fr.field_name.startswith("_"):
indices.append(i)
return indices

Expand All @@ -1291,7 +1300,7 @@ def _key_to_index(self):
d = {}
field_records = self.ntuple.field_records
for i, fr in enumerate(field_records):
if fr.parent_field_id == self.index and fr.type_name != "":
if fr.parent_field_id == self.index and not fr.field_name.startswith("_"):
d[fr.field_name] = i
return d

Expand Down
Loading