diff --git a/dataretrieval/wqp.py b/dataretrieval/wqp.py index 24e1737e..1e184aca 100644 --- a/dataretrieval/wqp.py +++ b/dataretrieval/wqp.py @@ -42,7 +42,7 @@ def get_results( ssl_check=True, - legacy=True, + legacy=False, **kwargs, ) -> tuple[DataFrame, WQP_Metadata]: """Query the WQP for results. @@ -152,7 +152,7 @@ def get_results( def what_sites( ssl_check=True, - legacy=True, + legacy=False, **kwargs, ) -> tuple[DataFrame, WQP_Metadata]: """Search WQP for sites within a region with specific data. @@ -207,7 +207,7 @@ def what_sites( def what_organizations( ssl_check=True, - legacy=True, + legacy=False, **kwargs, ) -> tuple[DataFrame, WQP_Metadata]: """Search WQP for organizations within a region with specific data. @@ -256,7 +256,7 @@ def what_organizations( return df, WQP_Metadata(response) -def what_projects(ssl_check=True, legacy=True, **kwargs): +def what_projects(ssl_check=True, legacy=False, **kwargs): """Search WQP for projects within a region with specific data. Any WQP API parameter can be passed as a keyword argument to this function. @@ -305,7 +305,7 @@ def what_projects(ssl_check=True, legacy=True, **kwargs): def what_activities( ssl_check=True, - legacy=True, + legacy=False, **kwargs, ) -> tuple[DataFrame, WQP_Metadata]: """Search WQP for activities within a region with specific data. @@ -369,7 +369,7 @@ def what_activities( def what_detection_limits( ssl_check=True, - legacy=True, + legacy=False, **kwargs, ) -> tuple[DataFrame, WQP_Metadata]: """Search WQP for result detection limits within a region with specific @@ -427,7 +427,7 @@ def what_detection_limits( def what_habitat_metrics( ssl_check=True, - legacy=True, + legacy=False, **kwargs, ) -> tuple[DataFrame, WQP_Metadata]: """Search WQP for habitat metrics within a region with specific data. @@ -476,7 +476,7 @@ def what_habitat_metrics( return df, WQP_Metadata(response) -def what_project_weights(ssl_check=True, legacy=True, **kwargs): +def what_project_weights(ssl_check=True, legacy=False, **kwargs): """Search WQP for project weights within a region with specific data. Any WQP API parameter can be passed as a keyword argument to this function. @@ -528,7 +528,7 @@ def what_project_weights(ssl_check=True, legacy=True, **kwargs): return df, WQP_Metadata(response) -def what_activity_metrics(ssl_check=True, legacy=True, **kwargs): +def what_activity_metrics(ssl_check=True, legacy=False, **kwargs): """Search WQP for activity metrics within a region with specific data. Any WQP API parameter can be passed as a keyword argument to this function. @@ -580,11 +580,12 @@ def what_activity_metrics(ssl_check=True, legacy=True, **kwargs): return df, WQP_Metadata(response) -def wqp_url(service): +def wqp_url(service, warn=True): """Construct the WQP URL for a given service.""" base_url = "https://www.waterqualitydata.us/data/" - _warn_legacy_use() + if warn: + _warn_legacy_use() if service not in services_legacy: raise ValueError( @@ -598,7 +599,6 @@ def wqx3_url(service): """Construct the WQP URL for a given WQX 3.0 service.""" base_url = "https://www.waterqualitydata.us/wqx3/" - _warn_wqx3_use() if service not in services_wqx3: raise ValueError( @@ -681,11 +681,10 @@ def _warn_wqx3_use(): def _warn_legacy_use(): message = ( - "This function call will return the legacy WQX format, " - "which means USGS data have not been updated since March 2024. " - "Please review the dataretrieval-python documentation for more " - "information on updated WQX3.0 profiles. Setting `legacy=False` " - "will remove this warning." + "You are explicitly requesting the legacy WQX format " + "(legacy=True), which means USGS data have not been updated " + "since March 2024. Remove legacy=True from your call to use " + "the current WQX3.0 profiles." ) warnings.warn(message, DeprecationWarning, stacklevel=2) diff --git a/tests/wqp_test.py b/tests/wqp_test.py index a337f7ec..b09c1c49 100644 --- a/tests/wqp_test.py +++ b/tests/wqp_test.py @@ -18,13 +18,14 @@ def test_get_results(requests_mock): - """Tests water quality portal ratings query""" + """Tests water quality portal results query using the default WQX3.0 profile""" request_url = ( - "https://www.waterqualitydata.us/data/Result/Search?siteid=WIDNR_WQX-10032762" + "https://www.waterqualitydata.us/wqx3/Result/search?siteid=WIDNR_WQX-10032762" "&characteristicName=Specific+conductance&startDateLo=05-01-2011&startDateHi=09-30-2011" "&mimeType=csv" + "&dataProfile=fullPhysChem" ) - response_file_path = "tests/data/wqp_results.txt" + response_file_path = "tests/data/wqp3_results.txt" mock_request(requests_mock, request_url, response_file_path) df, md = get_results( siteid="WIDNR_WQX-10032762", @@ -33,42 +34,39 @@ def test_get_results(requests_mock): startDateHi="09-30-2011", ) assert type(df) is DataFrame - assert df.size == 315 + assert df.size == 900 assert md.url == request_url assert isinstance(md.query_time, datetime.timedelta) assert md.header == {"mock_header": "value"} assert md.comment is None -def test_get_results_WQX3(requests_mock): - """Tests water quality portal results query with new WQX3.0 profile""" +def test_get_results_legacy(requests_mock): + """Tests water quality portal results query with explicit legacy=True""" request_url = ( - "https://www.waterqualitydata.us/wqx3/Result/search?siteid=WIDNR_WQX-10032762" + "https://www.waterqualitydata.us/data/Result/Search?siteid=WIDNR_WQX-10032762" "&characteristicName=Specific+conductance&startDateLo=05-01-2011&startDateHi=09-30-2011" "&mimeType=csv" - "&dataProfile=fullPhysChem" ) - response_file_path = "tests/data/wqp3_results.txt" + response_file_path = "tests/data/wqp_results.txt" mock_request(requests_mock, request_url, response_file_path) - df, md = get_results( - legacy=False, - siteid="WIDNR_WQX-10032762", - characteristicName="Specific conductance", - startDateLo="05-01-2011", - startDateHi="09-30-2011", - ) + with pytest.warns(DeprecationWarning, match="legacy=True"): + df, md = get_results( + legacy=True, + siteid="WIDNR_WQX-10032762", + characteristicName="Specific conductance", + startDateLo="05-01-2011", + startDateHi="09-30-2011", + ) assert type(df) is DataFrame - assert df.size == 900 + assert df.size == 315 assert md.url == request_url - assert isinstance(md.query_time, datetime.timedelta) - assert md.header == {"mock_header": "value"} - assert md.comment is None def test_what_sites(requests_mock): - """Tests Water quality portal sites query""" + """Tests Water quality portal sites query using the default WQX3.0 profile""" request_url = ( - "https://www.waterqualitydata.us/data/Station/Search?statecode=US%3A34&characteristicName=Chloride" + "https://www.waterqualitydata.us/wqx3/Station/search?statecode=US%3A34&characteristicName=Chloride" "&mimeType=csv" ) response_file_path = "tests/data/wqp_sites.txt" @@ -117,9 +115,9 @@ def test_what_projects(requests_mock): def test_what_activities(requests_mock): - """Tests Water quality portal activities query""" + """Tests Water quality portal activities query using the default WQX3.0 profile""" request_url = ( - "https://www.waterqualitydata.us/data/Activity/Search?statecode=US%3A34&characteristicName=Chloride" + "https://www.waterqualitydata.us/wqx3/Activity/search?statecode=US%3A34&characteristicName=Chloride" "&mimeType=csv" ) response_file_path = "tests/data/wqp_activities.txt"