fix(wqp): preserve leading zeros on code columns (HUCs, parameter codes, FIPS)#311
Draft
thodson-usgs wants to merge 1 commit into
Draft
fix(wqp): preserve leading zeros on code columns (HUCs, parameter codes, FIPS)#311thodson-usgs wants to merge 1 commit into
thodson-usgs wants to merge 1 commit into
Conversation
…es, FIPS) The nine WQP getters read responses with a bare `pd.read_csv(StringIO(text), delimiter=",", low_memory=False)`, which infers code columns as int/float and silently drops their significant leading zeros: a USGS parameter code "00060" became 60, HUC8 "07090002" became 7090002. (R dataRetrieval reads these as character.) Add a `_read_wqp_csv` helper that reads the header, then re-reads with `dtype=str` for any column whose name is a code/identifier (ends with "code", or contains "identifier"/"huc"/"fips") — covering both the legacy and WQX3.0 column schemas — while leaving value columns numeric. All nine read sites use it. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
All nine WQP getters read the response with a bare
pd.read_csv(StringIO(text), delimiter=",", low_memory=False), which infers code columns as int/float and silently drops their significant leading zeros:R
dataRetrievalreads these as character. (The NWIS RDB path is unaffected — it pinssite_no/parm_cdtostralready.)Fix
Add a
_read_wqp_csvhelper (used by all nine read sites): read the header, then re-read withdtype=strfor any column whose name is a code/identifier — ends with "code", or contains "identifier"/"huc"/"fips". This covers both the legacy and WQX3.0 column schemas while leaving value columns (e.g.ResultMeasureValue) numeric.Verification
Added a regression test; the full
wqpsuite (15) passes —df.shape/df.sizeand the derived*DateTimecolumns are unchanged by the dtype shift.ruffclean.🤖 Generated with Claude Code