fix(nwis): forward get_record state, restore major-filter validation, clarify format#310
Draft
thodson-usgs wants to merge 1 commit into
Draft
Conversation
…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>
541c652 to
0ccd573
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three fixes in the (deprecated)
nwismodule, 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 nosites, failed with a confusing "Bad Request." Now forwarded as the NWISstateCdmajor filter. (wide_format/datetime_indexlikewise 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_peaksdidkwargs["sites"] = kwargs.pop("sites", sites), which always set the key (toNonewhen absent), soquery_waterservices'any(key in kwargs …)check always passed.get_dv()/get_iv()with no filter therefore gave a confusing "Bad Request" instead of the intendedTypeError. Inject the filter only when actually provided.3.
format=collided.get_dv/get_ivpassedformat="json"explicitly and splatted**kwargs, soget_dv(sites=…, format="rdb")raisedTypeError: got multiple values for 'format'. These getters parse JSON, so they now reject a non-jsonformatwith a clearValueError.Verification (no network)
Added three regression tests; the full
nwissuite (47) passes;ruffclean.🤖 Generated with Claude Code