forked from earthobservations/wetterdienst
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve command line interface for monthly and annual data
This adds some DWIM-magic to improve behaviour when acquiring data from the monthly and annual time resolutions. It is mostly about appropriate time range floor/ceil computations but also adds the respective names for DATE_FROM and DATE_TO columns within monthly and annual data.
- Loading branch information
Showing
7 changed files
with
102 additions
and
5 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
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
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
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 |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
|
||
|
||
class StartDateEndDateError(Exception): | ||
print("Error: 'start_date' must be smaller or equal to 'end_date'.") | ||
pass |
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,30 @@ | ||
import pytest | ||
from dateparser import parse as parsedate | ||
from pandas import Timestamp | ||
|
||
from python_dwd.additionals.time_handling import mktimerange | ||
from python_dwd.enumerations.time_resolution_enumeration import TimeResolution | ||
|
||
|
||
def test_mktimerange_annual(): | ||
|
||
assert mktimerange(TimeResolution.ANNUAL, parsedate('2019')) == \ | ||
(Timestamp('2019-01-01 00:00:00'), Timestamp('2019-12-31 00:00:00')) | ||
|
||
assert mktimerange(TimeResolution.ANNUAL, parsedate('2010'), parsedate('2020')) == \ | ||
(Timestamp('2010-01-01 00:00:00'), Timestamp('2020-12-31 00:00:00')) | ||
|
||
|
||
def test_mktimerange_monthly(): | ||
|
||
assert mktimerange(TimeResolution.MONTHLY, parsedate('2020-05')) == \ | ||
(Timestamp('2020-05-01 00:00:00'), Timestamp('2020-05-31 00:00:00')) | ||
|
||
assert mktimerange(TimeResolution.MONTHLY, parsedate('2017-01'), parsedate('2019-12')) == \ | ||
(Timestamp('2017-01-01 00:00:00'), Timestamp('2019-12-31 00:00:00')) | ||
|
||
|
||
def test_mktimerange_invalid(): | ||
|
||
with pytest.raises(NotImplementedError): | ||
mktimerange(TimeResolution.DAILY, parsedate('2020-05-01')) |