Skip to content

Commit fcfaf14

Browse files
thodson-usgsclaude
andcommitted
feat(waterdata.xarray): always drop hash IDs; ignore include_hash
The xarray path never surfaces hash columns (neither the per-record OGC feature id nor the per-series join key), so route every wrapper through a _fetch helper that pops include_hash before calling the underlying getter. This makes the flag inert in the xarray path -- passing include_hash=True no longer triggers a fetch of a column we'd only discard -- and documents that hash IDs are always omitted here. The pandas getters keep include_hash as the opt-in flag; only the xarray layer drops them unconditionally. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 6e88cd6 commit fcfaf14

2 files changed

Lines changed: 34 additions & 6 deletions

File tree

dataretrieval/waterdata/xarray.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -329,22 +329,33 @@ def _sites(df):
329329
return []
330330

331331

332+
def _fetch(func, args, kwargs):
333+
"""Call the underlying getter with hash IDs forced off.
334+
335+
The xarray path never surfaces hash columns (neither the per-record
336+
UUID nor the per-series join key), so ``include_hash`` is dropped here:
337+
passing it has no effect and we avoid fetching a column we'd discard.
338+
"""
339+
kwargs.pop("include_hash", None)
340+
return func(*args, **kwargs)
341+
342+
332343
def _xr_doc(func):
333344
"""Prepend an xarray note to the wrapped getter's docstring."""
334345
note = (
335346
" xarray wrapper: same arguments as "
336347
f"``dataretrieval.waterdata.{func.__name__}``, but returns a\n"
337-
" CF-conventions ``xarray.Dataset`` with series metadata populated.\n\n"
348+
" CF-conventions ``xarray.Dataset`` with series metadata populated.\n"
349+
" Hash-valued ID columns are always omitted here; the\n"
350+
" ``include_hash`` flag does not apply.\n\n"
338351
)
339352
return note + (func.__doc__ or "")
340353

341354

342355
def _timeseries_wrapper(func, *, service, default_cell_method=None):
343356
@_wraps(func)
344357
def wrapper(*args, **kwargs):
345-
# Default (hash-free) fetch: the per-record UUID is never requested or
346-
# materialized; CF attributes come from the surviving columns.
347-
df, base_meta = func(*args, **kwargs)
358+
df, base_meta = _fetch(func, args, kwargs)
348359
return _build_timeseries(
349360
df,
350361
base_meta,
@@ -360,7 +371,7 @@ def wrapper(*args, **kwargs):
360371
def _field_wrapper(func, *, service):
361372
@_wraps(func)
362373
def wrapper(*args, **kwargs):
363-
df, base_meta = func(*args, **kwargs)
374+
df, base_meta = _fetch(func, args, kwargs)
364375
return _build_timeseries(
365376
df,
366377
base_meta,
@@ -377,7 +388,7 @@ def wrapper(*args, **kwargs):
377388
def _stats_wrapper(func, *, service):
378389
@_wraps(func)
379390
def wrapper(*args, **kwargs):
380-
df, base_meta = func(*args, **kwargs)
391+
df, base_meta = _fetch(func, args, kwargs)
381392
return _build_stats(df, base_meta, service)
382393

383394
wrapper.__doc__ = _xr_doc(func)

tests/waterdata_xarray_test.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,20 @@ def test_public_wrappers_exist_and_are_documented():
178178
fn = getattr(wdx, name)
179179
assert callable(fn)
180180
assert "xarray wrapper" in (fn.__doc__ or "")
181+
182+
183+
def test_fetch_strips_include_hash():
184+
# The xarray path never surfaces hash columns, so include_hash must be
185+
# dropped before the underlying getter is called (no wasted fetch).
186+
captured = {}
187+
188+
def fake_getter(*args, **kwargs):
189+
captured.update(kwargs)
190+
return "df", "meta"
191+
192+
df, meta = wdx._fetch(
193+
fake_getter, (), {"include_hash": True, "parameter_code": "00060"}
194+
)
195+
assert (df, meta) == ("df", "meta")
196+
assert "include_hash" not in captured
197+
assert captured == {"parameter_code": "00060"}

0 commit comments

Comments
 (0)