Skip to content

Commit

Permalink
Merge pull request #792 from thehrh/events_pi_apply_cut_variable_name…
Browse files Browse the repository at this point in the history
…s_fix

Make event cutting for `EventsPi` work also when at least one variable name is conta…
  • Loading branch information
JanWeldert authored Aug 5, 2024
2 parents 631ad75 + 33ccbe9 commit a66bae1
Showing 1 changed file with 7 additions and 3 deletions.
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()

0 comments on commit a66bae1

Please sign in to comment.