Skip to content

Commit 3b70023

Browse files
thodson-usgsclaude
andcommitted
_format_api_dates: materialize iterable inputs (Copilot #4)
Previously `time`/`datetime`/`last_modified`/`begin`/`end` were typed as `str | Iterable[str] | None`, but the implementation used `len(...)` and subscripting — generators and other non-Sequence iterables would have raised at runtime, contradicting the annotation. Add a single `list(...)` materialization line right after the str wrap, so any iterable (pandas.Series, numpy.ndarray, generators, sets) flows through cleanly. The half-bounded NaT/None range form is preserved. Verified by passing list / tuple / Series / generator / `[pd.NaT, ...]` through and getting the expected formatted output in each case. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 62a58cf commit 3b70023

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

dataretrieval/waterdata/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ def _format_api_dates(
230230
# Convert single string to list for uniform processing
231231
if isinstance(datetime_input, str):
232232
datetime_input = [datetime_input]
233+
elif not isinstance(datetime_input, (list, tuple)):
234+
# Materialize any other iterable (pandas.Series, numpy.ndarray,
235+
# generator, ...) so the len()/subscript operations below work.
236+
datetime_input = list(datetime_input)
233237

234238
# Check for null or all NA and return None
235239
if all(pd.isna(dt) or dt == "" or dt is None for dt in datetime_input):

0 commit comments

Comments
 (0)