Skip to content

Commit 3316f7a

Browse files
thodson-usgsclaude
andcommitted
Address Copilot review on PR #247: tighten _format_api_dates docstring
- Widen the `datetime_input` annotation to `str | list[str | None] | None` to match the actual contract — range endpoints may be `None`/`NaN`/empty for half-bounded ranges. - Rewrite the Notes bullets to spell out the per-element NA behavior (single value -> None; range endpoint -> ".."; range is None only when every element is NA or a non-NA element fails to parse). - Drop the stale "replaces 'nan' with '..' in the output" bullet — the implementation no longer string-replaces, it handles NA per-element. - Document `PT...` time-only durations alongside `P7D` in the parameter description. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 74625a0 commit 3316f7a

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

dataretrieval/waterdata/utils.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def _format_one(dt, *, date: bool, local_tz) -> str | None:
175175

176176

177177
def _format_api_dates(
178-
datetime_input: str | list[str], date: bool = False
178+
datetime_input: str | list[str | None] | None, date: bool = False
179179
) -> str | None:
180180
"""
181181
Formats date or datetime input(s) for use with an API.
@@ -185,10 +185,12 @@ def _format_api_dates(
185185
186186
Parameters
187187
----------
188-
datetime_input : Union[str, List[str]]
188+
datetime_input : Union[str, List[Optional[str]], None]
189189
A single date/datetime string or a list of one or two date/datetime
190190
strings. Accepts formats like "%Y-%m-%d %H:%M:%S", ISO 8601 (with or
191-
without ``Z``/numeric offset), or relative periods (e.g., "P7D").
191+
without ``Z``/numeric offset), or relative periods (e.g., "P7D" /
192+
"PT36H"). Range endpoints may be ``None``/``NaN``/empty to denote a
193+
half-bounded range.
192194
date : bool, optional
193195
If True, uses only the date portion ("YYYY-MM-DD"). If False (default),
194196
returns full datetime in UTC ISO 8601 format ("YYYY-MM-DDTHH:MM:SSZ").
@@ -210,14 +212,16 @@ def _format_api_dates(
210212
211213
Notes
212214
-----
213-
- Handles blank or NA values by returning None.
214-
- Supports relative period strings (e.g., "P7D") and passes them through
215-
unchanged.
215+
- A single blank/NA value returns None. In a two-value range, a blank/NA
216+
endpoint is rendered as ``".."`` to denote an open bound (e.g.
217+
``"2024-01-01/.."``); the range is only None when *every* element is
218+
blank/NA or any non-NA element fails to parse.
219+
- Supports ISO 8601 durations such as "P7D" and "PT36H" and pre-formatted
220+
intervals containing ``"/"``; both are passed through unchanged.
216221
- Converts datetimes to UTC and formats as ISO 8601 with 'Z' suffix when
217222
`date` is False. Inputs with an explicit offset (``Z`` or ``+HH:MM``) are
218223
converted from that offset to UTC; naive inputs are interpreted in the
219224
local time zone for backwards compatibility.
220-
- For date ranges, replaces "nan" with ".." in the output.
221225
"""
222226
# Get timezone
223227
local_timezone = datetime.now().astimezone().tzinfo

0 commit comments

Comments
 (0)