Skip to content

Conversation

@FBruzzesi
Copy link
Member

What type of PR is this? (check all applicable)

  • πŸ’Ύ Refactor
  • ✨ Feature
  • πŸ› Bug Fix
  • πŸ”§ Optimization
  • πŸ“ Documentation
  • βœ… Test
  • 🐳 Other

Related issues

Checklist

  • Code follows style guide (ruff)
  • Tests added
  • Documented the changes

If you have comments or can explain your changes, please do so below

@FBruzzesi FBruzzesi added fix high priority Your PR will be reviewed very quickly if you address this labels Oct 7, 2025
@dangotbanned
Copy link
Member

dangotbanned commented Oct 7, 2025

You're more than welcome to steal these test cases πŸ˜‰

I was pretty surprised at how short the test suite was for filter_test.py

Comment on lines -2927 to -2929
if (
len(predicates) == 1 and is_list_of(predicates[0], bool) and not constraints
): # pragma: no cover
Copy link
Member Author

@FBruzzesi FBruzzesi Oct 7, 2025

Choose a reason for hiding this comment

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

This was not covering full spectrum of possibilities

@FBruzzesi

This comment was marked as resolved.

@dangotbanned
Copy link
Member

dangotbanned commented Oct 7, 2025

  • if any(is_list_of(pred, bool) for pred in predicates):

  • tuple(plx._series.from_iterable(pred, context=plx).to_narwhals() if is_list_of(pred, bool) else pred for pred in predicates)

Move whatever is going on here into a new guard function like those in _utils.

Any time the logic starts getting hard to follow, TypeIs will save you πŸ˜‰

Edit: I don't recommend putting everything in one method like this, but the polars logic has a few tricks to draw from

https://github.com/pola-rs/polars/blob/faab1f8eeeb1ad1a60fbd6e433bfbc3239737422/py-polars/src/polars/lazyframe/frame.py#L4074-L4143

@dangotbanned
Copy link
Member

dangotbanned commented Oct 8, 2025

@FBruzzesi I just added more tests from upstream:

The last 2 would cover (df7acdd#r167422933)

dangotbanned added a commit that referenced this pull request Oct 8, 2025
Compared to (2ebca30)

Now supports the new semantics that will appear in #3183, following #3182
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

thanks both!

@dangotbanned
Copy link
Member

@MarcoGorelli just to clarify (#3183 (comment)) and feel free to ignore if it was clear already

I somehow managed to start a thread that isn't showing on the PR 😭

And the commit I linked (which has more tests) is from (#3173).

I'm just trying to avoid the same bug I fixed in (pola-rs/polars#16254) from being introduced here πŸ™‚

@FBruzzesi
Copy link
Member Author

@dangotbanned if you are happy with the state of this, let's merge :)

@dangotbanned dangotbanned self-requested a review October 9, 2025 12:07
@dangotbanned
Copy link
Member

@dangotbanned if you are happy with the state of this, let's merge :)

Will do one more once over for (#3183 (comment)), but we should be good to merge later πŸ‘

I've gotten a bit distracted by #3188, which we might need to fix upstream

Copy link
Member

@dangotbanned dangotbanned left a comment

Choose a reason for hiding this comment

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

Thanks @FBruzzesi, provided I've not broken an edge case on an old version in (#3183 (comment)) - looks ready to merge

applause narwhal

@FBruzzesi FBruzzesi merged commit ebb2a40 into main Oct 9, 2025
30 of 31 checks passed
@FBruzzesi FBruzzesi deleted the fix/dataframe-filter branch October 9, 2025 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix high priority Your PR will be reviewed very quickly if you address this

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: DataFrame.filter silently ignores **constraints when using list[bool]

4 participants