From b4e45333f207418213d709063f83d6c4800cc488 Mon Sep 17 00:00:00 2001
From: leufen1 <l.leufen@fz-juelich.de>
Date: Tue, 1 Dec 2020 15:37:03 +0100
Subject: [PATCH] introduced test if all requested variables are available, the
 join module will raise an EmptyQueryResult with detailed information which
 variables could not be loaded

---
 mlair/helpers/join.py | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/mlair/helpers/join.py b/mlair/helpers/join.py
index 43a01768..99689ab1 100644
--- a/mlair/helpers/join.py
+++ b/mlair/helpers/join.py
@@ -47,6 +47,13 @@ def download_join(station_name: Union[str, List[str]], stat_var: dict, station_t
     # load series information
     vars_dict = load_series_information(station_name, station_type, network_name, join_url_base, headers, data_origin)
 
+    # check if all requested variables are available
+    if set(stat_var).issubset(vars_dict) is False:
+        missing_variables = set(stat_var).difference(vars_dict)
+        origin = helpers.select_from_dict(data_origin, missing_variables)
+        options = f"station={station_name}, type={station_type}, network={network_name}, origin={origin}"
+        raise EmptyQueryResult(f"No data found for variables {missing_variables} and options {options} in JOIN.")
+
     # correct stat_var values if data is not aggregated (hourly)
     if sampling == "hourly":
         stat_var = {key: "values" for key in stat_var.keys()}
-- 
GitLab