Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions dataretrieval/waterdata/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ def get_time_series_metadata(
unit_of_measure: str | Iterable[str] | None = None,
computation_period_identifier: str | Iterable[str] | None = None,
computation_identifier: str | Iterable[str] | None = None,
thresholds: int | None = None,
thresholds: float | list[float] | None = None,
sublocation_identifier: str | Iterable[str] | None = None,
primary: str | Iterable[str] | None = None,
parent_time_series_id: str | Iterable[str] | None = None,
Expand Down Expand Up @@ -1213,7 +1213,7 @@ def get_latest_continuous(
approval_status: str | Iterable[str] | None = None,
unit_of_measure: str | Iterable[str] | None = None,
qualifier: str | Iterable[str] | None = None,
value: int | None = None,
value: str | Iterable[str] | None = None,
last_modified: str | Iterable[str] | None = None,
skip_geometry: bool | None = None,
time: str | Iterable[str] | None = None,
Expand Down Expand Up @@ -1407,7 +1407,7 @@ def get_latest_daily(
approval_status: str | Iterable[str] | None = None,
unit_of_measure: str | Iterable[str] | None = None,
qualifier: str | Iterable[str] | None = None,
value: int | None = None,
value: str | Iterable[str] | None = None,
last_modified: str | Iterable[str] | None = None,
skip_geometry: bool | None = None,
time: str | Iterable[str] | None = None,
Expand Down
26 changes: 15 additions & 11 deletions dataretrieval/waterdata/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@
"time-series-metadata": "time_series_id",
}

# Every service's output id EXCEPT the two that are genuinely user-facing
# (``monitoring_location_id`` and ``time_series_id``). The rest are synthetic
# per-record ids that ``_arrange_cols`` moves to the end of a result frame.
# Derived from ``_OUTPUT_ID_BY_SERVICE`` so adding a service can't silently
# leave a stray id column at the front again.
_EXTRA_ID_COLS = set(_OUTPUT_ID_BY_SERVICE.values()) - {
"monitoring_location_id",
"time_series_id",
}


def _switch_arg_id(ls: dict[str, Any], id_name: str, service: str):
"""
Expand Down Expand Up @@ -803,7 +813,7 @@ def _next_req_url(
continue
href = link.get("href")
if not href:
return href
return None
# Refuse to follow a next-page link to a different host —
# the request's headers/auth were minted for the original
# host and shouldn't leak to whatever a poisoned response
Expand Down Expand Up @@ -905,7 +915,9 @@ def _get_resp_data(

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

# If no geometry present, then return pandas dataframe. A geodataframe
Expand Down Expand Up @@ -1292,15 +1304,7 @@ def _arrange_cols(

# Move meaningless-to-user, extra id columns to the end
# of the dataframe, if they exist
extra_id_col = set(df.columns).intersection(
{
"latest_continuous_id",
"latest_daily_id",
"daily_id",
"continuous_id",
"field_measurement_id",
}
)
extra_id_col = set(df.columns).intersection(_EXTRA_ID_COLS)

# If the arbitrary id column is returned (either due to properties
# being none or NaN), then move it to the end of the dataframe, but
Expand Down
Loading