diff --git a/metobsapi/tests/test_data_api.py b/metobsapi/tests/test_data_api.py index 645be8c780294bb1f6cf2f24cf3468025e03a3d6..d2bb3af17e22ee98e50ce2129fc84ee331dacaa1 100644 --- a/metobsapi/tests/test_data_api.py +++ b/metobsapi/tests/test_data_api.py @@ -337,6 +337,26 @@ def test_shorthand_one_symbol_json_column(client): 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") + res2 = _query_with_symbols(client, "rel_hum:air_temp:wind_speed") + assert res1["results"]["data"]["air_temp"] == res2["results"]["data"]["air_temp"] + assert res1["results"]["data"]["rel_hum"] == res2["results"]["data"]["rel_hum"] + + +def _query_with_symbols(client, symbols: str) -> dict: + res = client.get(f"/api/data.json?site=aoss&inst=tower&symbols={symbols}&begin=-00:10:00&order=column") + res = json.loads(res.data.decode()) + assert res["code"] == 200 + assert res["num_results"] == 9 + for symbol in symbols.split(":"): + assert symbol in res["results"]["data"] + assert len(res["results"]["data"][symbol]) == 9 + assert len(res["results"]["timestamps"]) == 9 + return res + + @pytest.mark.parametrize( "symbols", [ diff --git a/metobsapi/util/query_influx.py b/metobsapi/util/query_influx.py index 4b35afd10ed0f601623a9ad83165996a506ef0af..bbc2ee3ecc6c85f83d14efef0448a986011726a6 100644 --- a/metobsapi/util/query_influx.py +++ b/metobsapi/util/query_influx.py @@ -89,6 +89,8 @@ class QueryHandler: else: 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] # "_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