From 2293a51b84a1dcbcd5c2089bacdb1c9cca8a9dca Mon Sep 17 00:00:00 2001 From: Timothy Hodson <34148978+thodson-usgs@users.noreply.github.com> Date: Fri, 9 Aug 2024 15:26:30 -0500 Subject: [PATCH] Remove hardcoded format in nwis.get_discharge_measurements (#150) * Remove hardcoded format in nwis.get_discharge_measurements * Update test URL --- dataretrieval/nwis.py | 5 ++++- tests/waterservices_test.py | 14 ++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/dataretrieval/nwis.py b/dataretrieval/nwis.py index 39cbafbf..f6d24fa9 100644 --- a/dataretrieval/nwis.py +++ b/dataretrieval/nwis.py @@ -309,8 +309,11 @@ def get_discharge_measurements( kwargs['begin_date'] = kwargs.pop('begin_date', start) kwargs['end_date'] = kwargs.pop('end_date', end) + if 'format' not in kwargs: + kwargs['format'] = 'rdb' + response = query_waterdata( - 'measurements', format='rdb', ssl_check=ssl_check, **kwargs + 'measurements', ssl_check=ssl_check, **kwargs ) return _read_rdb(response.text), NWIS_Metadata(response, **kwargs) diff --git a/tests/waterservices_test.py b/tests/waterservices_test.py index c829232a..10eda337 100755 --- a/tests/waterservices_test.py +++ b/tests/waterservices_test.py @@ -27,6 +27,7 @@ except ImportError: gpd = None + def test_query_waterdata_validation(): """Tests the validation parameters of the query_waterservices method""" with pytest.raises(TypeError) as type_error: @@ -179,7 +180,8 @@ def test_get_info(requests_mock): def test_get_qwdata(requests_mock): - """Tests get_qwdata method correctly generates the request url and returns the result in a DataFrame""" + """Tests get_qwdata method correctly generates the request url and returns + the result in a DataFrame""" format = "rdb" site = '01491000%2C01645000' request_url = 'https://nwis.waterdata.usgs.gov/nwis/qwdata?site_no={}' \ @@ -306,8 +308,8 @@ def test_get_discharge_measurements(requests_mock): DataFrame""" format = "rdb" site = "01594440" - request_url = 'https://nwis.waterdata.usgs.gov/nwis/measurements?format={}&site_no={}' \ - '&begin_date=2000-02-14&end_date=2020-02-15'.format(format, site) + request_url = 'https://nwis.waterdata.usgs.gov/nwis/measurements?site_no={}' \ + '&begin_date=2000-02-14&end_date=2020-02-15&format={}'.format(site, format) response_file_path = 'data/waterdata_measurements.txt' mock_request(requests_mock, request_url, response_file_path) df, md = get_discharge_measurements(sites=[site], start='2000-02-14', end='2020-02-15') @@ -321,10 +323,10 @@ def test_get_discharge_measurements(requests_mock): @pytest.mark.parametrize("site_input_type_list", [True, False]) def test_get_discharge_measurements_sites_value_types(requests_mock, site_input_type_list): """Tests get_discharge_measurements method for valid input types for 'sites' parameter""" - _format = "rdb" + format = "rdb" site = "01594440" - request_url = 'https://nwis.waterdata.usgs.gov/nwis/measurements?format={}&site_no={}' \ - '&begin_date=2000-02-14&end_date=2020-02-15'.format(_format, site) + request_url = 'https://nwis.waterdata.usgs.gov/nwis/measurements?site_no={}' \ + '&begin_date=2000-02-14&end_date=2020-02-15&format={}'.format(site, format) response_file_path = 'data/waterdata_measurements.txt' mock_request(requests_mock, request_url, response_file_path) if site_input_type_list: