Skip to content

feat(waterdata): serve the method and citation reference tables - #470

Open
thodson-usgs wants to merge 10 commits into
DOI-USGS:mainfrom
thodson-usgs:feat/method-reference-tables
Open

thodson-usgs wants to merge 10 commits into
DOI-USGS:mainfrom
thodson-usgs:feat/method-reference-tables

Conversation

@thodson-usgs

@thodson-usgs thodson-usgs commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

waterdata.get_reference_table now accepts methods, method-categories, method-citations, citations and combined-method-citations. Before, it rejected all five although the server offers them.

Usage

from dataretrieval import waterdata

# 4082 methods, keyed by method_id
methods, _ = waterdata.get_reference_table("methods")

# Look up one method by its ID column
thm01, _ = waterdata.get_reference_table("methods", query={"method_id": "THM01"})

# The tables join on same-named columns, with no renaming
categories, _ = waterdata.get_reference_table("method-categories")
methods = methods.merge(categories, on="method_category", how="left")
# columns: method_id, method_type, method_category, method_name,
#          method_description, method_category_name, method_category_description

ID column naming

The old rule (removesuffix("s").replace("-", "_")) gives wrong names for these collections (method, method_categorie, method_citation, citation, combined_method_citation). For the four new collections that another table refers to, the ID column has the name of the foreign-key column, so tables join on same-named columns. The rule is replaced by one explicit table, _OUTPUT_ID_BY_REFERENCE_COLLECTION, that names the ID column of every reference collection, including the counties and countries special cases. Every existing collection keeps its current ID column name. A test checks that the table and the METADATA_COLLECTIONS Literal list the same collections, so adding a table to only one of them fails.

collection ID column referenced by
methods method_id method-citations.method_id, combined-method-citations.method_id, time-series-methods.method_id
method-categories method_category methods.method_category
method-citations citation_method_id combined-method-citations.citation_method_id
citations citation_name method-citations.citation_name
combined-method-citations combined_method_citation_id none; its id is synthetic (<method_id>.<citation_method_id>) and both parts are columns, so it needs a name of its own

The docstring's option list and the description of the ID column are updated, and NEWS.md has an entry. The reference-lists demo notebook has a new section, Method and citation tables, that joins methods to their categories and citations.

Verification

  • Live (2026-11-18), all five collections returned data with the columns above (4082 methods, 4 categories, 3149 method-citations, 945 citations, 4374 combined rows). Every methods.method_category is in method-categories, every method-citations.method_id is in methods, every combined citation_method_id is in method-citations, and the combined ID equals <method_id>.<citation_method_id> on every row.
  • A query filter on the new ID name (e.g. query={"method_id": "00021"} on methods) returns the one matching row for each collection.
  • One join is not complete: 176 of the 2526 non-null method-citations.citation_name values (e.g. EPA-600/R-93/100) have no row in citations; the server's citations table does not contain them. 623 rows have a null citation_name.
  • Offline tests, parametrized over the five collections, fail if one is rejected or its ID column is misnamed. Another test checks the foreign keys against the ID names, and a third checks that _OUTPUT_ID_BY_REFERENCE_COLLECTION and METADATA_COLLECTIONS list the same collections. For the 19 existing collections, the table gives the same ID names as the old rule (checked by comparing the two).
  • ruff check, ruff format --check, mypy, lint-imports, xenon, complexipy and coverage run -m pytest tests/ && coverage report (1674 passed, 99.05%) pass.

thodson-usgs and others added 5 commits November 18, 2026 10:31
Seven of the 24 reference tables are now exceptions to the singularize
rule, and a wrong rule-made name passed silently. An explicit table,
kept in step with METADATA_COLLECTIONS by a key-sync test, mirrors
_OUTPUT_ID_BY_COLLECTION for the data collections.

The method-table tests read live-captured records that refer to each
other, so the join test merges real frames instead of comparing
hand-typed property lists. The NEWS entry is shortened.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thodson-usgs thodson-usgs added the v1 Non-breaking: can merge for the next 1.x release label Nov 23, 2026
…A_COLLECTIONS

IDEs and type checkers now offer the table names and flag a misspelled one
before the call. The runtime check against the same Literal is unchanged.
…ts notebook

Correct the sentence on ID-column names, which the method and citation tables
no longer follow, and add a section that joins methods to method-categories
and method-citations to citations. Also port R's list-valued filter example
(read_waterdata_metadata on time-zone-codes) to a query with a list.
@thodson-usgs
thodson-usgs marked this pull request as ready for review November 30, 2026 18:18
@thodson-usgs
thodson-usgs requested a review from ehinman December 1, 2026 15:37
thodson-usgs and others added 3 commits December 1, 2026 13:33
The comment, docstring and NEWS entry said the method and citation tables
"name" their ID column after the column that refers to them. They now say
the ID column has that column's name. The demo notebook says the methods
are used to produce USGS data, and its table shows "none" in place of a
dash for the combined table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`combined-method-citations` is the one new table that no other table
refers to, so its ID column is not named after a referring column. The
NEWS entry, the comment and the Returns section now say so, and give its
`<method_id>.<citation_method_id>` form. The NEWS entry moves to the top,
dated 12/01/2026, to be re-dated on the day it lands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v1 Non-breaking: can merge for the next 1.x release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant