Fix inverted non-numeric >= and <= fallbacks in resolve_filter - #393
Open
nikhilsi wants to merge 1 commit into
Open
Fix inverted non-numeric >= and <= fallbacks in resolve_filter#393nikhilsi wants to merge 1 commit into
nikhilsi wants to merge 1 commit into
Conversation
The non-numeric branch of >= returned le() and <= returned ge(), so any string or date ordered comparison silently selected the opposite rows. Adds truth-table tests for string dates including > and < as already-correct controls.
Contributor
|
Thank you for your contribution. I affirm that this contributor has signed the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
In
openavmkit/filters.pyat 7952236, the non-numeric fallback branches for>=and<=are swapped:>=on a non-numeric column returnsdf[field].le(value)<=on a non-numeric column returnsdf[field].ge(value)The
>and<branches just above (lines 183, 188) are correct, whichpoints to a copy-paste swap. The effect is that any settings filter that
compares a string column with
>=or<=(the common case being sale-datethresholds like
[">=", "sale_date", "str:2020-01-01"]) silently selectsthe exact complement of the intended rows.
The change
Swap them back:
>=maps to.ge(value)and<=maps to.le(value).Two lines. Numeric columns are unaffected (they take the
is_column_of_typebranch, which was already correct).What changes downstream
Filters on non-numeric columns using
>=or<=start selecting the rowsthey say they select. Any settings file that unknowingly relied on the
inverted behavior will flip, but that behavior contradicted both the
operator names and the numeric branch, so the previous results were wrong.
Verification
A test is included (
tests/test_filters.py). It builds a frame with astring
sale_datecolumn spanning three dates and asserts that[">=", "sale_date", "str:<middle date>"]selects the middle and laterrows and
["<=", ...]selects the middle and earlier rows. Both assertionsfail at 7952236 and pass with this change.
Fixes #376.