Skip to content

Commit f3d1e8f

Browse files
thodson-usgsclaude
andcommitted
Make format contract explicit in get_watershed
Previously `get_watershed` had two named formats (`"geojson"`, `"object"`) and any other value silently fell through to a `Watershed` — the same bug shape that masked the dead `"shape"` branch removed earlier in this PR. Add an explicit `"watershed"` case and raise `ValueError` on unrecognized values so a typo'd format fails loudly instead of returning whatever the fallthrough is. Also fix `get_sample_watershed`, whose docstring promises a `Watershed` but called `get_watershed(...)` with the default `format="geojson"` (returns the raw `requests.Response`). Pass `format="watershed"` explicitly so the function matches its documented return type. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent b325f92 commit f3d1e8f

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

dataretrieval/streamstats.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def get_sample_watershed():
5656
from the streamstats JSON object.
5757
5858
"""
59-
return get_watershed("NY", -74.524, 43.939)
59+
return get_watershed("NY", -74.524, 43.939, format="watershed")
6060

6161

6262
def get_watershed(
@@ -106,8 +106,8 @@ def get_watershed(
106106
format: string, optional
107107
Selects the return shape. ``"geojson"`` (default) returns the raw
108108
``requests.Response``; ``"object"`` returns the parsed JSON ``dict``;
109-
any other value returns a :obj:`Watershed` instance built from the
110-
parsed JSON.
109+
``"watershed"`` returns a :obj:`Watershed` instance built from the
110+
parsed JSON. Any other value raises ``ValueError``.
111111
112112
Returns
113113
-------
@@ -140,7 +140,12 @@ def get_watershed(
140140
if format == "object":
141141
return data
142142

143-
return Watershed.from_streamstats_json(data)
143+
if format == "watershed":
144+
return Watershed.from_streamstats_json(data)
145+
146+
raise ValueError(
147+
f"Invalid format {format!r}; expected 'geojson', 'object', or 'watershed'."
148+
)
144149

145150

146151
class Watershed:

0 commit comments

Comments
 (0)