refactor(waterdata)!: snake_case get_samples params (camelCase kept via shim)#331
Draft
thodson-usgs wants to merge 2 commits into
Draft
refactor(waterdata)!: snake_case get_samples params (camelCase kept via shim)#331thodson-usgs wants to merge 2 commits into
thodson-usgs wants to merge 2 commits into
Conversation
…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
f160dec to
48b2cdb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Ahead of the breaking 1.2.0 release, standardize the modern
waterdatagetter surface on snake_case parameter names.get_samplesandget_samples_summarywere 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_codemaps straight to the samestateFipsFIPS code the API expects,bboxtoboundingBox, etc. The function still sends the Samples API its native camelCase query parameters.Param mapping (old camelCase -> new snake_case)
activityMediaNameactivity_media_nameactivityStartDateLoweractivity_start_date_loweractivityStartDateUpperactivity_start_date_upperactivityTypeCodeactivity_type_codecharacteristicGroupcharacteristic_groupcharacteristiccharacteristic(unchanged)characteristicUserSuppliedcharacteristic_user_suppliedboundingBoxbboxcountryFipscountry_codestateFipsstate_codecountyFipscounty_codesiteTypeCodesite_type_codesiteTypeNamesite_type_nameusgsPCodeusgs_pcodehydrologicUnithydrologic_unitmonitoringLocationIdentifiermonitoring_location_idorganizationIdentifierorganization_idpointLocationLatitudepoint_location_latitudepointLocationLongitudepoint_location_longitudepointLocationWithinMilespoint_location_within_milesprojectIdentifierproject_idrecordIdentifierUserSuppliedrecord_identifier_user_suppliedget_samples_summary:monitoringLocationIdentifier->monitoring_location_id.service/profile/ssl_checkare 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)(indataretrieval/waterdata/utils.py) wraps both getters. If a caller passes a deprecated camelCase keyword, the wrapper:DeprecationWarningthat names the replacement, andTypeErrorif 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_APIdict 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
get_samples/get_samples_summarytests (offline,pytest-httpx) to the new snake_case names.DeprecationWarningnaming the new param, and produce the same camelCase request URL.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 onmainand unrelated to this change; the decorator is typed to preserve the wrapped function's return type sosamples.py'sget_usgs_sampleswrapper stays precisely typed).9 passed).🤖 Generated with Claude Code