Commit f2a2503
fix(nwis): forward get_record state, fix major-filter validation, reject bad format
Several fixes in the deprecated `nwis` module, surfaced by the package review.
- `get_record(state=…)` was accepted and documented but never forwarded. It now
reaches the request as the NWIS `stateCd` major filter; previously it was
silently dropped, producing a confusing "Bad Request" when used without
`sites`.
- The "must specify a major filter" validation was defeated: callers injected a
filter key unconditionally (e.g. `kwargs["sites"] = kwargs.pop("sites", sites)`
set the key to None when absent), so the membership-based guards in
`query_waterservices`/`query_waterdata` always passed and a filterless request
went out as a confusing "Bad Request" instead of the intended TypeError. The
guards now require a filter that is present *and* non-None, rejecting an unset
filter at the chokepoint — no per-getter pre-filtering needed. (`utils.query`
already strips None-valued params, so this is purely a validation change.)
- `get_dv`/`get_iv`/`get_discharge_peaks`/`get_stats` each parse a fixed response
body but passed `format=` explicitly alongside `**kwargs`, so e.g.
`get_dv(sites=…, format="rdb")` raised "multiple values for 'format'". A
caller-supplied non-native `format` is now rejected with a clear ValueError via
the shared `_reject_unexpected_format` helper (json for dv/iv, rdb for
peaks/stats).
- `get_ratings` is per-site; called without one it issued a request returning an
unhelpful error page. It now fails fast with a clear TypeError (also covering
`get_record(service="ratings")`).
Adds regression tests for each. Full nwis suite passes; ruff and mypy --strict
clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent ecf2833 commit f2a2503
2 files changed
Lines changed: 154 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
129 | 144 | | |
130 | 145 | | |
131 | 146 | | |
| |||
277 | 292 | | |
278 | 293 | | |
279 | 294 | | |
| 295 | + | |
280 | 296 | | |
281 | 297 | | |
282 | 298 | | |
| |||
355 | 371 | | |
356 | 372 | | |
357 | 373 | | |
| 374 | + | |
| 375 | + | |
358 | 376 | | |
359 | 377 | | |
360 | 378 | | |
| |||
392 | 410 | | |
393 | 411 | | |
394 | 412 | | |
395 | | - | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
396 | 416 | | |
397 | 417 | | |
398 | | - | |
399 | | - | |
| 418 | + | |
| 419 | + | |
400 | 420 | | |
401 | 421 | | |
402 | 422 | | |
| |||
453 | 473 | | |
454 | 474 | | |
455 | 475 | | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
456 | 482 | | |
457 | | - | |
| 483 | + | |
| 484 | + | |
458 | 485 | | |
459 | 486 | | |
460 | 487 | | |
| |||
537 | 564 | | |
538 | 565 | | |
539 | 566 | | |
| 567 | + | |
540 | 568 | | |
541 | 569 | | |
542 | 570 | | |
| |||
724 | 752 | | |
725 | 753 | | |
726 | 754 | | |
| 755 | + | |
727 | 756 | | |
728 | 757 | | |
729 | 758 | | |
| |||
788 | 817 | | |
789 | 818 | | |
790 | 819 | | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
791 | 825 | | |
792 | 826 | | |
793 | 827 | | |
| |||
956 | 990 | | |
957 | 991 | | |
958 | 992 | | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
959 | 999 | | |
960 | 1000 | | |
961 | 1001 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
| 24 | + | |
22 | 25 | | |
23 | 26 | | |
24 | 27 | | |
| |||
120 | 123 | | |
121 | 124 | | |
122 | 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 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
123 | 233 | | |
124 | 234 | | |
125 | 235 | | |
| |||
0 commit comments