Skip to content

Commit 6a6f5a4

Browse files
committed
Date filtering adjusted to include up to end_date
1 parent f328a51 commit 6a6f5a4

File tree

4 files changed

+8
-11
lines changed

4 files changed

+8
-11
lines changed

pyngeso/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from .pyngeso import NgEso
22

3-
__version__ = '0.1.1'
3+
__version__ = '0.2.0'

pyngeso/pyngeso.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,14 @@ def construct_date_range(
9191
raise ValueError("At least one of {start_date,end_date} should be provided")
9292
if all(dates_provided):
9393
self.validate_date_range(start_date, end_date)
94-
# add 1 day to end_date as casting as timestamp rounds it down to midnight
95-
if end_date:
96-
end_date = datetime.strptime(end_date, "%Y-%m-%d") + timedelta(days=1)
9794

9895
date_range_map = {
99-
(True, False): f"where \"{date_col}\" > '{start_date}'::timestamp",
96+
(True, False): f"where \"{date_col}\" >= '{start_date}'::timestamp",
10097
(False, True): f"where \"{date_col}\" < '{end_date}'::timestamp",
10198
(
10299
True,
103100
True,
104-
): f"where \"{date_col}\" between '{start_date}'::timestamp "
101+
): f"where \"{date_col}\" BETWEEN '{start_date}'::timestamp "
105102
f"and '{end_date}'::timestamp",
106103
}
107104
date_filter_sql = date_range_map.get(dates_provided)

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pyngeso"
3-
version = "0.1.1"
3+
version = "0.2.0"
44
description = "Simple python wrapper for the National Grid ESO Portal"
55
authors = ["atsangarides <[email protected]>"]
66
license = "MIT"

tests/test_pyngeso.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
@pytest.mark.vcr
1111
def test_day_ahead_historic_forecast():
12-
start_date = "2018-01-01"
12+
start_date = "2018-01-02"
1313
end_date = "2018-01-02"
1414
client = NgEso("historic-day-ahead-demand-forecast")
1515
r = client.query(date_col="TARGETDATE", start_date=start_date, end_date=end_date)
@@ -20,7 +20,7 @@ def test_day_ahead_historic_forecast():
2020
assert isinstance(records, list)
2121
assert len(records) > 0
2222
unique_target_dates = set([record.get("TARGETDATE") for record in records])
23-
assert len(unique_target_dates) == 2
23+
assert len(unique_target_dates) == 1
2424

2525

2626
@pytest.mark.vcr
@@ -42,7 +42,7 @@ def test_day_ahead_historic_forecast_missing_data_warning(caplog):
4242
@pytest.mark.vcr
4343
def test_2day_ahead_historic_forecast():
4444
start_date = "2018-03-30"
45-
end_date = "2018-03-31"
45+
end_date = "2018-03-30"
4646
client = NgEso("historic-2day-ahead-demand-forecast")
4747
r = client.query(date_col="TARGETDATE", start_date=start_date, end_date=end_date)
4848

@@ -52,4 +52,4 @@ def test_2day_ahead_historic_forecast():
5252
assert isinstance(records, list)
5353
assert len(records) > 0
5454
unique_target_dates = set([record.get("TARGETDATE") for record in records])
55-
assert len(unique_target_dates) == 2
55+
assert len(unique_target_dates) == 1

0 commit comments

Comments
 (0)