diff --git a/metobsapi/tests/test_data_api.py b/metobsapi/tests/test_data_api.py index 272f993e88b99b1f9c6d69772db018e3f64b1dc3..78ec1a4a2ddc4ed5b5ded37c0ecfcf9b7eff9e9a 100644 --- a/metobsapi/tests/test_data_api.py +++ b/metobsapi/tests/test_data_api.py @@ -337,6 +337,21 @@ def test_shorthand_one_symbol_json_column(client): assert len(res["results"]["timestamps"]) == 9 +@pytest.mark.usefixtures("influxdb_air_temp_9_values") +def test_shorthand_fill_symbol_json_column(client): + """Test that a valid column that is not available is still present in the result.""" + res = client.get("/api/data.json?site=aoss&inst=tower&symbols=air_temp:wind_speed&begin=-00:10:00&order=column") + res = json.loads(res.data.decode()) + assert res["code"] == 200 + assert res["num_results"] == 9 + assert "air_temp" in res["results"]["data"] + assert "wind_speed" in res["results"]["data"] + assert len(res["results"]["data"]["air_temp"]) == 9 + assert len(res["results"]["data"]["wind_speed"]) == 9 + assert np.isnan(res["results"]["data"]["wind_speed"]).all() + assert len(res["results"]["timestamps"]) == 9 + + @pytest.mark.usefixtures("influxdb_3_symbols_9_values") def test_shorthand_two_symbols_json_column_order_check(client): res1 = _query_with_symbols(client, "air_temp:rel_hum:wind_speed") diff --git a/metobsapi/util/query_influx.py b/metobsapi/util/query_influx.py index 15d8f78bc7a6b94fd08f023e18ba699af7368495..49a546875c6c98793c624963205dccd5863d0ab3 100644 --- a/metobsapi/util/query_influx.py +++ b/metobsapi/util/query_influx.py @@ -90,7 +90,7 @@ class QueryHandler: data_frame = frames_for_inst[0] data_frame = data_frame.drop(columns=["site", "inst"]) # get dataframe into the same order that was requested - data_frame = data_frame[symbol_names] + data_frame = data_frame.reindex(columns=symbol_names) # "_time" should already be set as the index, so we don't need to rename it new_column_names = [f"{site}.{inst}.{col_name}" for col_name in data_frame.columns] data_frame.columns = new_column_names