Commit fa61ed8
* 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 #3586
* style: fix ruff formatting and TRY300 in _check_scalar
---------
Co-authored-by: Cipher <cipher@openclaw.ai>
1 parent 1cb1cce commit fa61ed8
File tree
2 files changed
+22
-3
lines changed- src/zarr/core/dtype/npy
- tests/test_dtype/test_npy
2 files changed
+22
-3
lines changed| 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 | + | |
| 213 | + | |
204 | 214 | | |
205 | 215 | | |
206 | 216 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
69 | 72 | | |
70 | 73 | | |
71 | 74 | | |
| |||
113 | 116 | | |
114 | 117 | | |
115 | 118 | | |
116 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
117 | 123 | | |
118 | 124 | | |
119 | 125 | | |
| |||
160 | 166 | | |
161 | 167 | | |
162 | 168 | | |
163 | | - | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
164 | 173 | | |
165 | 174 | | |
166 | 175 | | |
| |||
0 commit comments