From 8af6b3e8f0533f2537564154bb23c42a25655d91 Mon Sep 17 00:00:00 2001 From: Carsten Hinz <c.hinz@fz-juelich.de> Date: Thu, 2 May 2024 09:05:01 +0200 Subject: [PATCH] bug fix. In dataclass attributes with an explicit setter to restrict the valid parameters are treated as having a default value by python changed constructor of MetaData --- .vscode/settings.json | 5 +++++ tests/benchmark.py | 2 +- tests/conftest.py | 2 +- toargridding/gridding.py | 2 +- toargridding/metadata.py | 13 ++++++------- 5 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..b9e9926 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "cSpell.words": [ + "timeseries" + ] +} \ No newline at end of file diff --git a/tests/benchmark.py b/tests/benchmark.py index bbeca43..7390b17 100644 --- a/tests/benchmark.py +++ b/tests/benchmark.py @@ -81,7 +81,7 @@ def time_rest_client_response(start, end): use_downloaded=False, ) time_window = TimeSample(start, end, SAMPLING) - sample = Metadata.construct("mole_fraction_of_ozone_in_air", STATISTIC, time_window) + sample = Metadata.construct("mole_fraction_of_ozone_in_air", time_window, STATISTIC) timer_start = datetime.now() wait_for_client_response(rest_client, sample) diff --git a/tests/conftest.py b/tests/conftest.py index 5e9ca92..4b58914 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -44,7 +44,7 @@ def toar_variable_ozon(): @pytest.fixture def metadata_ozone_mean(toar_variable_ozon, time): - return Metadata(toar_variable_ozon, "mean", time) + return Metadata(toar_variable_ozon, time, "mean") def load_local_data(*args, **kwargs): diff --git a/toargridding/gridding.py b/toargridding/gridding.py index 3b6ab36..be6b552 100644 --- a/toargridding/gridding.py +++ b/toargridding/gridding.py @@ -40,7 +40,7 @@ def get_gridded_toar_data( """ metadatas = [ - Metadata.construct(var, stat, time) for var, stat in product(variables, stats) + Metadata.construct(var, time, stat) for var, stat in product(variables, stats) ] datasets = [] diff --git a/toargridding/metadata.py b/toargridding/metadata.py index d1d83d2..ac2bae5 100644 --- a/toargridding/metadata.py +++ b/toargridding/metadata.py @@ -88,18 +88,17 @@ class Metadata: ---------- variable: support variable of the TOAR data base - statistics: - statistical processing applied by the TOAR database for this request time: requested time points + statistics: + statistical processing applied by the TOAR database for this request """ - variable: TOARVariable - statistic: str time: TimeSample + statistic: str @staticmethod - def construct(standart_name: str, stat: str, time: TimeSample): + def construct(standart_name: str, time: TimeSample, stat: str): """constructor Parameters: @@ -115,7 +114,7 @@ class Metadata: variable = TOARVariable.get(standart_name) - return Metadata(variable, stat, time) + return Metadata(variable, time, stat) @property def statistic(self) -> str: # TODO make better @@ -127,7 +126,7 @@ class Metadata: return self._statistic @statistic.setter - def statistics(self, stat : str): + def statistic(self, stat : str): if stat not in STATISTICS_LIST: raise ValueError(f"invalid statistic: {stat}") self._statistic = stat -- GitLab