Repository navigation
feat(waterdata): add getters for time-series revisions and methods - #471
Open
thodson-usgs wants to merge 11 commits into
Open
thodson-usgs wants to merge 11 commits into
thodson-usgs wants to merge 11 commits into
Conversation
Add get_time_series_revisions and get_time_series_methods for the time-series-revisions and time-series-methods OGC collections. Both collections are non-spatial, so the getters omit bbox and skip_geometry and pass spatial=False. Register both in _OUTPUT_ID_BY_COLLECTION (time_series_revision_id, time_series_method_id) and WATERDATA_COLLECTIONS so get_cql and get_queryables accept them. Parse OGC datetime columns as ISO 8601. time-series-methods mixes whole and fractional seconds in end, and the inferred format turned every value of the other precision into NaT.
Mock the empty-result test with the existing _mock_items and _schema_url helpers instead of a regex that matched both collections' items and schema URLs, and assert the empty frame drops the schema's geometry. Drop the collection name from the ISO 8601 comment in the shared OGC shaping code, which names no service.
format="ISO8601" raises, rather than coercing, when a column mixes naive and offset values, where the inferred parse it replaced returned the column with the odd values as NaT. Fall back to the inferred parse in that case, so a getter that returned such a column before still does.
…visions-methods # Conflicts: # NEWS.md
…as 2 The Python 3.10 CI legs run pandas 2.3, the last pandas for 3.10, and failed four tests. When a column mixes naive and offset values, pandas 2 parses it with format="ISO8601" by returning object values and a FutureWarning, where pandas 3 raises. _parse_datetimes caught only the raise, so on pandas 2 the column came back as object dtype instead of datetimes. A result that is not a datetime dtype now falls back to the inferred parse too, and the ISO 8601 attempt's FutureWarning is suppressed (the fallback repeats it where it applies). pandas 2 parses to nanoseconds, which end in 2262, so the 9999-12-31 open interval end is NaT there. The tests that check it is kept now run on pandas 3 only, and the revisions test checks for a UTC datetime dtype rather than the microsecond unit pandas 3 uses.
… frames On pandas 2, which parses datetimes to nanoseconds (1677 to 2262), time-series-methods' 0001-01-01 start and 9999-12-31 end of an open interval became NaT with a "could not be parsed" warning, and a column holding only such values lost its time zone. When the ISO 8601 parse loses a value, the column is parsed again at microsecond resolution, which pandas 3 uses already. get_cql on time-series-methods or time-series-revisions returned a GeoDataFrame with a column of null geometries, unlike the typed getters. The Water Data wrapper now treats both collections as non-spatial for every caller. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The microsecond re-parse ran whenever a value was lost, on either pandas, and astype accepts formats ISO 8601 does not, so on pandas 3 a column with "01/02/2024" was parsed without the unparsed-value warning. It now runs only where the loss can come from the nanosecond range: on pandas 2, and only for a column with NaT, which also skips the mask on every clean column. get_ogc_data's spatial argument defaults from _NONSPATIAL_COLLECTIONS, as output_id defaults from _OUTPUT_ID_BY_COLLECTION, instead of the set overriding whatever the caller passed. Docstrings and the NEWS sentence keep the constraint, not the history; the open-interval test is folded into test_get_time_series_methods. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n notebook AGENTS.md asks for a demo with each new collection. Both collections describe a time series, so they get a short section after the combined-metadata example rather than a notebook of their own.
thodson-usgs
marked this pull request as ready for review
November 30, 2026 18:18
Docstrings and comments said records "carry" no geometry, that a column "takes the inferred parse", that the `spatial` default "reads it from" a set for collections "outside the map", and that a fallback "keeps the call returning, with the odd value NaT". They now say what is computed: records have no geometry, `spatial=None` means False for a collection in `_NONSPATIAL_COLLECTIONS` and True otherwise, and a mixed naive and offset column is parsed with the inferred format, with NaT for the offset value. NEWS and the notebook say the collections "contain" the data. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pandas 2 parses datetimes to nanoseconds. Only a column that lost an out-of-range value (0001-01-01 or 9999-12-31) was parsed again at microseconds, so a `time-series-methods` frame with an open interval had `end` at microseconds and `begin` at nanoseconds. `end - begin`, and a concat with a frame that had no open interval, raised OutOfBoundsDatetime. Every parsed time column is now converted to microseconds on pandas 2, the resolution pandas 3 uses, so a column's resolution no longer depends on its values. NEWS lists it as a behavior change for pandas 2. Also from review: - The `_parse_datetimes` docstring says the inferred parse raises on pandas 3 for a column that mixes UTC offsets, as it did before. - The docstring examples say a date-only end bound is midnight UTC, in place of "began in 2018 or 2019". - The NEWS entry moves to the top, dated 12/01/2026, to be re-dated on the day it lands, and is shorter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Adds typed getters for two Water Data OGC collections that dataretrieval did not wrap:
time-series-revisionsandtime-series-methods.Usage
Both return a plain
pandas.DataFrame. Once #470 is merged,method_idjoins towaterdata.get_reference_table("methods")for each method's name and description.New functions
Both are in
dataretrieval.waterdata.metadata, exported fromdataretrieval.waterdataand re-exported by thewaterdata.apifacade.Each named argument is one of the collection's queryables, plus the control arguments the other getters share. Both collections are non-spatial: the server returns
geometry: null, and returns HTTP 400 forbbox. So neither getter hasbboxorskip_geometry. Both collections are listed in a new_NONSPATIAL_COLLECTIONSset inwaterdata/utils.py, and thespatialargument ofwaterdata.utils.get_ogc_datanow defaults toNone, meaning it is looked up in that set. As a result both getters return a plainDataFrameeven when geopandas is installed, and so doesget_cqlon either collection. Reference tables still passspatial=Falseexplicitly.time-series-methodshas nomonitoring_location_idqueryable (the server returns HTTP 400 for it), soget_time_series_methodsdoesn't offer that argument, and its docstring points toget_time_series_metadatafor looking up a location'stime_series_idvalues.ID columns
The
idthe server sends is returned astime_series_revision_idandtime_series_method_id. These follow the<collection, singular>_idpattern used bydaily_id,peak_idandfield_measurement_id. Both are in_OUTPUT_ID_BY_COLLECTIONandWATERDATA_COLLECTIONS, soget_cqlandget_queryablesaccept the collections. Because both are synthetic IDs,_EXTRA_ID_COLSmoves them to the end of the frame.Date parsing fix
time-series-methodssendsendwith mixed second precision: closed intervals end at...:00.000001+00:00, some at...:00+00:00, and open intervals at9999-12-31T23:59:59.999999+00:00._type_colscalledpd.to_datetimewith no format. pandas infers a single format from the first value, so every value of the other precision becameNaTwith aUserWarning. Live, one series lost 1 of its 10endvalues._type_colsnow parses as ISO 8601. If a column mixes naive and offset values, the ISO 8601 parse raises instead of coercing, so in that case the column is parsed with the inferred format, as it was before. pandas 2 parses to nanoseconds, which span 1677 to 2262, so it turns the0001-01-01and9999-12-31bounds intoNaT. On pandas 2 a column that lost a value this way is parsed again at microseconds, and every other parsed time column is converted to microseconds, the resolution pandas 3 uses. Without the conversion,endwas at microseconds andbeginat nanoseconds, soend - beginand apd.concatwith a closed-interval frame raisedOutOfBoundsDatetime. This changes the shared OGC shaping for all Water Data and NGWMN getters. I checkedget_daily,get_continuous,get_field_measurements,get_time_series_metadataandngwmn.get_water_levellive with UserWarnings as errors: dtypes are unchanged and no value becameNaT. The live suite passes too. On pandas 2 (the Python 3.10 CI job), the time columns of every Water Data and NGWMN getter change from nanoseconds to microseconds; NEWS lists this as a behavior change.Demo notebook
The introduction notebook has a new section, Time-series revisions and methods. It gets the revisions for one monitoring location, and the methods for another location's discharge and temperature series, joined to the series metadata.
Verification
ruff check,ruff format --check,mypy,lint-imports(7 kept),xenon,complexipy, andcoverage run -m pytest tests/ && coverage report(1710 passed, 99.06% branch coverage, above the ratchet) all pass. The offline suite also passes on pandas 2.3.3, except for the tests that need geopandas, which that environment did not have.waterdata_ogc_fixtures.jsonstyle, with two real features per collection added. They assert the exact query string sent (includingbeginrendered as2018-01-01T00:00:00Z/2019-12-31T00:00:00Z), a CQL2infor a list oftime_series_id, a plainDataFramewith nogeometry, the renamed ID columns, and that the 9999-12-31endis kept after parsing.waterdata_queryables.jsonwas regenerated with the script inwaterdata_queryables_test.py; only the two new collections changed. Both getters are registered in the properties and public-API contract tests.pytest -m live tests/, 53 passed). Direct calls:get_time_series_revisions(monitoring_location_id="USGS-01646500"): 26 rows. Withbegin="2018-01-01/2019-12-31": 23 rows.get_time_series_methods(time_series_id="0003587a6a544f6aa37fe13dc2050985")(USGS-05124000 water temperature): 10 rows, noNaTinend. Withbegin="2021-01-01/2021-12-31": 7 rows.