Fix get_results: preserve user-supplied WQX3.0 dataProfile#250
Fix get_results: preserve user-supplied WQX3.0 dataProfile#250thodson-usgs merged 4 commits intoDOI-USGS:mainfrom
Conversation
The validation block silently overwrote any user-supplied WQX3.0 dataProfile because the `else` clause attached to the *outer* `if "dataProfile" in kwargs and ... not in result_profiles_wqx3` and fired whenever that compound condition was False — including the case where the user passed a *valid* profile like "narrow" or "basicPhysChem". The documented example `dataProfile="narrow"` therefore did not actually request the narrow profile. Restructure the WQX3.0 branch so the default (`fullPhysChem`) is only applied when the user did *not* set `dataProfile` at all. Also raise `ValueError` rather than `TypeError` for invalid profile values (these are bad values, not bad types) and call the constructor with a single formatted message — the previous code passed two separate strings, producing a tuple-args exception. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Selects valid_profiles + url + kind once per branch, then validates and applies the WQX3.0 default in straight-line code. Replaces the 3-deep nesting in the wqx3 branch and the duplicated `dataProfile in kwargs and ... not in profiles` check across both branches. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The simplify pass added `TypeError(msg, msg)` -> `ValueError(single_msg)` fixes to `get_results`'s two `dataProfile` validators. PR DOI-USGS#250 ("Fix get_results: preserve user-supplied WQX3.0 dataProfile") restructures the same code more thoroughly and addresses the same exception-shape bug as a side effect, so this PR should not duplicate that work. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes dataretrieval.wqp.get_results() so WQX3.0 requests preserve a caller-provided dataProfile instead of always falling back to the default profile. It narrows the change to the WQP results path and adds a regression test around the request URL that gets sent.
Changes:
- Refactors
get_results()profile selection/validation so WQX3.0 only defaults tofullPhysChemwhendataProfilewas omitted. - Changes invalid
dataProfilehandling to raiseValueErrorwith a single formatted message. - Adds a regression test confirming
dataProfile="narrow"is preserved in the outbound WQX3.0 request.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
dataretrieval/wqp.py |
Refactors get_results() legacy/WQX3.0 profile handling and exception construction. |
tests/wqp_test.py |
Adds a regression test covering preservation of a valid user-supplied WQX3.0 dataProfile. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| f"Valid options are {result_profiles_legacy}.", | ||
| ) | ||
|
|
||
| if legacy: |
| raise ValueError( | ||
| f"dataProfile {profile!r} is not a valid {kind} profile. " | ||
| f"Valid options are {valid_profiles}." |
Per copilot review on PR DOI-USGS#250. Other helpers (what_sites, etc.) use 'legacy is True' to gate URL selection, so a non-bool value like 1 or 'false' would otherwise route differently in get_results vs the rest of the module. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
@copilot-pull-request-reviewer thanks for the review. Accepted: Declining: regression test for invalid |
Summary
The validation block silently overwrote any user-supplied WQX3.0
dataProfilebecause theelseclause attached to the outerif "dataProfile" in kwargs and ... not in result_profiles_wqx3and fired whenever that compound condition was False — including the case where the user passed a valid profile like"narrow"or"basicPhysChem". The documented exampledataProfile="narrow"therefore did not actually request the narrow profile.This PR restructures the WQX3.0 branch so the default (
fullPhysChem) is only applied when the user did not setdataProfileat all.It also raises
ValueErrorrather thanTypeErrorfor invalid profile values (these are bad values, not bad types) and calls the constructor with a single formatted message — the previous code passed two separate strings, producing a tuple-args exception that printed as('msg1', 'msg2').Test plan
tests/wqp_test.py—test_get_results_wqx3_preserves_user_dataProfile— confirms a valid user-supplied WQX3.0 profile ("narrow") is preserved end-to-end through the request URL. The accompanyingTypeError->ValueErrorshape fix is documented by the diff and not separately unit-tested.tests/wqp_test.py(12 tests) pass.API_USGS_PATset).Related PRs
Other open PRs in this bug-review series that touch
dataretrieval/wqp.py(different functions, no functional conflicts):WQP_Metadata.site_infoproperty binding.get_results'sTypeError->ValueErrorshape; that overlap was reverted so this PR fully owns theget_resultsrewrite.