Skip to content

fix(nwis): stop emitting a DeprecationWarning at import time#300

Merged
thodson-usgs merged 1 commit into
DOI-USGS:mainfrom
thodson-usgs:fix/nwis-no-import-time-deprecation
Jun 1, 2026
Merged

fix(nwis): stop emitting a DeprecationWarning at import time#300
thodson-usgs merged 1 commit into
DOI-USGS:mainfrom
thodson-usgs:fix/nwis-no-import-time-deprecation

Conversation

@thodson-usgs
Copy link
Copy Markdown
Collaborator

Problem

dataretrieval/nwis.py issues a DeprecationWarning at module top-level, and dataretrieval/__init__.py does from dataretrieval.nwis import * unconditionally. So import dataretrieval emits a DeprecationWarning for every consumer — even users who only touch the waterdata module — and fails to import at all under -W error::DeprecationWarning (a common CI configuration):

$ python -W error::DeprecationWarning -c "import dataretrieval"
DeprecationWarning: The 'nwis' services are deprecated and being decommissioned. ...

Fix

Remove the module-level warning. Deprecation is already signaled where it's actionable: the @_deprecated decorator wraps every public nwis function and emits a per-function DeprecationWarning on use (with a thread-local guard so layered wrappers warn once). That targeted mechanism is unchanged.

Verification

  • python -W error::DeprecationWarning -c "import dataretrieval" now succeeds.
  • Calling a deprecated function still warns: nwis.get_record(...)
    `nwis.get_record` is deprecated and will be removed ... use the appropriate `waterdata.get_*()` ...
  • ruff clean.

🤖 Generated with Claude Code

nwis.py warned at module top-level, and dataretrieval/__init__ star-imports
nwis, so `import dataretrieval` emitted a DeprecationWarning for every consumer
(including waterdata-only users) and failed to import entirely under
`-W error::DeprecationWarning`, which is common in CI.

Deprecation is already signaled where it matters: the @_deprecated decorator
emits a per-function warning on every nwis call. Removed the redundant
module-level warning; the per-function warnings are unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@thodson-usgs thodson-usgs force-pushed the fix/nwis-no-import-time-deprecation branch from 63fce1b to 7cf10f1 Compare June 1, 2026 00:29
@thodson-usgs thodson-usgs marked this pull request as ready for review June 1, 2026 00:30
@thodson-usgs thodson-usgs merged commit 0cb38d2 into DOI-USGS:main Jun 1, 2026
8 checks passed
@thodson-usgs thodson-usgs deleted the fix/nwis-no-import-time-deprecation branch June 1, 2026 00:30
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