Skip to content

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

Draft
thodson-usgs wants to merge 1 commit into
DOI-USGS:mainfrom
thodson-usgs:fix/nwis-no-import-time-deprecation
Draft

fix(nwis): stop emitting a DeprecationWarning at import time#300
thodson-usgs wants to merge 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>
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