Skip to content

Commit 9e05040

Browse files
thodson-usgsclaude
andcommitted
fix(waterdata): small coherence cleanups (annotations, column order, defensiveness)
Five small, low-risk fixes surfaced by the package review: 1. get_latest_continuous / get_latest_daily: `value` was annotated `int`, but every other getter (and the docstrings) use `str | Iterable[str]`; the `int` hint also rejected the multi-value list filtering the others advertise. 2. get_time_series_metadata: `thresholds` was annotated `int`, vs `float | list[float]` on get_combined_metadata for the same queryable. 3. _arrange_cols: the "move the synthetic per-record id column to the end" set omitted peak_id, channel_measurements_id, combined_meta_id, and field_series_id, so those four getters left their id at the front instead of the end like daily_id. Added them for consistent column layout. 4. _next_req_url: returned a falsy `href` ("") instead of None, contradicting its Optional[str] contract. Return None. 5. _get_resp_data (geopandas branch): mirror the non-geopandas branch's `f.get("id")` so a feature missing a top-level id yields None rather than a KeyError. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent ee653e5 commit 9e05040

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

dataretrieval/waterdata/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ def get_time_series_metadata(
768768
unit_of_measure: str | Iterable[str] | None = None,
769769
computation_period_identifier: str | Iterable[str] | None = None,
770770
computation_identifier: str | Iterable[str] | None = None,
771-
thresholds: int | None = None,
771+
thresholds: float | list[float] | None = None,
772772
sublocation_identifier: str | Iterable[str] | None = None,
773773
primary: str | Iterable[str] | None = None,
774774
parent_time_series_id: str | Iterable[str] | None = None,
@@ -1213,7 +1213,7 @@ def get_latest_continuous(
12131213
approval_status: str | Iterable[str] | None = None,
12141214
unit_of_measure: str | Iterable[str] | None = None,
12151215
qualifier: str | Iterable[str] | None = None,
1216-
value: int | None = None,
1216+
value: str | Iterable[str] | None = None,
12171217
last_modified: str | Iterable[str] | None = None,
12181218
skip_geometry: bool | None = None,
12191219
time: str | Iterable[str] | None = None,
@@ -1407,7 +1407,7 @@ def get_latest_daily(
14071407
approval_status: str | Iterable[str] | None = None,
14081408
unit_of_measure: str | Iterable[str] | None = None,
14091409
qualifier: str | Iterable[str] | None = None,
1410-
value: int | None = None,
1410+
value: str | Iterable[str] | None = None,
14111411
last_modified: str | Iterable[str] | None = None,
14121412
skip_geometry: bool | None = None,
14131413
time: str | Iterable[str] | None = None,

dataretrieval/waterdata/utils.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ def _next_req_url(
803803
continue
804804
href = link.get("href")
805805
if not href:
806-
return href
806+
return None
807807
# Refuse to follow a next-page link to a different host —
808808
# the request's headers/auth were minted for the original
809809
# host and shouldn't leak to whatever a poisoned response
@@ -905,7 +905,9 @@ def _get_resp_data(
905905

906906
# Organize json into geodataframe and make sure id column comes along.
907907
df = gpd.GeoDataFrame.from_features(features)
908-
df["id"] = pd.json_normalize(features)["id"].values
908+
# Mirror the non-geopandas branch's defensive ``f.get("id")`` so a feature
909+
# missing a top-level ``id`` yields None rather than a KeyError.
910+
df["id"] = [f.get("id") for f in features]
909911
df = df[["id"] + [col for col in df.columns if col != "id"]]
910912

911913
# If no geometry present, then return pandas dataframe. A geodataframe
@@ -1299,6 +1301,10 @@ def _arrange_cols(
12991301
"daily_id",
13001302
"continuous_id",
13011303
"field_measurement_id",
1304+
"field_series_id",
1305+
"peak_id",
1306+
"channel_measurements_id",
1307+
"combined_meta_id",
13021308
}
13031309
)
13041310

0 commit comments

Comments
 (0)