From 0891e7eaa9d11dad394ef2088931d22e70dd4a51 Mon Sep 17 00:00:00 2001 From: Francesc Ortiz Date: Thu, 18 Nov 2021 12:40:46 +0100 Subject: [PATCH 1/2] Don't pollute stdout in order to allow creating CLI tools that use this library. --- entsoe/decorators.py | 5 +++-- entsoe/parsers.py | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/entsoe/decorators.py b/entsoe/decorators.py index 0d51aff..b657f47 100644 --- a/entsoe/decorators.py +++ b/entsoe/decorators.py @@ -1,3 +1,4 @@ +import sys from socket import gaierror from time import sleep import requests @@ -22,7 +23,7 @@ def retry_wrapper(*args, **kwargs): except (requests.ConnectionError, gaierror) as e: error = e print("Connection Error, retrying in {} seconds".format( - self.retry_delay)) + self.retry_delay), file=sys.stderr) sleep(self.retry_delay) continue else: @@ -90,7 +91,7 @@ def day_wrapper(*args, start, end, **kwargs): try: frame = func(*args, start=_start, end=_end, **kwargs) except NoMatchingDataError: - print(f"NoMatchingDataError: between {_start} and {_end}") + print(f"NoMatchingDataError: between {_start} and {_end}", file=sys.stderr) frame = None frames.append(frame) diff --git a/entsoe/parsers.py b/entsoe/parsers.py index 27bde45..7294392 100644 --- a/entsoe/parsers.py +++ b/entsoe/parsers.py @@ -1,3 +1,4 @@ +import sys import zipfile from io import BytesIO from typing import Union @@ -357,7 +358,7 @@ def _parse_contracted_reserve_series(soup, tz, label): df.sort_index(inplace=True) index = _parse_datetimeindex(soup, tz) if len(index) > len(df.index): - print("Shortening index") + print("Shortening index", file=sys.stderr) df.index = index[:len(df.index)] else: df.index = index From fb1fb46923831068a90263210aa2ab9227e060e1 Mon Sep 17 00:00:00 2001 From: Francesc Ortiz Date: Thu, 18 Nov 2021 12:41:28 +0100 Subject: [PATCH 2/2] Update tests because 2 calls now return pd.DataFrame instead of pd.Series. --- tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests.py b/tests.py index 7976c97..d961239 100644 --- a/tests.py +++ b/tests.py @@ -92,8 +92,6 @@ def test_basic_queries(self): def test_basic_series(self): queries = [ self.client.query_day_ahead_prices, - self.client.query_load, - self.client.query_load_forecast, self.client.query_generation_forecast, self.client.query_net_position_dayahead ] @@ -110,6 +108,8 @@ def query_crossborder_flows(self): def test_basic_dataframes(self): queries = [ + self.client.query_load, + self.client.query_load_forecast, self.client.query_wind_and_solar_forecast, self.client.query_generation, self.client.query_installed_generation_capacity,