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

Fix approach to detecting assignment for gte/lte operators #13285

Merged
merged 3 commits into from
May 11, 2023
Merged
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
3 changes: 2 additions & 1 deletion python/cudf/cudf/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand Down