Commit c4ffef4
fix(textclean): an unknown field type must not lose its protection silently (#474)
config_for_field matched the declared semantic_type exactly -- case-sensitive
and untrimmed -- and returned the caller's base config on no match. The failure
mode ran backwards for a safety-oriented library: a recognised structural type
was protected from lossy transformation, while an unrecognised one received it
in full. Declaring more about a column bought less protection.
With TextCleanConfig(case="lower", remove_punctuation=True):
identifier / ticker / email 'Sekr3t-P@ss!!!' preserved
password / api_key / secret 'sekr3tpss'
Ticker / TICKER / 'ticker ' 'sekr3tpss'
identifer (typo) / e-mail 'sekr3tpss'
So a near-miss in the type name quietly downgraded a protected column, and a
credential-bearing column named by a type outside the vocabulary was mangled.
The lookup is now normalised (casefold + strip), so Ticker, TICKER and
"ticker " resolve to ticker. A type that is still unrecognised warns when a
lossy option is active, which is the courtesy fieldcheck already extends for an
unknown semantic_type; the message names the column's type, the specific
options that will run, and the known types.
Deliberately limited:
- Every lossy option is opt-in, so a default fd.clean never reached this path
and is unchanged.
- The default config has no lossy option, so no warning fires on the common
path -- verified by a test, since the suite treats freshdata warnings as
errors.
- semantic_type=None is not a misspelling and stays silent.
- Behaviour for an unrecognised type is otherwise unchanged. Whether it should
instead default to the structural (lossless) config is a real behaviour
change and is left for a decision rather than taken here.
Worth noting textclean's 28 known types are a superset of both
fieldcheck._KNOWN_SEMANTIC_TYPES (23) and SEMANTIC_TYPES (17), so this was
lookup strictness rather than a third taxonomy.
21 new tests; full suite 6643 passed / 0 failed, coverage 93.90%.
Co-authored-by: Kevin Costner <kiran.gangalakunta@gmail.com>1 parent 6f53878 commit c4ffef4
3 files changed
Lines changed: 217 additions & 34 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
10 | 22 | | |
11 | 23 | | |
12 | 24 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
54 | 66 | | |
55 | 67 | | |
56 | 68 | | |
| |||
121 | 133 | | |
122 | 134 | | |
123 | 135 | | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
133 | 170 | | |
134 | 171 | | |
135 | 172 | | |
136 | 173 | | |
137 | 174 | | |
138 | 175 | | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
139 | 194 | | |
140 | 195 | | |
141 | 196 | | |
| |||
149 | 204 | | |
150 | 205 | | |
151 | 206 | | |
152 | | - | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
153 | 213 | | |
154 | | - | |
155 | | - | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
156 | 221 | | |
157 | | - | |
| 222 | + | |
158 | 223 | | |
159 | | - | |
160 | | - | |
161 | | - | |
| 224 | + | |
| 225 | + | |
162 | 226 | | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
163 | 239 | | |
164 | 240 | | |
165 | 241 | | |
| |||
211 | 287 | | |
212 | 288 | | |
213 | 289 | | |
214 | | - | |
215 | | - | |
216 | | - | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
217 | 293 | | |
218 | 294 | | |
219 | 295 | | |
| |||
225 | 301 | | |
226 | 302 | | |
227 | 303 | | |
228 | | - | |
229 | | - | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
230 | 308 | | |
231 | 309 | | |
232 | 310 | | |
| |||
327 | 405 | | |
328 | 406 | | |
329 | 407 | | |
330 | | - | |
331 | | - | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
332 | 411 | | |
333 | 412 | | |
334 | 413 | | |
| |||
344 | 423 | | |
345 | 424 | | |
346 | 425 | | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
352 | 435 | | |
353 | 436 | | |
354 | 437 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
0 commit comments