fix(semantic): use the validator phone and email patterns in type inference - #424
Merged
Merged
Conversation
…erence Semantic type inference kept its own email and phone regexes after #318 fixed the ones in fieldcheck. Punycode TLD emails and long international phone formats were inferred as non-email/non-phone, and numbers with more than 15 digits could be inferred as phone. Reuse fieldcheck's _EMAIL_RE and _is_phone so inference accepts exactly what validate_fields accepts. fieldcheck is unchanged.
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.
Summary
Semantic type inference (
fd.infer_roles→semantic_type) now detects emails and phones with the same patterns asfd.validate_fields. This is a follow-up to #318.Root cause
#318 fixed the email and phone validators in
fieldcheck.py: punycode TLDs (xn--…), longer formatted international numbers, and a 7–15 digit count per E.164.semantic/semantic_types.pykept its own copies of the old regexes. As a result, inference returnedunknownforuser@example.xn--p1aiand+49 (0) 30 - 1234 - 0001. It also had no 15-digit cap, so 16–17 digit numbers could be inferred asphone.Behaviour change
semantic_typesnow imports_EMAIL_REand_is_phonefromfieldcheck, so both accept exactly the same values. There is no import cycle, andfieldcheckis unchanged.email.phone.phone.role="id"/role="text"short-circuitsphone, as before and as invalidate_fields.Default-output changes
Only the
semantic_type,semantic_type_confidenceandsemantic_type_evidencecolumns fromfd.infer_rolescan change, along with the same columns inExplainReport.rolesfromexplain_clean. Columns whose role isidortextare resolved before any content detector, so they are unaffected. For columns whose role is categorical or numeric:category_code(0.4) →email(0.9).+44 (0) 20 7946 0958or+49-(0)-30-1234-0001:category_code(0.4) →phone(0.9).phone(0.9) →category_code(0.4)phone(0.9) →unknown(0.2)No cleaning, semantic repair or masking changes. The default cleaning path does not use
semantic_type, andlearn_memoryand the compliance adapter read onlyrole,missing_pctanddomain_sensitivefrominfer_roles.Tests
New tests in
tests/test_semantic_types.pyfail onmainand pass with this change:role="id"infer_rolesend to end on categorical columnsvalidate_fieldsaccepts the valueVerification
ruff check .: passedmypy src/freshdata: no issuespytest -m "not online and not large": Python 3.12 / pandas 2.3.3: 6289 passed, 14 skipped; Python 3.9 / pandas 1.5.3: 6260 passed, 18 skippedpytest tests/truthbench: 290 passed