Skip to content

Commit f10f08b

Browse files
thodson-usgsclaude
andauthored
Enrich waterdata getter docstrings with examples adapted from R (#265)
Cross-referenced each Python waterdata getter's Examples section against the corresponding R analogue in DOI-USGS/dataRetrieval and ported the distinctive examples that the Python docs were missing: - get_daily: add ISO 8601 duration ("P7D") and last_modified ("P7D") examples. Also fix a pre-existing bug where the multi-site / approval_status example block was missing its closing parenthesis and trailing comma. - get_latest_continuous: add time="P7D" and multi-site + last_modified="P7D" examples. - get_latest_daily: add last_modified="P7D" and multi-site + multi-parameter examples. - get_field_measurements: add a half-bounded-time example ("1980-01-01/..") and document the inverse "../<date>" form. Docs only — no signature, behavior, or test changes. Ruff clean. Live spot-verification was attempted but blocked by a 429 rate limit; the new examples only use date-format and multi-value idioms that are already covered by existing tests. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 63b586e commit f10f08b

1 file changed

Lines changed: 64 additions & 7 deletions

File tree

dataretrieval/waterdata/api.py

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,27 @@ def get_daily(
208208
... time="2021-01-01T00:00:00Z/2022-01-01T00:00:00Z",
209209
... )
210210
211+
>>> # Quick "show me the last week" idiom (ISO 8601 duration)
212+
>>> df, md = dataretrieval.waterdata.get_daily(
213+
... monitoring_location_id="USGS-02238500",
214+
... parameter_code="00060",
215+
... time="P7D",
216+
... )
217+
211218
>>> # Get approved daily flow data from multiple sites
212219
>>> df, md = dataretrieval.waterdata.get_daily(
213-
... monitoring_location_id = ["USGS-05114000", "USGS-09423350"],
214-
... approval_status = "Approved",
215-
... time = "2024-01-01/.."
220+
... monitoring_location_id=["USGS-05114000", "USGS-09423350"],
221+
... approval_status="Approved",
222+
... time="2024-01-01/..",
223+
... )
224+
225+
>>> # Pull only rows whose underlying record was refreshed in the
226+
>>> # last 7 days — handy for incremental ETL polling
227+
>>> df, md = dataretrieval.waterdata.get_daily(
228+
... monitoring_location_id="USGS-02238500",
229+
... parameter_code="00060",
230+
... last_modified="P7D",
231+
... )
216232
"""
217233
service = "daily"
218234
output_id = "daily_id"
@@ -1329,6 +1345,22 @@ def get_latest_continuous(
13291345
... monitoring_location_id="USGS-02238500", parameter_code="00060"
13301346
... )
13311347
1348+
>>> # Restrict to the last 7 days; sites with no observation in that
1349+
>>> # window are dropped instead of returned with stale values
1350+
>>> df, md = dataretrieval.waterdata.get_latest_continuous(
1351+
... monitoring_location_id="USGS-02238500",
1352+
... parameter_code="00060",
1353+
... time="P7D",
1354+
... )
1355+
1356+
>>> # Pull only rows whose underlying record was refreshed in the
1357+
>>> # last 7 days, across multiple sites and parameters
1358+
>>> df, md = dataretrieval.waterdata.get_latest_continuous(
1359+
... monitoring_location_id=["USGS-451605097071701", "USGS-14181500"],
1360+
... parameter_code=["00060", "72019"],
1361+
... last_modified="P7D",
1362+
... )
1363+
13321364
>>> # Get latest continuous measurements for multiple sites
13331365
>>> df, md = dataretrieval.waterdata.get_latest_continuous(
13341366
... monitoring_location_id=["USGS-05114000", "USGS-09423350"]
@@ -1510,6 +1542,21 @@ def get_latest_daily(
15101542
... monitoring_location_id="USGS-02238500", parameter_code="00060"
15111543
... )
15121544
1545+
>>> # Restrict to rows whose underlying record was refreshed in the
1546+
>>> # last 7 days
1547+
>>> df, md = dataretrieval.waterdata.get_latest_daily(
1548+
... monitoring_location_id="USGS-02238500",
1549+
... parameter_code="00060",
1550+
... last_modified="P7D",
1551+
... )
1552+
1553+
>>> # Multi-site, multi-parameter — discharge and water temperature
1554+
>>> # at two sites in a single round-trip
1555+
>>> df, md = dataretrieval.waterdata.get_latest_daily(
1556+
... monitoring_location_id=["USGS-01491000", "USGS-01645000"],
1557+
... parameter_code=["00060", "00010"],
1558+
... )
1559+
15131560
>>> # Get most recent daily measurements for two sites
15141561
>>> df, md = dataretrieval.waterdata.get_latest_daily(
15151562
... monitoring_location_id=["USGS-05114000", "USGS-09423350"]
@@ -1686,13 +1733,23 @@ def get_field_measurements(
16861733
... skip_geometry=True,
16871734
... )
16881735
1736+
>>> # Half-bounded time range: every measurement at this site since
1737+
>>> # 1980 (open-ended end). Use ``"../<date>"`` for the inverse
1738+
>>> # (everything up to a date).
1739+
>>> df, md = dataretrieval.waterdata.get_field_measurements(
1740+
... monitoring_location_id="USGS-425957088141001",
1741+
... time="1980-01-01/..",
1742+
... )
1743+
16891744
>>> # Get field measurements from multiple sites and
16901745
>>> # parameter codes from the last 20 years
16911746
>>> df, md = dataretrieval.waterdata.get_field_measurements(
1692-
... monitoring_location_id = ["USGS-451605097071701",
1693-
"USGS-263819081585801"],
1694-
... parameter_code = ["62611", "72019"],
1695-
... time = "P20Y"
1747+
... monitoring_location_id=[
1748+
... "USGS-451605097071701",
1749+
... "USGS-263819081585801",
1750+
... ],
1751+
... parameter_code=["62611", "72019"],
1752+
... time="P20Y",
16961753
... )
16971754
"""
16981755
service = "field-measurements"

0 commit comments

Comments
 (0)