From 6bf472e1522be2d420ccd2b6bc54b364ac9e6124 Mon Sep 17 00:00:00 2001 From: David Hoese <david.hoese@ssec.wisc.edu> Date: Thu, 27 Jul 2023 13:27:49 -0500 Subject: [PATCH] Fix handling of only one wind component in API request --- metobsapi/data_api.py | 3 ++- metobsapi/tests/test_data_api.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/metobsapi/data_api.py b/metobsapi/data_api.py index f2c7e2b..ef23a6b 100644 --- a/metobsapi/data_api.py +++ b/metobsapi/data_api.py @@ -75,10 +75,11 @@ def handle_symbols(symbols: list[str]): # detecting 'wind_direction', otherwise we don't know we need to readd it influx_to_requested_symbols[f"{site}.{inst}.{influx_name}"] = symbol + influx_symbols.setdefault((site, inst), []) if s == "wind_direction": add_winds.add((site, inst)) continue - influx_symbols.setdefault((site, inst), []).append(influx_name) + influx_symbols[(site, inst)].append(influx_name) # Add the symbols needed to compute the wind_speed and wind_direction for site, inst in add_winds: diff --git a/metobsapi/tests/test_data_api.py b/metobsapi/tests/test_data_api.py index 78ec1a4..8159342 100644 --- a/metobsapi/tests/test_data_api.py +++ b/metobsapi/tests/test_data_api.py @@ -402,6 +402,22 @@ def test_wind_speed_direction_json(symbols, client): assert len(list(res["results"]["data"].keys())) == len(symbols) +@pytest.mark.usefixtures("influxdb_wind_fields_9_values") +def test_wind_direction_only_json(client): + symbols = ["wind_direction"] + symbol_param = ":".join(symbols) + site_inst_params = "&site=aoss&inst=tower" + + res = client.get(f"/api/data.json?symbols={symbol_param}{site_inst_params}&begin=-00:10:00&order=column") + res = json.loads(res.data.decode()) + assert res["code"] == 200 + assert res["num_results"] == 9 + for symbol_name in symbols: + assert symbol_name in res["results"]["data"] + assert not np.isnan(res["results"]["data"][symbol_name]).all() + assert len(list(res["results"]["data"].keys())) == len(symbols) + + def test_one_symbol_two_insts_json_row(client, mock_influxdb_query): fake_result = _fake_data( "1m", -- GitLab