Polish wqp.py: silence prints, fix exception shape, fix typos#256
Draft
thodson-usgs wants to merge 3 commits intoDOI-USGS:mainfrom
Draft
Polish wqp.py: silence prints, fix exception shape, fix typos#256thodson-usgs wants to merge 3 commits intoDOI-USGS:mainfrom
thodson-usgs wants to merge 3 commits intoDOI-USGS:mainfrom
Conversation
- Replace 6 stdout `print(...)` calls in `what_organizations`, `what_projects`, `what_detection_limits`, `what_habitat_metrics`, `what_project_weights`, and `what_activity_metrics` with `warnings.warn(..., UserWarning)` so callers can capture or filter the message instead of getting unconditional stdout pollution. - Convert `wqp_url`/`wqx3_url` from `TypeError(msg, msg)` (which raises with `args=(msg1, msg2)` and is the wrong type for an unrecognized argument) to `ValueError(single_msg)`. - Add `low_memory=False` to `what_activity_metrics` `read_csv` for consistency with the other 8 helpers. - Fix typos: `Retrun` -> `Return`, `intermitttently` -> `intermittently`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Extract `_warn_wqx3_unavailable()` next to `_warn_wqx3_use()` and `_warn_legacy_use()`. Replaces 6 copies of an identical 4-line `warnings.warn(...)` block with a single helper call. `stacklevel=3` preserves the original `stacklevel=2` semantics through the extra helper frame. - Collapse `if legacy is True: url = ... else: warn(); url = ...` branches in 6 helpers — both arms assigned the same legacy URL — to `if not legacy: warn()` followed by a single assignment. - Apply the same `TypeError(msg, msg)` -> `ValueError(single_msg)` fix to `get_results`'s two `dataProfile` validators (the same broken pattern this PR already fixed in `wqp_url`/`wqx3_url`); also fixes the missing space in the joined "WQX3.0profile" message. - Add 2 regression tests for the `get_results` error paths. 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>
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
A handful of small, discrete polish fixes in
dataretrieval/wqp.py:what_organizations,what_projects,what_detection_limits,what_habitat_metrics,what_project_weights,what_activity_metrics) hadprint(\"WQX3.0 profile not available, returning legacy profile.\")statements that fire wheneverlegacy=Falseis passed. Library code shouldn'tprintto stdout; converted towarnings.warn(..., UserWarning, stacklevel=2)so callers can filter, redirect, or capture them viawarnings/pytest.warns.wqp_url/wqx3_url:TypeError(\"... Valid options are\", f\"{services}.\")produced an exception whoseargsis a 2-tuple of strings, breaking the message rendering and using the wrong exception class (ValueErroris the right type for an unrecognized argument value). Replaced with a singleValueErrorcarrying one f-string.what_activity_metricswas the onlyread_csvsite in this module withoutlow_memory=False. Added it for parity with the other eight helpers.Retrun->Return(docstring);intermitttently->intermittently(warning text).Test plan
test_wqp_url_unknown_service_raises_value_error— confirms ValueError (not TypeError) with single readable message.test_wqx3_url_unknown_service_raises_value_error— same for WQX3.0 helper.test_what_organizations_legacy_false_warns— confirmslegacy=Falseemits aUserWarning(not stdoutprint).nwis_test.py): 199 passed.🤖 Generated with Claude Code