fix: repair WQP_Metadata.site_info and streamstats.Watershed#295
Merged
thodson-usgs merged 1 commit intoMay 30, 2026
Merged
Conversation
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>
243a794 to
ed364ea
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.
Summary
Two long-standing correctness bugs in
dataretrievalhelper classes, each with a regression test. The fixes are independent and non-breaking.WQP_Metadata.site_infowas dead codeThe
@propertywas defined inside__init__, so it never existed on the class. Accessing the documentedmd.site_infoattribute fell through toBaseMetadata.site_info, which raisesNotImplementedError.It now lives at class scope, reads from
self._parameters, and returns thewhat_sites()lookup for whichever ofsites/site/site_nothe query supplied (orNoneif none was). This matchesNWIS_Metadata.site_info.streamstats.Watershedwas unusableThree bugs compounded:
from_streamstats_jsonassigned 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 aWatershedinstead of a shape, andget_sample_watershed()returned the raw response rather than aWatershed.After this change:
from_streamstats_jsonbuilds an independent instance (via__new__, bypassing the network-fetching__init__) and populates it through a shared_populatehelper.__init__fetches and populatesself.format="shape"raisesNotImplementedErrorinstead of failing silently.get_sample_watershed()requestsformat="object", so it returns aWatershedas its docstring claims.Related to #260: this repairs the
Watershedclass and the silentformatfall-through non-breakingly. The broader "dropformat, always returnWatershed" proposal in that issue remains a separate (breaking) decision.Tests
tests/wqp_test.py—site_infois an accessible property; returnsNonewhen the query named no site and routes towhat_sitesotherwise.tests/streamstats_test.py(new) —from_streamstats_jsonyields independent instances;formathandling forobject/geojson/shape.Verified on the current
main: thewqpandstreamstatstest suites pass andruffis clean.🤖 Generated with Claude Code