Skip to content

Commit

Permalink
make event cutting work also when at least one variable name is conta…
Browse files Browse the repository at this point in the history
…ined within another
  • Loading branch information
thehrh committed Aug 3, 2024
1 parent 631ad75 commit 33ccbe9
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 33ccbe9

Please sign in to comment.