Skip to content

refactor(waterdata)!: snake_case get_samples params (camelCase kept via shim)#331

Merged
thodson-usgs merged 3 commits into
DOI-USGS:mainfrom
thodson-usgs:chore/samples-snake-case
Jun 24, 2026
Merged

refactor(waterdata)!: snake_case get_samples params (camelCase kept via shim)#331
thodson-usgs merged 3 commits into
DOI-USGS:mainfrom
thodson-usgs:chore/samples-snake-case

Conversation

@thodson-usgs

Copy link
Copy Markdown
Collaborator

What

Ahead of the breaking 1.2.0 release, standardize the modern waterdata getter surface on snake_case parameter names. get_samples and get_samples_summary were the last outliers — they exposed the Samples API's native camelCase param names, while every other OGC waterdata getter already uses snake_case.

Only names change. Semantics are unchanged: state_code maps straight to the same stateFips FIPS code the API expects, bbox to boundingBox, etc. The function still sends the Samples API its native camelCase query parameters.

Param mapping (old camelCase -> new snake_case)

Old (Samples API camelCase) New (snake_case)
activityMediaName activity_media_name
activityStartDateLower activity_start_date_lower
activityStartDateUpper activity_start_date_upper
activityTypeCode activity_type_code
characteristicGroup characteristic_group
characteristic characteristic (unchanged)
characteristicUserSupplied characteristic_user_supplied
boundingBox bbox
countryFips country_code
stateFips state_code
countyFips county_code
siteTypeCode site_type_code
siteTypeName site_type_name
usgsPCode usgs_pcode
hydrologicUnit hydrologic_unit
monitoringLocationIdentifier monitoring_location_id
organizationIdentifier organization_id
pointLocationLatitude point_location_latitude
pointLocationLongitude point_location_longitude
pointLocationWithinMiles point_location_within_miles
projectIdentifier project_id
recordIdentifierUserSupplied record_identifier_user_supplied

get_samples_summary: monitoringLocationIdentifier -> monitoring_location_id. service/profile/ssl_check are unchanged.

The chosen names follow get_monitoring_locations (country_code/state_code/county_code/bbox/monitoring_location_id), matching the convention already used across the OGC getters.

How the back-compat shim works

A new generic, testable decorator _accept_legacy_kwargs(mapping) (in dataretrieval/waterdata/utils.py) wraps both getters. If a caller passes a deprecated camelCase keyword, the wrapper:

  1. renames it to the new snake_case parameter,
  2. emits a DeprecationWarning that names the replacement, and
  3. raises TypeError if both the old and new name are supplied for the same argument.

Callers using the new snake_case names see no warning. Internally, a module-level _SAMPLES_PARAM_TO_API dict maps each public snake_case param back to its camelCase wire name just before the request is built (mirroring how the OGC getters map e.g. skipGeometry/bbox). The legacy-kwargs mapping is derived from _SAMPLES_PARAM_TO_API, so the two can't drift apart. The demo notebooks use camelCase and are left untouched — the shim keeps them working.

Tests

  • Updated the existing get_samples / get_samples_summary tests (offline, pytest-httpx) to the new snake_case names.
  • Added tests that the legacy camelCase names still work, emit a DeprecationWarning naming the new param, and produce the same camelCase request URL.
  • Added a test that passing both the old and new name raises TypeError, and that snake_case-only calls emit no warning.

Verification

  • ruff check / ruff format --check: clean.
  • mypy --strict dataretrieval/: no new errors (the 3 remaining errors are pre-existing on main and unrelated to this change; the decorator is typed to preserve the wrapped function's return type so samples.py's get_usgs_samples wrapper stays precisely typed).
  • Offline samples tests pass (9 passed).

🤖 Generated with Claude Code

thodson-usgs and others added 2 commits June 23, 2026 21:52
…ia shim)

Standardize the modern waterdata getter surface on snake_case parameter
names ahead of the breaking 1.2.0 release. `get_samples` and
`get_samples_summary` were the last getters exposing the Samples API's
native camelCase param names; every other OGC getter already uses
snake_case.

The function still sends the Samples API its native camelCase query
parameters: a module-level `_SAMPLES_PARAM_TO_API` dict maps each public
snake_case parameter to its camelCase wire name just before the request is
built (mirroring how the OGC getters map e.g. `skipGeometry`/`bbox`).

Mappings follow `get_monitoring_locations`: `stateFips`->`state_code`,
`countyFips`->`county_code`, `countryFips`->`country_code`,
`boundingBox`->`bbox`, `monitoringLocationIdentifier`->`monitoring_location_id`;
the rest are snake_cased (`usgsPCode`->`usgs_pcode`,
`hydrologicUnit`->`hydrologic_unit`, etc.). Docstrings now document each
snake_case parameter and note its underlying Samples-API camelCase name.

A new generic, testable `_accept_legacy_kwargs(mapping)` decorator
(dataretrieval/waterdata/utils.py) lets both getters still accept the old
camelCase names, translating them to the new snake_case params and emitting
a DeprecationWarning that names the replacement. Existing callers (including
the demo notebooks, left untouched) keep working with a warning.

BREAKING CHANGE: `get_samples` / `get_samples_summary` parameters are now
snake_case. The old camelCase names still work but emit a DeprecationWarning
and will be removed in a future release.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Sjb14HkwuCydKSKMsaXsgd
…samples kwarg

The existing tests check a couple of deprecated camelCase params end-to-end.
Add a single unit test that iterates the whole `_SAMPLES_LEGACY_KWARGS` mapping
and asserts, for every legacy name, that it is still accepted, emits a
`DeprecationWarning` naming the snake_case replacement, is renamed to that
param, and round-trips to the same Samples-API wire name it always used — so
every existing camelCase call site keeps producing an identical request. A
future param renamed without a legacy alias now fails this test.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Sjb14HkwuCydKSKMsaXsgd
@thodson-usgs thodson-usgs force-pushed the chore/samples-snake-case branch from f160dec to 48b2cdb Compare June 24, 2026 02:54
…ake_case

Adds an end-to-end equivalence test: passing every renamed parameter as its
legacy camelCase name produces a byte-identical request URL AND an identical
DataFrame to the snake_case call (verified for all 21 renamed params at once,
offline via pytest-httpx). This is the strongest backward-compat guarantee —
the camelCase shim changes nothing the caller observes but the parameter names —
and complements the existing per-name mapping test and the warning-path tests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Sjb14HkwuCydKSKMsaXsgd
thodson-usgs added a commit to thodson-usgs/dataretrieval-python that referenced this pull request Jun 24, 2026
Expose idiomatic snake_case parameter names on ``get_wateruse`` and map them to
the NWDC's compact wire names when the request is built — the same user-facing
convention as ``waterdata.get_samples`` (DOI-USGS#331):

    timeres   -> time_resolution
    startdate -> start_date
    enddate   -> end_date

Only the Python-facing parameters change; the NWDC query still receives
``timeres`` / ``startdate`` / ``enddate`` on the wire. ``wateruse`` is a new,
unreleased module, so there are no prior callers to keep compatible and no
deprecation shim is needed (unlike DOI-USGS#331, which had to accept the released
camelCase aliases).

Updates the signature, docstrings, the README and demo-notebook examples, and
adds a test pinning the snake_case -> wire-name mapping.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Sjb14HkwuCydKSKMsaXsgd
@thodson-usgs thodson-usgs marked this pull request as ready for review June 24, 2026 15:32
@thodson-usgs thodson-usgs merged commit 047a53e into DOI-USGS:main Jun 24, 2026
9 checks passed
@thodson-usgs thodson-usgs deleted the chore/samples-snake-case branch June 24, 2026 15:32
thodson-usgs added a commit to thodson-usgs/dataretrieval-python that referenced this pull request Jun 24, 2026
Expose idiomatic snake_case parameter names on ``get_wateruse`` and map them to
the NWDC's compact wire names when the request is built — the same user-facing
convention as ``waterdata.get_samples`` (DOI-USGS#331):

    timeres   -> time_resolution
    startdate -> start_date
    enddate   -> end_date

Only the Python-facing parameters change; the NWDC query still receives
``timeres`` / ``startdate`` / ``enddate`` on the wire. ``wateruse`` is a new,
unreleased module, so there are no prior callers to keep compatible and no
deprecation shim is needed (unlike DOI-USGS#331, which had to accept the released
camelCase aliases).

Updates the signature, docstrings, the README and demo-notebook examples, and
adds a test pinning the snake_case -> wire-name mapping.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Sjb14HkwuCydKSKMsaXsgd
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