Skip to content

Enrich waterdata getter docstrings with examples adapted from R#265

Merged
thodson-usgs merged 2 commits intoDOI-USGS:mainfrom
thodson-usgs:enrich-waterdata-examples
May 6, 2026
Merged

Enrich waterdata getter docstrings with examples adapted from R#265
thodson-usgs merged 2 commits intoDOI-USGS:mainfrom
thodson-usgs:enrich-waterdata-examples

Conversation

@thodson-usgs
Copy link
Copy Markdown
Collaborator

Summary

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. Same rationale as the audit done for get_combined_metadata in #264 — many R example sets cover useful idioms (ISO 8601 durations, half-bounded time intervals, last_modified for incremental polling, multi-value POST queries) that aren't yet shown in the Python docs.

Docs only — no signature, behavior, or test changes.

Functions touched and what was added

Function Added
get_daily ISO 8601 duration (time="P7D") example; last_modified="P7D" example for incremental ETL polling. Also fixed a pre-existing bug where the multi-site / approval_status example block was missing its closing parenthesis and trailing comma.
get_latest_continuous time="P7D" example (drops sites with no recent observation); multi-site / multi-parameter + last_modified="P7D" example.
get_latest_daily last_modified="P7D" example; multi-site + multi-parameter (discharge + water-temperature) example.
get_field_measurements Half-bounded time example ("1980-01-01/.." for everything since 1980; documents the inverse "../<date>" form).

What was deliberately skipped

  • Functions whose example coverage already matched or exceeded R's: get_continuous (5 examples), get_monitoring_locations (2 well-chosen ones already, R's bbox+chaining cases would duplicate get_combined_metadata's new chaining example in Add waterdata.get_combined_metadata for combined location + time-series inventory #264), get_time_series_metadata, get_stats_por, get_stats_date_range, get_samples, get_codes, get_reference_table, get_channel, get_samples_summary.
  • R-only kwargs that have no Python equivalent (no_paging, attach_request, chunk_size, convertType flag toggling). Filter chunking happens automatically in Python.
  • get_daily's R dv_post example using approval_status=c("Approved", "Provisional") — Python already has an approval_status="Approved" example.

Test plan

  • ruff check clean.
  • Each function's __doc__ renders correctly (verified via help()).
  • Live API spot-check: attempted but blocked by a 429 rate limit. The new examples only exercise date-format and multi-value idioms (P7D duration, 1980-01-01/.. half-bounded interval, last_modified field) that are already covered by existing tests and other functions' working examples.

Related

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>
@thodson-usgs thodson-usgs requested a review from Copilot May 6, 2026 13:37
Same pre-existing bug shape as the one PR 265 already fixed in
get_daily: a list item on a continuation line without the doctest
"... " prefix, which makes doctest end the example mid-bracket
(SyntaxError: '[' was never closed). Found by exec'ing every example
in the four PR-touched functions against the live USGS API.

Reformatted to put each list element on its own properly-prefixed
continuation line, matching the style used elsewhere in this file.
While here, dropped the non-PEP8 spaces around the `=` of keyword
arguments.

After this fix, all 15 doctest examples in the four functions PR 265
touched pass when run with the package imported (15/15 across
get_daily, get_latest_continuous, get_latest_daily,
get_field_measurements; verified live against api.waterdata.usgs.gov).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the dataretrieval.waterdata getter docstrings to include additional usage examples (ported/adapted from the R dataRetrieval package) that demonstrate common querying idioms such as ISO 8601 durations, half-bounded time intervals, and incremental polling via last_modified.

Changes:

  • Added new Examples to get_daily showing time="P7D" and incremental polling with last_modified="P7D", and corrected a broken multi-site example formatting.
  • Added new Examples to get_latest_continuous and get_latest_daily covering time="P7D", multi-site/multi-parameter queries, and last_modified="P7D".
  • Added a half-bounded time interval Example to get_field_measurements (time="1980-01-01/..") and documented the inverse form.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@thodson-usgs thodson-usgs requested a review from ldecicco-USGS May 6, 2026 13:43
Copy link
Copy Markdown
Collaborator

@ldecicco-USGS ldecicco-USGS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Helpful examples that will most likely help users realize they don't need to calculate specific date ranges.

@thodson-usgs thodson-usgs merged commit f10f08b into DOI-USGS:main May 6, 2026
8 checks passed
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.

3 participants