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

Make event cutting for EventsPi work also when at least one variable name is conta… #792

Merged
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
10 changes: 7 additions & 3 deletions pisa/core/events_pi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from collections.abc import Mapping, Iterable, Sequence
from collections import OrderedDict
import copy
import re

import numpy as np

Expand Down Expand Up @@ -551,8 +552,11 @@ def apply_cut(self, keep_criteria):
# Create the cut expression, and get the resulting mask
crit_str = keep_criteria
for variable_name in variables:
crit_str = crit_str.replace(
variable_name, 'self["%s"]["%s"]' % (key, variable_name)
# using word boundary \b to replace whole words only
crit_str = re.sub(
r'\b{}\b'.format(variable_name),
'self["%s"]["%s"]' % (key, variable_name),
crit_str
)
mask = eval(crit_str) # pylint: disable=eval-used

Expand Down Expand Up @@ -754,4 +758,4 @@ def main():


if __name__ == "__main__":
main()
main()
Loading