Skip to content

fix: repair WQP_Metadata.site_info and streamstats.Watershed#295

Merged
thodson-usgs merged 1 commit into
DOI-USGS:mainfrom
thodson-usgs:fix/resume-postproc-and-broken-helpers
May 30, 2026
Merged

fix: repair WQP_Metadata.site_info and streamstats.Watershed#295
thodson-usgs merged 1 commit into
DOI-USGS:mainfrom
thodson-usgs:fix/resume-postproc-and-broken-helpers

Conversation

@thodson-usgs
Copy link
Copy Markdown
Collaborator

@thodson-usgs thodson-usgs commented May 29, 2026

Summary

Two long-standing correctness bugs in dataretrieval helper classes, each with a regression test. The fixes are independent and non-breaking.

WQP_Metadata.site_info was dead code

The @property was defined inside __init__, so it never existed on the class. Accessing the documented md.site_info attribute fell through to BaseMetadata.site_info, which raises NotImplementedError.

It now lives at class scope, reads from self._parameters, and returns the what_sites() lookup for whichever of sites / site / site_no the query supplied (or None if none was). This matches NWIS_Metadata.site_info.

streamstats.Watershed was unusable

Three bugs compounded:

  • from_streamstats_json assigned the parsed fields to class attributes and returned the class object rather than an instance — so every call mutated shared state and handed back the same object.
  • __init__ fetched a watershed but discarded the result, leaving instances empty.
  • get_watershed(format="shape") silently fell through to returning a Watershed instead of a shape, and get_sample_watershed() returned the raw response rather than a Watershed.

After this change:

  • from_streamstats_json builds an independent instance (via __new__, bypassing the network-fetching __init__) and populates it through a shared _populate helper.
  • __init__ fetches and populates self.
  • the unimplemented format="shape" raises NotImplementedError instead of failing silently.
  • get_sample_watershed() requests format="object", so it returns a Watershed as its docstring claims.

Related to #260: this repairs the Watershed class and the silent format fall-through non-breakingly. The broader "drop format, always return Watershed" proposal in that issue remains a separate (breaking) decision.

Tests

  • tests/wqp_test.pysite_info is an accessible property; returns None when the query named no site and routes to what_sites otherwise.
  • tests/streamstats_test.py (new) — from_streamstats_json yields independent instances; format handling for object / geojson / shape.

Verified on the current main: the wqp and streamstats test suites pass and ruff is clean.

🤖 Generated with Claude Code

@thodson-usgs thodson-usgs changed the title fix(waterdata): post-process chunked resume; repair WQP & streamstats metadata fix(waterdata): repair WQP_Metadata.site_info and streamstats.Watershed May 30, 2026
@thodson-usgs thodson-usgs marked this pull request as ready for review May 30, 2026 16:19
Two long-standing correctness bugs in helper classes, each with a
regression test. The fixes are independent and non-breaking.

WQP_Metadata.site_info: the property was defined inside __init__, so it
never existed on the class. Accessing the documented md.site_info
attribute fell through to BaseMetadata.site_info, which raises
NotImplementedError. Moved it to class scope, reading from
self._parameters and returning the what_sites() lookup for whichever of
sites/site/site_no the query supplied (None if none was). This now
mirrors NWIS_Metadata.site_info.

streamstats.Watershed: the class was unusable. from_streamstats_json
assigned the parsed fields to class attributes and returned the class
object rather than an instance, so every call mutated shared state and
handed back the same object; __init__ fetched a watershed but discarded
the result, leaving instances empty; and get_watershed(format="shape")
silently fell through to returning a Watershed instead of a shape.

Now from_streamstats_json builds an independent instance (via __new__,
bypassing the network-fetching __init__) and populates it through a
shared _populate helper; __init__ fetches and populates self; the
unimplemented format="shape" raises NotImplementedError instead of
failing silently; and get_sample_watershed() requests format="object"
so it returns a Watershed as documented.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@thodson-usgs thodson-usgs force-pushed the fix/resume-postproc-and-broken-helpers branch from 243a794 to ed364ea Compare May 30, 2026 16:37
@thodson-usgs thodson-usgs changed the title fix(waterdata): repair WQP_Metadata.site_info and streamstats.Watershed fix: repair WQP_Metadata.site_info and streamstats.Watershed May 30, 2026
@thodson-usgs thodson-usgs merged commit cdd533e into DOI-USGS:main May 30, 2026
8 checks passed
@thodson-usgs thodson-usgs deleted the fix/resume-postproc-and-broken-helpers branch May 30, 2026 16:40
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