Skip to content

Commit

Permalink
clearer error message
Browse files Browse the repository at this point in the history
  • Loading branch information
martinvonk committed Apr 2, 2024
1 parent 161c7b3 commit 02214a0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
26 changes: 10 additions & 16 deletions hydropandas/io/knmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,11 +603,8 @@ def download_knmi_data(stn, meteo_var, start, end, settings, stn_name=None):
stations : pandas DataFrame
information about the measurement station
"""

logger.debug(
f"download KNMI {meteo_var} data from station "
f"{stn}-{stn_name} between {start} and {end}"
)
msg = f"{stn}-{stn_name} between {start} and {end}"
logger.debug(f"download KNMI {meteo_var} data from station " + msg)

# define variables
knmi_df = pd.DataFrame()
Expand Down Expand Up @@ -673,25 +670,22 @@ def download_knmi_data(stn, meteo_var, start, end, settings, stn_name=None):
adjust_time=True,
)
except (ValueError, KeyError) as e:
logger.error(e)
logger.error(f"{e} {msg}")
if settings["raise_exceptions"]:
raise e

if knmi_df.empty:
logger.debug(
"no measurements found for station "
f"{stn}-{stn_name} between {start} and {end}"
)

stations = (
pd.DataFrame()
if knmi_df.empty
else get_stations(meteo_var=meteo_var).loc[[variables["station"]], :]
)
logger.error(f"no measurements found for station {msg}")
stations = pd.DataFrame()
else:
stations = get_stations(meteo_var=meteo_var).loc[[variables["station"]], :]

return knmi_df, variables, stations


Exception()


@lru_cache()
def get_knmi_daily_rainfall_api(stn: int, start=None, end=None):
"""download and read knmi daily rainfall.
Expand Down
6 changes: 5 additions & 1 deletion tests/test_001_to_from.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,11 @@ def test_knmi_collection_from_locations():
obsc = obscollection_dinozip_gw()
try:
hpd.read_knmi(
locations=obsc, meteo_vars=["EV24", "RD"], starts="2010", ends="2015"
locations=obsc,
meteo_vars=["EV24", "RD"],
starts="2010",
ends="2015",
raise_exceptions=False,
)
except ConnectionError:
pass
Expand Down

0 comments on commit 02214a0

Please sign in to comment.