Skip to content

Commit 4a83b47

Browse files
thodson-usgsclaude
andcommitted
feat(wateruse): warn that the module is experimental on each call
The USGS NWDC water-use service is new and still changing, so flag `wateruse` as experimental: a `FutureWarning` (in the spirit of `pandas.DataFrame.attrs`' experimental notice) plus a `.. warning::` admonition in the `get_wateruse` docstring. Emitted per call rather than on import: `dataretrieval` imports `wateruse` eagerly (`from . import wateruse`), so an import-time warning would fire for every `import dataretrieval` user; firing inside `get_wateruse` reaches only callers who actually request water-use data. The tests silence the warning module-wide and assert it once explicitly. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Sjb14HkwuCydKSKMsaXsgd
1 parent db3d90d commit 4a83b47

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

dataretrieval/wateruse.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
import asyncio
4747
import io
48+
import warnings
4849
from collections.abc import Callable, Iterable
4950
from typing import Any
5051

@@ -105,6 +106,13 @@ def get_wateruse(
105106
) -> tuple[pd.DataFrame, BaseMetadata]:
106107
"""Get USGS water-use data from the NWDC web service.
107108
109+
.. warning::
110+
111+
``dataretrieval.wateruse`` is **experimental**. The USGS NWDC water-use
112+
service is new and still changing, so this function's parameters and
113+
returned columns may change without warning. Pin a ``dataretrieval``
114+
version if you need a stable interface.
115+
108116
Retrieves modeled water-use estimates from the USGS National Water
109117
Availability Assessment Data Companion. The area is given as exactly one of
110118
``state``, ``county``, or ``huc``; results are always returned on a HUC12
@@ -204,6 +212,18 @@ def get_wateruse(
204212
... )
205213
206214
"""
215+
# Experimental-status notice. Emitted per call rather than on import
216+
# because ``dataretrieval`` imports this module eagerly, so an import-time
217+
# warning would fire for every ``import dataretrieval`` user; firing here
218+
# reaches only callers who actually request water-use data.
219+
warnings.warn(
220+
"dataretrieval.wateruse is experimental: the USGS NWDC water-use "
221+
"service is new and still changing, so this function's parameters and "
222+
"returned columns may change without warning. Pin a dataretrieval "
223+
"version if you need a stable interface.",
224+
FutureWarning,
225+
stacklevel=2,
226+
)
207227
# The public parameters are idiomatic snake_case (consistent with
208228
# ``waterdata.get_samples``); the NWDC service expects compact lowercase
209229
# query names, so map to those here as the request is built.

tests/wateruse_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
from dataretrieval.utils import BaseMetadata
1616
from dataretrieval.wateruse import _next_page_url, _resolve_locations, get_wateruse
1717

18+
# ``get_wateruse`` emits an experimental-status FutureWarning on every call; the
19+
# dedicated test below asserts it explicitly, so silence it for the rest.
20+
pytestmark = pytest.mark.filterwarnings("ignore::FutureWarning")
21+
1822
# Match the NWDC endpoint regardless of query string, so assertions can drill
1923
# into the captured params without coupling registration to param order.
2024
WU_RE = re.compile(r"^https://api\.water\.usgs\.gov/nwaa-data/data(\?.*)?$")
@@ -63,6 +67,15 @@ def test_get_wateruse_single_page(httpx_mock):
6367
assert len(df) == 3
6468

6569

70+
def test_get_wateruse_warns_experimental(httpx_mock):
71+
"""``get_wateruse`` emits a ``FutureWarning`` flagging the module as
72+
experimental (the NWDC service and this interface are still settling)."""
73+
httpx_mock.add_response(method="GET", url=WU_RE, text=_CSV_PAGE)
74+
75+
with pytest.warns(FutureWarning, match="experimental"):
76+
get_wateruse(model="wu-public-supply-wd", state="RI")
77+
78+
6679
def test_huc12_id_kept_as_string_with_leading_zero(httpx_mock):
6780
"""The HUC12 identifier must not be coerced to int (leading zeros matter)."""
6881
httpx_mock.add_response(method="GET", url=WU_RE, text=_CSV_PAGE)

0 commit comments

Comments
 (0)