Repository navigation
feat(ogc): accept date, datetime and Timestamp values in date arguments - #442
Open
bhaskargurram-ai wants to merge 2 commits into
Open
bhaskargurram-ai wants to merge 2 commits into
bhaskargurram-ai wants to merge 2 commits into
Conversation
A datetime.date, datetime.datetime or pandas.Timestamp passed to a date
argument (time=[df.index.min(), None]) failed inside the formatter with
AttributeError ('endswith') or, for a lone datetime, TypeError (not
iterable), naming no argument. Read them like the equivalent string:
aware values convert to UTC, naive ones use the local zone as naive
strings do, a date is midnight of that day, and NaT is an open bound.
Any other type raises ValueError naming the argument.
Follow-up named in DOI-USGS#441.
Contributor
Author
|
@thodson-usgs this picks up the non-string follow-up you listed in #441. I went with accepting date/datetime/Timestamp rather than only rejecting them, since |
_validate_time_no_duration iterated a lone Timestamp/date and raised TypeError before the formatter could read it; it now normalizes with _coerce_to_list and checks only string elements. Also: drop the redundant date check in _coerce_to_list (a date is not iterable), update the Mapping TypeError to name the accepted types, and tighten the NEWS entry.
thodson-usgs
added a commit
to bhaskargurram-ai/dataretrieval-python
that referenced
this pull request
Oct 11, 2026
A tuple keeps _split_interval assignable to items once DOI-USGS#442 widens the element type, where a list[str | None] would trip list invariance.
This was referenced Oct 11, 2026
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.
Follow-up from #441, which noted that
pd.Timestampanddatetimeelements fail withAttributeErrororTypeError.Problem
A
datetime.date,datetime.datetimeorpandas.Timestamppassed to a date argument fails inside the formatter, and the error names no argument:time=[pd.Timestamp("2024-01-01", tz="UTC"), None]andtime=[date(2024, 1, 1), None]raiseAttributeError: ... has no attribute 'endswith'time=datetime(2024, 1, 1)raisesTypeError: 'datetime.datetime' object is not iterabletime=[df.index.min(), None]is a natural call for a pandas user, and today it hits the first case.Change
In
dataretrieval/ogc/dates.py, these values are now read like the equivalent string:dateis midnight of that day.NaTis an open bound, likeNone.A lone value is treated as a single element, as a lone string already is. Any other type, for example a number, raises
ValueErrornaming the argument and listing the accepted types (the minimum suggested in #441)._format_onenow delegates to a small_to_datetimehelper, so each function stays under the complexity limit.Tests
test_format_api_dates_accepts_date_and_datetime_objects: date, date pairs, awareTimestampanddatetime(an offset converted to UTC),NaTas an open bound, and mixed string andTimestampranges.test_format_api_dates_reads_naive_objects_like_naive_strings: a naivedatetime/Timestampand its string spelling build the same filter, so this holds in any time zone.test_format_api_dates_rejects_other_types_naming_the_argumenttest_construct_api_requests_accepts_timestamp_bounds: request-level check thattime=[Timestamp, None]producestime=2024-01-01%2F..The full suite passes locally (1267 passed), including the new tests under TZ=UTC, America/Denver, Asia/Kolkata and America/Chicago.
coverage reportpasses at 98.99%. ruff, mypy, lint-imports, xenon and complexipy are clean.Open question
The public getter annotations still say
str | list[str]. Should I widen them to include date objects in this PR, or leave that as a separate change?