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: added hasattr check to NanoAODEvents __repr__ #909

Merged
merged 20 commits into from
Oct 18, 2023
Merged
Changes from 1 commit
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
23 changes: 23 additions & 0 deletions tests/test_nanoevents.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,26 @@ def test_read_nanodata(suffix):

crossref(events)
crossref(events[ak.num(events.Jet) > 2])


def test_missing_eventIds_error():
path = os.path.abspath("tests/samples/missing_luminosityBlock.root")
with pytest.raises(
Exception,
match="There are missing event ID fields: ['luminosityBlock'] \n\n\
The event ID fields ['run', 'luminosityBlock', 'event'] are necessary to perform sub-run identification \
(e.g. for corrections and sub-dividing data during different detector conditions),\
to cross-validate MC and Data (i.e. matching events for comparison), and to generate event displays. \
It's advised to never drop these branches from the dataformat.\n\n\
This error can be demoted to a warning by setting the class level variable error_missing_event_ids to False.",
):
factory = NanoEventsFactory.from_root(path, schemaclass=NanoAODSchema)
factory.events()


def test_missing_eventIds_warning():
path = os.path.abspath("tests/samples/missing_luminosityBlock.root")
with pytest.raises(RuntimeWarning, match="Missing event_ids : ['luminosityBlock']"):
NanoAODSchema.error_missing_event_ids = False
Copy link
Contributor Author

@pviscone pviscone Oct 17, 2023

Choose a reason for hiding this comment

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

Is there a safer way to turn the error_missing_events_ids flag to False?
In this way, I think that it will disable it globally

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the intended pattern, it's fine!

factory = NanoEventsFactory.from_root(path, schemaclass=NanoAODSchema)
factory.events()