diff --git a/python/cudf/cudf/core/dataframe.py b/python/cudf/cudf/core/dataframe.py index 8c8f0119b3f..2371dfc51cd 100644 --- a/python/cudf/cudf/core/dataframe.py +++ b/python/cudf/cudf/core/dataframe.py @@ -7139,13 +7139,14 @@ def eval(self, expr: str, inplace: bool = False, **kwargs): "Keyword arguments other than `inplace` are not supported" ) - # Have to use a regex match to avoid capturing "==" - includes_assignment = re.search("[^=]=[^=]", expr) is not None + # Have to use a regex match to avoid capturing ==, >=, or <= + equals_sign_regex = "[^=><]=[^=]" + includes_assignment = re.search(equals_sign_regex, expr) is not None # Check if there were multiple statements. Filter out empty lines. statements = tuple(filter(None, expr.strip().split("\n"))) if len(statements) > 1 and any( - re.search("[^=]=[^=]", st) is None for st in statements + re.search(equals_sign_regex, st) is None for st in statements ): raise ValueError( "Multi-line expressions are only valid if all expressions " diff --git a/python/cudf/cudf/tests/test_dataframe.py b/python/cudf/cudf/tests/test_dataframe.py index b3c8468c119..918bd995ed1 100644 --- a/python/cudf/cudf/tests/test_dataframe.py +++ b/python/cudf/cudf/tests/test_dataframe.py @@ -9794,6 +9794,7 @@ def df_eval(request): ("a / b", float), ("a * b", int), ("a > b", int), + ("a >= b", int), ("a > b > c", int), ("a > b < c", int), ("a & b", int), @@ -9835,7 +9836,7 @@ def test_dataframe_eval(df_eval, expr, dtype): assert_eq(expect, got, check_names=False) # Test inplace - if re.search("[^=]=[^=]", expr) is not None: + if re.search("[^=><]=[^=]", expr) is not None: pdf_eval = df_eval.to_pandas() pdf_eval.eval(expr, inplace=True) df_eval.eval(expr, inplace=True)