Skip to content

Commit ee67e84

Browse files
thodson-usgsclaude
andcommitted
Unify legacy/wqx3 dataProfile validation
Selects valid_profiles + url + kind once per branch, then validates and applies the WQX3.0 default in straight-line code. Replaces the 3-deep nesting in the wqx3 branch and the duplicated `dataProfile in kwargs and ... not in profiles` check across both branches. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 8fdd267 commit ee67e84

1 file changed

Lines changed: 14 additions & 20 deletions

File tree

dataretrieval/wqp.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -126,30 +126,24 @@ def get_results(
126126

127127
kwargs = _check_kwargs(kwargs)
128128

129-
if legacy is True:
130-
if (
131-
"dataProfile" in kwargs
132-
and kwargs["dataProfile"] not in result_profiles_legacy
133-
):
134-
raise ValueError(
135-
f"dataProfile {kwargs['dataProfile']!r} is not a legacy profile. "
136-
f"Valid options are {result_profiles_legacy}."
137-
)
138-
129+
if legacy:
130+
valid_profiles = result_profiles_legacy
131+
kind = "legacy"
139132
url = wqp_url("Result")
140-
141133
else:
142-
if "dataProfile" in kwargs:
143-
if kwargs["dataProfile"] not in result_profiles_wqx3:
144-
raise ValueError(
145-
f"dataProfile {kwargs['dataProfile']!r} is not a valid "
146-
f"WQX3.0 profile. Valid options are {result_profiles_wqx3}."
147-
)
148-
else:
149-
kwargs["dataProfile"] = "fullPhysChem"
150-
134+
valid_profiles = result_profiles_wqx3
135+
kind = "WQX3.0"
151136
url = wqx3_url("Result")
152137

138+
profile = kwargs.get("dataProfile")
139+
if profile is not None and profile not in valid_profiles:
140+
raise ValueError(
141+
f"dataProfile {profile!r} is not a valid {kind} profile. "
142+
f"Valid options are {valid_profiles}."
143+
)
144+
if not legacy and profile is None:
145+
kwargs["dataProfile"] = "fullPhysChem"
146+
153147
response = query(url, kwargs, delimiter=";", ssl_check=ssl_check)
154148

155149
df = pd.read_csv(StringIO(response.text), delimiter=",", low_memory=False)

0 commit comments

Comments
 (0)