Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ def visit_Compare(self, node: ast.Compare) -> ds.Expression:

op = node.ops[0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove test_expression_evaluator.py from semgrep.yml, and also add the pytest.main to the bottom of test_expression_evaluator.py?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if isinstance(op, ast.In):
return left_expr.is_in(comparators[0])
return pc.is_in(left_expr, comparators[0])
elif isinstance(op, ast.NotIn):
return ~left_expr.is_in(comparators[0])
return ~pc.is_in(left_expr, comparators[0])
elif isinstance(op, ast.Eq):
return left_expr == comparators[0]
elif isinstance(op, ast.NotEq):
Expand Down Expand Up @@ -233,7 +233,7 @@ def visit_Call(self, node: ast.Call) -> ds.Expression:
nan_is_null=nan_is_null
),
"is_valid": lambda arg: arg.is_valid(),
"is_in": lambda arg1, arg2: arg1.is_in(arg2),
"is_in": lambda arg1, arg2: pc.is_in(arg1, arg2),
}

if func_name in function_map:
Expand Down
16 changes: 16 additions & 0 deletions python/ray/data/tests/test_expression_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import pyarrow as pa
import pyarrow.parquet as pq
import pytest
from pkg_resources import parse_version

from ray.data._internal.planner.plan_expression.expression_evaluator import (
ExpressionEvaluator,
)
from ray.data.tests.conftest import get_pyarrow_version


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -292,6 +294,10 @@ def sample_data(tmpdir_factory):
]


@pytest.mark.skipif(
get_pyarrow_version() < parse_version("20.0.0"),
reason="test_filter requires PyArrow >= 20.0.0",
)
@pytest.mark.parametrize("expression, expected_data", expressions_and_expected_data)
def test_filter(sample_data, expression, expected_data):
"""Test the filter functionality of the ExpressionEvaluator."""
Expand Down Expand Up @@ -329,6 +335,10 @@ def test_filter_equal_negative_number():
assert result_df == expected


@pytest.mark.skipif(
get_pyarrow_version() < parse_version("20.0.0"),
reason="test_filter requires PyArrow >= 20.0.0",
)
def test_filter_bad_expression(sample_data):
with pytest.raises(ValueError, match="Invalid syntax in the expression"):
ExpressionEvaluator.get_filters(expression="bad filter")
Expand All @@ -338,3 +348,9 @@ def test_filter_bad_expression(sample_data):
sample_data_path, _ = sample_data
with pytest.raises(pa.ArrowInvalid):
pq.read_table(sample_data_path, filters=filters)


if __name__ == "__main__":
import sys

sys.exit(pytest.main(["-v", __file__]))
1 change: 0 additions & 1 deletion semgrep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ rules:
# FIXME: These tests weren't run in CI, and now they're failing.
- "python/ray/data/tests/test_arrow_serialization.py"
- "python/ray/data/tests/test_block.py"
- "python/ray/data/tests/test_expression_evaluator.py"
- "python/ray/data/tests/test_hash_shuffle.py"
- "python/ray/data/tests/test_operator_fusion.py"
languages:
Expand Down