Skip to content

Fix WQP_Metadata.site_info: bind as a real property and forward kwargs#249

Draft
thodson-usgs wants to merge 2 commits intoDOI-USGS:mainfrom
thodson-usgs:fix/wqp-metadata-site-info
Draft

Fix WQP_Metadata.site_info: bind as a real property and forward kwargs#249
thodson-usgs wants to merge 2 commits intoDOI-USGS:mainfrom
thodson-usgs:fix/wqp-metadata-site-info

Conversation

@thodson-usgs
Copy link
Copy Markdown
Collaborator

Summary

WQP_Metadata.site_info was defined inside __init__ as a nested @property-decorated function that was never bound to the class. The decorator returned a property descriptor that was immediately discarded when __init__ returned, so md.site_info always fell through to BaseMetadata.site_info and raised NotImplementedError. The closure also used parameters[...] (the captured **parameters kwargs) for the lookup but self._parameters for the in check — an internal inconsistency.

Compounding the issue, every helper called WQP_Metadata(response) with no kwargs, so self._parameters was always {} even after fixing the closure.

This PR:

  • Moves site_info to a real @property on the class.
  • Looks up siteid first (WQP-native; the previous sites / site / site_no keys reflected an NWIS copy-paste and never matched a WQP query) while keeping the legacy aliases as a fallback.
  • Threads **kwargs through WQP_Metadata(response, **kwargs) from all nine call sites so the property has the parameters it needs.
  • Corrects the docstring: the attribute is comment (singular, inherited from BaseMetadata) and query_time is a datetime.timedelta (was datetme.timedelta).

Test plan

  • New regression tests in tests/wqp_test.py: site_info resolves and returns a (DataFrame, WQP_Metadata) tuple when siteid was provided; returns None when no site filter was supplied.
  • All tests/wqp_test.py (13 tests) pass.
  • Full local test suite passes (228 tests, with API_USGS_PAT set to avoid 429s on live tests).

thodson-usgs and others added 2 commits May 3, 2026 12:56
`site_info` was defined inside `WQP_Metadata.__init__` as a nested
`@property`-decorated function that was never bound to the class. The
decorator returned a property descriptor that was immediately discarded
when `__init__` returned, so `md.site_info` always fell through to
`BaseMetadata.site_info` and raised `NotImplementedError`. The closure
also used `parameters[...]` (the captured `**parameters` kwargs) for the
lookup but `self._parameters` for the `in` check — inconsistent.

Compounding the issue, every helper called `WQP_Metadata(response)` with
no kwargs, so `self._parameters` was always `{}` even after fixing the
closure.

Move `site_info` to a real property on the class, look up `siteid` first
(WQP-native; the previous `sites`/`site`/`site_no` keys reflected an NWIS
copy-paste and never matched a WQP query), and thread `**kwargs` through
`WQP_Metadata(response, **kwargs)` from all nine call sites so the
property has the parameters it needs.

Also corrected the docstring: the attribute is `comment` (not `comments`,
inherited from `BaseMetadata`), and the `query_time` type is
`datetime.timedelta` (not `datetme.timedelta`).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Folds the special-cased `siteid` branch into the loop over candidate
keys; semantics are unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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