fix: drop events whose category is null instead of emitting bare-prefix codes - #10
Merged
Conversation
…ix codes get_entry built codes with concat_str(..., ignore_nulls=True), so a null code column collapsed to just the prefix (e.g. a null lab_category became the code 'LAB-RES'), which then survived drop_nulls and entered the vocabulary as a meaningless token. Wrap the concat in when(col(code).is_not_null()) so such rows become null and are removed by the existing drop_nulls; ignore_nulls is kept for the optional prefix. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
Author
|
This does seem like an issue but I'm not 100% sure the proposed fix is the right way to handle either |
Contributor
|
I definitey agree that we should have a principled way to handle this |
Contributor
|
This seems like a reasonable solution |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an event-collation bug where rows with a null category could still produce a non-null code (the bare prefix) due to concat_str(..., ignore_nulls=True), causing those rows to incorrectly survive drop_nulls and enter the vocabulary.
Changes:
- Make
codeevaluate tonullwhen the sourcecode/category column is null by guarding the concatenation withpl.when(pl.col(code).is_not_null()).then(...). - Preserve the existing behavior that
prefixis optional by retainingignore_nulls=Trueinside the concatenation.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
How to recreate
Why it's a bug
get_entrybuilds codes withconcat_str(..., ignore_nulls=True)so a null category collapses to just the prefix (e.g.LAB-RES) instead of null. The subsequentdrop_nulls(subset=["code"])therefore keeps these rows, and null categories — common in real CLIF*_categorycolumns — enter the vocabulary as a meaningless prefix-only token with whatever numeric value the row carried.How it was fixed
Wrap the concat in
pl.when(pl.col(code).is_not_null()).then(...)so rows with a null category become null codes and are removed by the existingdrop_nulls.ignore_nulls=Trueis retained inside, sinceprefixis legitimately optional.🤖 Generated with Claude Code