Commit 714d3cd
feat(waterdata): Auto-chunk OGC requests over the URL byte limit
The OGC `waterdata` getters previously failed with HTTP 414 when the
request URL exceeded the server's ~8 KB byte limit. A common pattern
— pulling a long site list from `get_monitoring_locations` and
feeding it into `get_daily` — was the main offender:
sites_df, _ = get_monitoring_locations(state_name="Ohio")
df, md = get_daily(
monitoring_location_id=sites_df["monitoring_location_id"].tolist(),
parameter_code="00060",
time="P7D",
)
Introduces a joint chunker that models every multi-value list
parameter and the cql-text `filter` (split on top-level `OR`) as a
chunkable axis. Greedy halving splits the biggest chunk across all
axes until each sub-request URL fits; the chunker fans out under the
hood and returns one combined DataFrame. Callers see no API change.
Mid-stream 429 / 5xx surface as `ChunkInterrupted` subclasses
(`QuotaExhausted` / `ServiceInterrupted`) carrying the partial result
plus a `.call` resumable handle — `exc.call.resume()` continues only
the still-pending sub-requests. Pre-emptive `RequestExceedsQuota`
catches plans that won't fit the remaining rate-limit window;
`API_USGS_LIMIT=0` bypasses the check.
Behavior changes for paginated / chunked calls:
- `BaseMetadata.url` still reflects the user's original query.
- `BaseMetadata.header` now carries the LAST page's headers so
`x-ratelimit-remaining` is current (was: first page's).
- `BaseMetadata.query_time` is now cumulative wall-clock across pages
(was: first page's elapsed).
Mirrors R `dataRetrieval`'s
[#870](DOI-USGS/dataRetrieval#870),
generalized from one filter axis to N joint axes.
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>1 parent 4a65fb1 commit 714d3cd
9 files changed
Lines changed: 3374 additions & 676 deletions
File tree
- dataretrieval/waterdata
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | 4 | | |
3 | 5 | | |
| |||
36 | 38 | | |
37 | 39 | | |
38 | 40 | | |
39 | | - | |
| 41 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
| 116 | + | |
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| |||
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
233 | 248 | | |
234 | 249 | | |
235 | 250 | | |
| |||
259 | 274 | | |
260 | 275 | | |
261 | 276 | | |
262 | | - | |
| 277 | + | |
263 | 278 | | |
264 | 279 | | |
265 | 280 | | |
| |||
320 | 335 | | |
321 | 336 | | |
322 | 337 | | |
323 | | - | |
| 338 | + | |
324 | 339 | | |
325 | 340 | | |
326 | 341 | | |
| |||
1254 | 1269 | | |
1255 | 1270 | | |
1256 | 1271 | | |
1257 | | - | |
| 1272 | + | |
1258 | 1273 | | |
1259 | 1274 | | |
1260 | 1275 | | |
| |||
1451 | 1466 | | |
1452 | 1467 | | |
1453 | 1468 | | |
1454 | | - | |
| 1469 | + | |
1455 | 1470 | | |
1456 | 1471 | | |
1457 | 1472 | | |
| |||
1633 | 1648 | | |
1634 | 1649 | | |
1635 | 1650 | | |
1636 | | - | |
| 1651 | + | |
1637 | 1652 | | |
1638 | 1653 | | |
1639 | 1654 | | |
| |||
0 commit comments