-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
192 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ Changelog | |
Development | ||
*********** | ||
|
||
- Fix DWD DMO again | ||
|
||
0.65.0 (24.10.2023) | ||
******************* | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright (C) 2018-2023, earthobservations developers. | ||
# Distributed under the MIT License. See LICENSE for more info. | ||
import datetime as dt | ||
|
||
import polars as pl | ||
import pytest | ||
|
||
from wetterdienst.provider.dwd.dmo import DwdDmoRequest | ||
from wetterdienst.provider.dwd.dmo.api import add_date_from_filename | ||
|
||
|
||
@pytest.fixture | ||
def df_files_january(): | ||
return pl.DataFrame( | ||
{ | ||
"date_str": [ | ||
"310000", | ||
"311200", | ||
] | ||
} | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def df_files_two_month(): | ||
return pl.DataFrame( | ||
{ | ||
"date_str": [ | ||
"311200", | ||
"010000", | ||
"011200", | ||
"020000", | ||
] | ||
} | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def df_files_end_of_month(): | ||
return pl.DataFrame( | ||
{ | ||
"date_str": [ | ||
"310000", | ||
"311200", | ||
] | ||
} | ||
) | ||
|
||
|
||
@pytest.mark.remote | ||
def test_dwd_dmo_stations(default_settings): | ||
# Acquire data. | ||
stations = DwdDmoRequest(parameter="icon", dmo_type="icon", settings=default_settings) | ||
given_df = stations.all().df | ||
assert not given_df.is_empty() | ||
assert given_df.select(pl.all().max()).to_dicts()[0] == { | ||
"from_date": None, | ||
"height": 4670.0, | ||
"icao_id": "ZYTX", | ||
"latitude": 79.59, | ||
"longitude": 179.2, | ||
"name": "ZWOENITZ", | ||
"state": None, | ||
"station_id": "Z949", | ||
"to_date": None, | ||
} | ||
assert given_df.select(pl.all().min()).to_dicts()[0] == { | ||
"from_date": None, | ||
"height": -350.0, | ||
"icao_id": "AFDU", | ||
"latitude": -78.27, | ||
"longitude": -176.1, | ||
"name": "16N55W", | ||
"state": None, | ||
"station_id": "01001", | ||
"to_date": None, | ||
} | ||
station_names_sorted = given_df.sort(pl.col("name").str.n_chars()).get_column("name").to_list() | ||
assert station_names_sorted[:5] == ["ELM", "PAU", "SAL", "AUE", "HOF"] | ||
assert station_names_sorted[-5:] == [ | ||
"MÜNSINGEN-APFELSTETT", | ||
"VILLINGEN-SCHWENNING", | ||
"WEINGARTEN BEI RAVEN", | ||
"LONDON WEATHER CENT.", | ||
"QUITO/MARISCAL SUCRE", | ||
] | ||
|
||
|
||
def test_add_date_from_filename(df_files_two_month): | ||
df = add_date_from_filename(df_files_two_month, dt.datetime(2021, 11, 15)) | ||
assert df.get_column("date").to_list() == [ | ||
dt.datetime(2021, 10, 31, 12, 0), | ||
dt.datetime(2021, 11, 1, 0, 0), | ||
dt.datetime(2021, 11, 1, 12, 0), | ||
dt.datetime(2021, 11, 2, 0, 0), | ||
] | ||
|
||
|
||
def test_add_date_from_filename_early_in_month(df_files_end_of_month): | ||
df = add_date_from_filename(df_files_end_of_month, dt.datetime(2021, 11, 1, 2)) | ||
assert df.get_column("date").to_list() == [ | ||
dt.datetime(2021, 10, 31, 0, 0, 0), | ||
dt.datetime(2021, 10, 31, 12, 0, 0), | ||
] | ||
|
||
|
||
def test_add_date_from_filename_early_in_year(df_files_january): | ||
df = add_date_from_filename(df_files_january, dt.datetime(2021, 1, 1, 1, 1, 1)) | ||
assert df.get_column("date").to_list() == [ | ||
dt.datetime(2020, 12, 31, 0, 0, 0), | ||
dt.datetime(2020, 12, 31, 12, 0, 0), | ||
] | ||
|
||
|
||
def test_add_date_from_filename_too_few_dates(): | ||
df = pl.DataFrame( | ||
{ | ||
"date_str": [ | ||
"311200", | ||
] | ||
} | ||
) | ||
with pytest.raises(ValueError): | ||
add_date_from_filename(df, dt.datetime(2021, 1, 1, 1, 1, 1)) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters