fix: remove row(s) equal-to/not-equal-to conditions were inverted - #263
Open
iabaako wants to merge 1 commit into
Open
fix: remove row(s) equal-to/not-equal-to conditions were inverted#263iabaako wants to merge 1 commit into
iabaako wants to merge 1 commit into
Conversation
|
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.



Pull Request Summary 🚀
What does this PR do? 📝
Fixes two logic bugs found while auditing every Prep step for inverted/incorrect condition handling:
RemoveRowsOperation._filter_by_equality— the "remove row(s)" action with conditionvalue is equal towas inverted: it kept only the matching rows instead of removing them, andvalue is not equal tohad the same problem in reverse (it kept only the non-matching rows). Both conditions now do what they say:equal toremoves the matches and keeps the rest;not equal toremoves the non-matches and keeps only the matches.AddNewColumnOperation'scountaggregation —pl.concat_list(cols).list.len()counted every source column regardless of nulls, socountalways just returned the number of selected columns instead of the number of non-null values in them (as documented: "count of non-null values from selected columns"). Now uses.list.drop_nulls().list.len().As a direct consequence, this also fixes #246: that issue reported that the Stata replication script generator (
replication/prep_script_generator.py) and the real in-app Polars engine disagreed onequal_to/not_equal_torow-removal direction, and assumed the replication script needed to change to match Polars. It was actually the reverse — the Stata generator was already correct, and Polars was the buggy side. Fixing_filter_by_equalityhere brings them back into agreement; verified directly that both sides now produce the same remaining rows forequal_toandnot_equal_toconditions on the same data.Closes #246
Why is this change needed? 🤔
Both were found by manually verifying every Prep operation's behavior against its labeled intent, prompted by a user noticing "remove row(s)" seemed to behave backwards for equality conditions. The bug was long-standing and had been silently encoded as "expected" in the existing test suite (test comments literally said
# equal_to keeps matching rows (removes non-matching)), so it was never caught by CI. Cross-checked against the replication script generator (replication/prep_script_generator.py), which independently implements the same condition and was already correct (keep if col != valuefor "equal to") — confirming the direction of this fix and that exported Stata scripts were never affected, only the live in-app engine.How was this implemented? 🛠️
_filter_by_equality: build the "is in value list" filter once, then apply it (not negated) fornot_equal_toand negated forequal_to— the opposite of what the code did before.countaggregation: added.list.drop_nulls()before.list.len()so nulls aren't counted.counttest that asserted the always-equals-column-count behavior, to assert the correct outcome. Added new tests: equality with an explicit remaining-values assertion (not just row counts, so this can't silently regress again), and acounttest with an all-missing row (expects0).How to test or reproduce? 🧪
uv run python -m pytest— full suite passes.just lint-py/just fmt-python/ pre-commit — clean.keep ifcommand now agree on the same remaining rows forequal_to/not_equal_toexamples.Screenshots (if applicable) 📷
N/A — bug fix, no new visual components.
Checklist ✅
Note on stacking
This PR is stacked on
fix/261-datetime-parse-crash(#262), itself stacked onfix/253-standardize-reapply-error-handling(#260) — both still open drafts. Base is set tofix/261-datetime-parse-crashso review only shows this PR's incremental diff. Retarget tomainonce the earlier PRs in the stack merge.🤖 Generated with Claude Code