Make _handle_stats_nesting tolerant of missing drop columns#257
Draft
thodson-usgs wants to merge 1 commit intoDOI-USGS:mainfrom
Draft
Make _handle_stats_nesting tolerant of missing drop columns#257thodson-usgs wants to merge 1 commit intoDOI-USGS:mainfrom
thodson-usgs wants to merge 1 commit intoDOI-USGS:mainfrom
Conversation
Both `.drop()` calls in `_handle_stats_nesting` (for the geopandas and pandas branches) hardcoded literal column names — `["type", "properties.data"]` and `["data"]`. If a stats response is ever returned in a slightly different shape (or one of those keys is renamed/removed), `drop()` raises `KeyError` and aborts the helper. The sibling `pd.json_normalize(...)` call later in the same function already passes `errors="ignore"`, so add the same to the two `drop()` calls for parity. Co-Authored-By: Claude Opus 4.7 (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.
Summary
_handle_stats_nestinghas two.drop(columns=...)calls (one for the geopandas branch, one for the pandas branch) that hardcode literal column names —[\"type\", \"properties.data\"]and[\"data\"]respectively. If a stats response ever comes back in a slightly different shape (renamed key, missing optional key, edge-case feature without the expected nesting),drop()raisesKeyErrorand aborts the helper.The sibling
pd.json_normalize(...)call later in the same function already passeserrors=\"ignore\", so this PR adds the same to the twodrop()calls for parity.Diff
Test plan
test_handle_stats_nesting_tolerates_missing_drop_columnsconstructs a stats body whose features lack the top-leveltypekey and confirms the function returns a populated DataFrame.mainwithKeyError: \"['type'] not found in axis\".nwis_test.py): 197 passed.🤖 Generated with Claude Code