Skip to content

fix(nwis): forward get_record state, restore major-filter validation, clarify format#310

Draft
thodson-usgs wants to merge 1 commit into
DOI-USGS:mainfrom
thodson-usgs:fix/nwis-record-filter-handling
Draft

fix(nwis): forward get_record state, restore major-filter validation, clarify format#310
thodson-usgs wants to merge 1 commit into
DOI-USGS:mainfrom
thodson-usgs:fix/nwis-record-filter-handling

Conversation

@thodson-usgs
Copy link
Copy Markdown
Collaborator

Summary

Three fixes in the (deprecated) nwis module, all surfaced by the package review.

1. get_record(state=…) was a dead parameter — accepted and documented, but never forwarded. get_record(state="OH", service="site") silently ignored it and, with no sites, failed with a confusing "Bad Request." Now forwarded as the NWIS stateCd major filter. (wide_format / datetime_index likewise remain accepted-but-unimplemented — unchanged here; wiring or removing them is a separate call for a deprecated module.)

2. The "must specify a major filter" validation was defeated. get_dv / get_iv / get_discharge_peaks did kwargs["sites"] = kwargs.pop("sites", sites), which always set the key (to None when absent), so query_waterservices' any(key in kwargs …) check always passed. get_dv() / get_iv() with no filter therefore gave a confusing "Bad Request" instead of the intended TypeError. Inject the filter only when actually provided.

3. format= collided. get_dv / get_iv passed format="json" explicitly and splatted **kwargs, so get_dv(sites=…, format="rdb") raised TypeError: got multiple values for 'format'. These getters parse JSON, so they now reject a non-json format with a clear ValueError.

Verification (no network)

get_dv()                       -> TypeError: ...must specify a major filter   (was: Bad Request)
get_dv(sites=…, format="rdb")  -> ValueError: get_dv returns JSON ...         (was: multiple values for 'format')
get_record(state="OH", ...)    -> forwards stateCd="OH"                       (was: silently dropped)

Added three regression tests; the full nwis suite (47) passes; ruff clean.

🤖 Generated with Claude Code

…arify format

Three fixes in the (deprecated) nwis module:

1. get_record's `state` argument was accepted and documented but never
   forwarded, so get_record(state="OH", service="site") silently ignored it and
   failed with a confusing "Bad Request". Forward it as the NWIS `stateCd`
   major filter.

2. get_dv / get_iv / get_discharge_peaks did
   `kwargs["sites"] = kwargs.pop("sites", sites)`, always injecting the key (as
   None when absent) and so defeating query_waterservices' "must specify a
   major filter" check — get_dv()/get_iv() with no filter raised a confusing
   "Bad Request" instead of the intended TypeError. Inject only when provided.

3. get_dv / get_iv passed `format="json"` explicitly alongside **kwargs, so
   get_dv(sites=..., format="rdb") raised "got multiple values for 'format'".
   These getters only parse JSON, so reject a non-json format with a clear
   ValueError.

`wide_format` / `datetime_index` on get_record remain accepted but
unimplemented (unchanged here); wiring or removing them is a separate decision
for this deprecated module.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@thodson-usgs thodson-usgs force-pushed the fix/nwis-record-filter-handling branch from 541c652 to 0ccd573 Compare May 31, 2026 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant