Commit 3683bb3
authored
fix(dtypes,strings): never abort cleaning on an unusual object cell (#453)
Three crashes on the default fd.clean path, all from code that assumed
every cell in an object column is scalar text:
* non-UTF-8 bytes: dtype inference cast a sample with astype("string"),
and pandas 2 decodes bytes when casting to StringDtype, so a BLOB read
out of a database raised UnicodeDecodeError. pandas 1.5 returned the
frame with the cell untouched. Text inspection now falls back to a view
that keeps str cells and ignores the rest, so both versions leave the
cell alone.
* pd.NA beside a list or dict: the strip and case passes counted repairs
with stripped.ne(s), whose flex comparison hands object columns to
NumPy, which calls bool() on pd.NA != pd.NA and raises "boolean value
of NA is ambiguous". Only str cells can change, so the comparison is
restricted to those positions.
* booleans mixed with pd.NaT: BooleanArray accepts only None/NaN as a
missing value, so [None, None, NaT, False] raised TypeError("Need to
pass bool-like values") -- but only when the frame had another column,
because that changed inference order. Missing cells are normalized to
NaN before the boolean cast.
Closes #447
Closes #448
Closes #4511 parent e5bac8a commit 3683bb3
4 files changed
Lines changed: 142 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 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 | + | |
126 | 161 | | |
127 | 162 | | |
128 | 163 | | |
| |||
132 | 167 | | |
133 | 168 | | |
134 | 169 | | |
135 | | - | |
| 170 | + | |
136 | 171 | | |
137 | 172 | | |
138 | 173 | | |
139 | 174 | | |
140 | 175 | | |
141 | | - | |
| 176 | + | |
142 | 177 | | |
143 | 178 | | |
144 | 179 | | |
| |||
165 | 200 | | |
166 | 201 | | |
167 | 202 | | |
168 | | - | |
| 203 | + | |
169 | 204 | | |
170 | 205 | | |
171 | 206 | | |
| |||
209 | 244 | | |
210 | 245 | | |
211 | 246 | | |
212 | | - | |
| 247 | + | |
213 | 248 | | |
214 | 249 | | |
215 | 250 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 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 | + | |
31 | 62 | | |
32 | 63 | | |
33 | 64 | | |
34 | 65 | | |
35 | | - | |
36 | 66 | | |
37 | 67 | | |
38 | 68 | | |
39 | 69 | | |
40 | 70 | | |
41 | 71 | | |
42 | 72 | | |
43 | | - | |
| 73 | + | |
44 | 74 | | |
45 | 75 | | |
46 | 76 | | |
47 | | - | |
48 | 77 | | |
49 | 78 | | |
50 | 79 | | |
| |||
66 | 95 | | |
67 | 96 | | |
68 | 97 | | |
69 | | - | |
70 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
71 | 101 | | |
72 | 102 | | |
73 | 103 | | |
| |||
83 | 113 | | |
84 | 114 | | |
85 | 115 | | |
86 | | - | |
87 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
88 | 120 | | |
89 | 121 | | |
90 | 122 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
482 | 482 | | |
483 | 483 | | |
484 | 484 | | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
0 commit comments