Skip to content

Commit 001b051

Browse files
thodson-usgsclaude
andcommitted
refactor(waterdata): collapse _coerce_targets to a single scalar guard
The `isinstance(parsed, pd.DatetimeIndex)` early-return was redundant: `pd.DatetimeIndex(parsed)` returns an equivalent index for an already- parsed DatetimeIndex, so the three branches reduce to one scalar guard that wraps a bare value in a list before constructing the index. Behavior is unchanged for every input kind (DatetimeIndex, scalar string/Timestamp, list, Series, ndarray, empty) — the existing nearest tests cover them all. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Sjb14HkwuCydKSKMsaXsgd
1 parent 2df9743 commit 001b051

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

dataretrieval/waterdata/nearest.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,8 @@ def _coerce_targets(targets: Any) -> pd.DatetimeIndex:
187187
is wrapped directly so its elements are preserved.
188188
"""
189189
parsed = pd.to_datetime(targets, utc=True)
190-
if isinstance(parsed, pd.DatetimeIndex):
191-
return parsed
192190
if pd.api.types.is_scalar(parsed):
193-
return pd.DatetimeIndex([parsed])
191+
parsed = [parsed]
194192
return pd.DatetimeIndex(parsed)
195193

196194

0 commit comments

Comments
 (0)