diff --git a/pisa/core/events_pi.py b/pisa/core/events_pi.py index a14b0da40..b2550b18e 100644 --- a/pisa/core/events_pi.py +++ b/pisa/core/events_pi.py @@ -6,6 +6,7 @@ from collections.abc import Mapping, Iterable, Sequence from collections import OrderedDict import copy +import re import numpy as np @@ -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 @@ -754,4 +758,4 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main()