fix(masking): validate unmatched columns and support snake_case matching - #406
Merged
Merged
Conversation
…ict CLI --mask - MaskingRule.strict defaults to False: listed columns that match nothing are recorded in MaskReport.unmatched_columns, so shared rule sets keep working in fd.anonymize and clean_enterprise. The CLI --mask rules are strict. - A listed column masks every frame column with the same name or snake_case form, instead of only the last one that normalises to it. - The duplicate-label pre-check in anonymize never raises for absent columns. - Split the three E501 test lines; add tests, docstrings and a changelog entry.
…lean_enterprise Move the #251 changelog entry to Changed, since it changes matching, adds the unmatched_columns report key and makes CLI --mask exit 1.
Contributor
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
FreshData benchmark report —
|
| fixture | n_rows | n_cols | p50 s | p95 s | peak MB | repair % | false-repair % | preserve % | trust | monotonic | export % |
|---|
Authored-code reduction (Metric 6)
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.
Supersedes #269. This branch carries the original commit by @Voyagerroc-Code (opened as PR #269 by @Voyagerroc-Lab), with authorship preserved, plus review changes on top. Thank you for the fix!
Summary
A masking rule whose
columnsmatched no column did nothing. For example,freshdata clean --mask Email:hashon a frame with anemailcolumn wrote the raw values and exited 0. Column resolution now matches by snake_case name, records names that match nothing, and can raise for them.Behaviour changes
MaskingRulecolumn name masks every column with the same name or the same snake_case form:"First Name"masksfirst_name, and"email"masks bothemailandEmail.MaskReport.unmatched_columns, which also appears inMaskReport.to_dict().MaskingRule.strict, defaultFalse. Withstrict=True, ormask_dataframe(..., strict=True), unmatched names raiseValueErrornaming them. Themask_dataframeargument overrides the rule's setting.freshdata clean --mask COLUMN:STRATEGYrules are strict, so the command exits 1 with a one-line error whenCOLUMNmatches no column.anonymizenever raises for absent columns.Commits
fix(masking): validate unmatched columns and support snake_case matching, by @Voyagerroc-Code (the original from fix(masking): validate unmatched columns and support snake_case matching #269).fix(masking): non-strict by default, mask every snake_case match, strict CLI --mask. Review changes:anonymizetest(masking): cover polars snake_case matching and strict rules in clean_enterprise. Adds tests and moves the changelog entry to Changed.Tests
mask_dataframe:strict=argument overrides the rulefd.anonymize: a shared rule with an absent column; a strict rule alongside duplicated labels elsewhere.clean_enterprise:ValueErrornaming itresult.mask_report.unmatched_columns--mask non_existent:hashexits 1 with a one-line error--mask Email:hashmasksemailVerification
Run on
maincbd1967 plus these commits:ruff check .: all checks passedmypy src/freshdata: no issuespytest -m "not online and not large", Python 3.12: 5603 passed, 13 skippedpytest -m "not online and not large", Python 3.9 / pandas 1.5: 5599 passed, 17 skippedCloses #251