Commit 5cc034d
Cipher
fix: BaseFloat._check_scalar rejects invalid string values (#3586)
BaseFloat._check_scalar returned True for all strings because the
FloatLike type union includes str. This allowed invalid strings like
'not valid' to pass the check and then raise a confusing ValueError
in _cast_scalar_unchecked instead of the expected TypeError.
Fix _check_scalar to validate string inputs by attempting conversion:
- Valid float strings (e.g. 'NaN', 'inf', '-inf', '1.5') return True
- Invalid strings (e.g. 'not valid') return False, causing cast_scalar
to raise TypeError as expected
Add test cases for invalid string inputs to invalid_scalar_params.
Fixes #35861 parent 1cb1cce commit 5cc034d
2 files changed
Lines changed: 12 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
204 | 213 | | |
205 | 214 | | |
206 | 215 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
| 116 | + | |
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
163 | | - | |
| 163 | + | |
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| |||
0 commit comments