Skip to content

[release] Accommodate multiple filters with same attribute#57577

Merged
aslonnie merged 1 commit intomasterfrom
khluu/filters_logic
Oct 9, 2025
Merged

[release] Accommodate multiple filters with same attribute#57577
aslonnie merged 1 commit intomasterfrom
khluu/filters_logic

Conversation

@khluu
Copy link
Copy Markdown
Contributor

@khluu khluu commented Oct 8, 2025

and allow a test to match with one of filters in the same attribute instead of saying it's mismatch if any of the filter fail

p
Signed-off-by: kevin <kevin@anyscale.com>
@khluu khluu requested a review from a team as a code owner October 8, 2025 23:10
@khluu
Copy link
Copy Markdown
Contributor Author

khluu commented Oct 8, 2025

test run: https://buildkite.com/ray-project/release/builds/62511 with 2 prefix filters

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a great feature to allow more flexible test filtering. The implementation is solid, and I've just added a few suggestions to improve code conciseness, performance, and test coverage. Overall, great work!

Comment on lines +44 to +62
for attr, values in test_filters.items():
# Check if at least one value matches for this attribute (OR logic)
attr_matched = False
for value in values:
# Only prefix filter doesn't use regex
if attr == "prefix":
if test.get_name().startswith(value):
attr_matched = True
break
else: # Match filters using regex
attr_value = _unflattened_lookup(test, attr) or ""
if re.match(value, attr_value):
attr_matched = True
break

# If none of the values matched for this attribute, skip this test
if not attr_matched:
attr_mismatch = True
break
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The current implementation for filtering tests can be made more concise and performant.

The nested loop structure can be simplified using Python's built-in any() function, which improves readability. Additionally, _unflattened_lookup is called on every iteration of the inner loop, which is inefficient. By using any(), we can ensure it's called just once per attribute.

Here's a suggested refactoring:

            for attr, values in test_filters.items():
                if attr == "prefix":
                    attr_matched = any(test.get_name().startswith(value) for value in values)
                else:
                    attr_value = _unflattened_lookup(test, attr) or ""
                    attr_matched = any(re.match(value, attr_value) for value in values)

                if not attr_matched:
                    attr_mismatch = True
                    break

Comment on lines +80 to +83
# Support multiple values for the same attribute (OR logic)
if parts[0] not in test_filters:
test_filters[parts[0]] = []
test_filters[parts[0]].append(parts[1])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This logic for appending to a list in a dictionary can be simplified using dict.setdefault(). This is more idiomatic and concise.

        # Support multiple values for the same attribute (OR logic)
        test_filters.setdefault(parts[0], []).append(parts[1])

Comment on lines +588 to +597
# Test OR logic with AND across attributes
filtered = self._filter_names(
tests,
frequency=Frequency.NIGHTLY,
test_filters={
"name": ["^test_1$", "^test_3$"],
"team": ["team_1", "team_2"],
},
)
self.assertSequenceEqual(filtered, [("test_1", False), ("test_3", False)])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The new test case for 'OR logic with AND across attributes' is good, but it could be stronger. Both test_1 and test_3 match the team filter ["team_1", "team_2"], so it doesn't fully test the AND part of the logic where one of the OR conditions for name is met but the AND condition for team is not.

I suggest adding another test case to cover this scenario, for example by filtering for a team that only one of the tests belongs to. This will ensure the filtering logic is robust.

        # Test OR logic with AND across attributes
        filtered = self._filter_names(
            tests,
            frequency=Frequency.NIGHTLY,
            test_filters={
                "name": ["^test_1$", "^test_3$"],
                "team": ["team_1", "team_2"],
            },
        )
        self.assertSequenceEqual(filtered, [("test_1", False), ("test_3", False)])

        # Test OR logic with AND across attributes (negative case)
        filtered = self._filter_names(
            tests,
            frequency=Frequency.NIGHTLY,
            test_filters={"name": ["^test_1$", "^test_3$"], "team": ["team_1"]},
        )
        self.assertSequenceEqual(filtered, [("test_1", False)])

@khluu khluu requested a review from aslonnie October 8, 2025 23:16
test_collection: List[Test],
frequency: Frequency,
test_filters: Optional[Dict[str, str]] = None,
test_filters: Optional[Dict[str, list]] = None,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

is this list a List[str]?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this does not seem to be fixed..

@aslonnie aslonnie added the go add ONLY when ready to merge, run all tests label Oct 8, 2025
@ray-gardener ray-gardener bot added core Issues that should be addressed in Ray Core devprod release-test release test labels Oct 9, 2025
@aslonnie aslonnie merged commit a36880f into master Oct 9, 2025
5 of 6 checks passed
@aslonnie aslonnie deleted the khluu/filters_logic branch October 9, 2025 07:17
simonsays1980 pushed a commit to simonsays1980/ray that referenced this pull request Oct 9, 2025
…ct#57577)

and allow a test to match with one of filters in the same attribute
instead of saying it's mismatch if any of the filter fail

Signed-off-by: kevin <kevin@anyscale.com>
liulehui pushed a commit to liulehui/ray that referenced this pull request Oct 9, 2025
…ct#57577)

and allow a test to match with one of filters in the same attribute
instead of saying it's mismatch if any of the filter fail

Signed-off-by: kevin <kevin@anyscale.com>
joshkodi pushed a commit to joshkodi/ray that referenced this pull request Oct 13, 2025
…ct#57577)

and allow a test to match with one of filters in the same attribute
instead of saying it's mismatch if any of the filter fail

Signed-off-by: kevin <kevin@anyscale.com>
Signed-off-by: Josh Kodi <joshkodi@gmail.com>
ArturNiederfahrenhorst pushed a commit to ArturNiederfahrenhorst/ray that referenced this pull request Oct 13, 2025
…ct#57577)

and allow a test to match with one of filters in the same attribute
instead of saying it's mismatch if any of the filter fail

Signed-off-by: kevin <kevin@anyscale.com>
harshit-anyscale pushed a commit that referenced this pull request Oct 15, 2025
and allow a test to match with one of filters in the same attribute
instead of saying it's mismatch if any of the filter fail

Signed-off-by: kevin <kevin@anyscale.com>
justinyeh1995 pushed a commit to justinyeh1995/ray that referenced this pull request Oct 20, 2025
…ct#57577)

and allow a test to match with one of filters in the same attribute
instead of saying it's mismatch if any of the filter fail

Signed-off-by: kevin <kevin@anyscale.com>
xinyuangui2 pushed a commit to xinyuangui2/ray that referenced this pull request Oct 22, 2025
…ct#57577)

and allow a test to match with one of filters in the same attribute
instead of saying it's mismatch if any of the filter fail

Signed-off-by: kevin <kevin@anyscale.com>
Signed-off-by: xgui <xgui@anyscale.com>
elliot-barn pushed a commit that referenced this pull request Oct 23, 2025
and allow a test to match with one of filters in the same attribute
instead of saying it's mismatch if any of the filter fail

Signed-off-by: kevin <kevin@anyscale.com>
Signed-off-by: elliot-barn <elliot.barnwell@anyscale.com>
landscapepainter pushed a commit to landscapepainter/ray that referenced this pull request Nov 17, 2025
…ct#57577)

and allow a test to match with one of filters in the same attribute
instead of saying it's mismatch if any of the filter fail

Signed-off-by: kevin <kevin@anyscale.com>
Aydin-ab pushed a commit to Aydin-ab/ray-aydin that referenced this pull request Nov 19, 2025
…ct#57577)

and allow a test to match with one of filters in the same attribute
instead of saying it's mismatch if any of the filter fail

Signed-off-by: kevin <kevin@anyscale.com>
Signed-off-by: Aydin Abiar <aydin@anyscale.com>
Future-Outlier pushed a commit to Future-Outlier/ray that referenced this pull request Dec 7, 2025
…ct#57577)

and allow a test to match with one of filters in the same attribute
instead of saying it's mismatch if any of the filter fail

Signed-off-by: kevin <kevin@anyscale.com>
Signed-off-by: Future-Outlier <eric901201@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Issues that should be addressed in Ray Core devprod go add ONLY when ready to merge, run all tests release-test release test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants