From e55b8e8178aa2ededd08c445c7432247116f8fc2 Mon Sep 17 00:00:00 2001 From: Benjamin Gutzmann Date: Sat, 9 Mar 2024 12:12:58 +0100 Subject: [PATCH] Cli/Restapi: Return empty values if no data is available --- CHANGELOG.rst | 1 + tests/ui/test_restapi.py | 17 +++++++++++++++++ wetterdienst/ui/core.py | 17 +++++++++++------ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 98a3c4f5a..1778ff96d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,7 @@ Development *********** - Docker: Install more extras +- Cli/Restapi: Return empty values if no data is available 0.77.1 (08.03.2024) ******************* diff --git a/tests/ui/test_restapi.py b/tests/ui/test_restapi.py index a977db6ae..04f57043f 100644 --- a/tests/ui/test_restapi.py +++ b/tests/ui/test_restapi.py @@ -407,6 +407,23 @@ def test_api_values_missing_null(client): assert response.json()["values"][0]["quality"] is None +@pytest.mark.remote +def test_api_values_missing_empty(client): + response = client.get( + "/api/values", + params={ + "provider": "dwd", + "network": "observation", + "station": "00011", + "parameter": "precipitation_height", + "resolution": "1_minute", + "period": "recent", + }, + ) + assert response.status_code == 200 + assert not response.json()["values"] + + @pytest.mark.remote def test_api_stations_missing_null(client): response = client.get( diff --git a/wetterdienst/ui/core.py b/wetterdienst/ui/core.py index af4d64c6c..83189b043 100644 --- a/wetterdienst/ui/core.py +++ b/wetterdienst/ui/core.py @@ -7,7 +7,12 @@ from wetterdienst.core.process import create_date_range from wetterdienst.core.timeseries.request import TimeseriesRequest -from wetterdienst.core.timeseries.result import StationsResult, ValuesResult +from wetterdienst.core.timeseries.result import ( + InterpolatedValuesResult, + StationsResult, + SummarizedValuesResult, + ValuesResult, +) from wetterdienst.metadata.datarange import DataRange from wetterdienst.metadata.period import PeriodType from wetterdienst.metadata.resolution import Resolution, ResolutionType @@ -285,7 +290,7 @@ def get_values( else: if values_.df.is_empty(): log.error("No data available for given constraints") - sys.exit(1) + return values_ if sql_values: log.info(f"Filtering with SQL: {sql_values}") @@ -309,7 +314,7 @@ def get_interpolate( si_units: bool, humanize: bool, use_nearby_station_distance: float, -) -> ValuesResult: +) -> InterpolatedValuesResult: """Core function for querying values via cli and restapi""" r = _get_stations_request( api=api, @@ -341,7 +346,7 @@ def get_interpolate( else: if values_.df.is_empty(): log.error("No data available for given constraints") - sys.exit(1) + return values_ if sql_values: log.info(f"Filtering with SQL: {sql_values}") @@ -363,7 +368,7 @@ def get_summarize( sql_values: str, si_units: bool, humanize: bool, -) -> ValuesResult: +) -> SummarizedValuesResult: """Core function for querying values via cli and restapi""" r = _get_stations_request( api=api, @@ -395,7 +400,7 @@ def get_summarize( else: if values_.df.is_empty(): log.error("No data available for given constraints") - sys.exit(1) + return values_ if sql_values: log.info(f"Filtering with SQL: {sql_values}")