Skip to content

Fix mangled column names for NWIS dam sublocation timeseries#231

Draft
thodson-usgs wants to merge 2 commits into
DOI-USGS:mainfrom
thodson-usgs:fix-nwis-column-names
Draft

Fix mangled column names for NWIS dam sublocation timeseries#231
thodson-usgs wants to merge 2 commits into
DOI-USGS:mainfrom
thodson-usgs:fix-nwis-column-names

Conversation

@thodson-usgs
Copy link
Copy Markdown
Collaborator

@thodson-usgs thodson-usgs commented Apr 13, 2026

Closes #177

Summary

  • NWIS methodDescription fields for dam sites include a sublocation qualifier in the form "STAGE - TAILWATER, [Tailwater]"
  • The previous method.strip("[]()").lower() only stripped leading/trailing brackets — it left the inner , [Tailwater fragment, producing column names like 00065_stage - tailwater, [tailwater
  • Fix: split on ", [" before stripping so "STAGE - TAILWATER, [Tailwater]""stage - tailwater" and "HEADWATER""headwater" (unchanged)

Live reproduction

Site 03399800 is a dam with both headwater and tailwater gage-height sublocations — the tailwater channel's methodDescription is "STAGE - TAILWATER, [Tailwater]", the exact shape that exposes the bug. Both runs below hit waterservices.usgs.gov.

from dataretrieval import nwis

df, _ = nwis.get_iv(sites="03399800", parameterCd="00065")
print([c for c in df.columns if "00065" in c])

# Pre-fix:
#   ['00065_headwater',
#    '00065_headwater_cd',
#    '00065_stage - tailwater, [tailwater',
#    '00065_stage - tailwater, [tailwater_cd']
#
# Post-fix:
#   ['00065_headwater',
#    '00065_headwater_cd',
#    '00065_stage - tailwater',
#    '00065_stage - tailwater_cd']

The pre-fix output was observed live against waterservices.usgs.gov during PR review.

Test plan

  • Added TestReadJsonColumnNames with 3 unit tests covering simple descriptions, bracket-qualified descriptions, and empty descriptions
  • All 96 unit tests pass

🤖 Generated with Claude Code

thodson-usgs and others added 2 commits April 13, 2026 18:27
NWIS methodDescription values like "STAGE - TAILWATER, [Tailwater]"
produced column names with bracket qualifiers (e.g.
"00065_stage - tailwater, [tailwater"). Strip the ", [...]" suffix
before building the column name so get_iv returns clean names like
"00065_stage - tailwater". Closes DOI-USGS#177.

Co-Authored-By: Claude Sonnet 4.6 <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.

Column Names get Mangled for Dam Headwater / Tailwater Stage Observations

1 participant