Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cli/Restapi: Return empty values if no data is available #1243

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*******************
Expand Down
17 changes: 17 additions & 0 deletions tests/ui/test_restapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
17 changes: 11 additions & 6 deletions wetterdienst/ui/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}")
Expand All @@ -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,
Expand Down Expand Up @@ -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}")
Expand All @@ -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,
Expand Down Expand Up @@ -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}")
Expand Down
Loading