From c3dc21b1d28393b67b44ca3341f685a46e54a512 Mon Sep 17 00:00:00 2001 From: mKlapwijk Date: Tue, 21 Nov 2023 14:22:23 +0100 Subject: [PATCH] Revert "Fix default arguments = [] change to None" This reverts commit 9edf5c7014f426657e3a22fc513c772465c70150. --- decoimpact/business/entities/rules/multiply_rule.py | 8 ++++---- decoimpact/data/entities/multiply_rule_data.py | 4 ++-- tests/business/entities/rules/test_multiply_rule.py | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/decoimpact/business/entities/rules/multiply_rule.py b/decoimpact/business/entities/rules/multiply_rule.py index 8a753163..6aab02b6 100644 --- a/decoimpact/business/entities/rules/multiply_rule.py +++ b/decoimpact/business/entities/rules/multiply_rule.py @@ -12,7 +12,7 @@ """ from datetime import datetime as _dt -from typing import List, Optional +from typing import List import numpy as _np import xarray as _xr @@ -31,7 +31,7 @@ def __init__( input_variable_names: List[str], multipliers: List[List[float]], output_variable_name: str = "output", - date_range: Optional[List[List[str]]] = None, + date_range: List[List[str]] = [], description: str = "", ): super().__init__(name, input_variable_names, output_variable_name, description) @@ -44,7 +44,7 @@ def multipliers(self) -> List[List[float]]: return self._multipliers @property - def date_range(self) -> Optional[List[List[str]]]: + def date_range(self) -> List[List[str]]: """Date range property""" return self._date_range @@ -64,7 +64,7 @@ def execute(self, value_array: _xr.DataArray, logger: ILogger) -> _xr.DataArray: old_dr = _xr.DataArray(value_array) new_dr = _xr.full_like(old_dr, _np.nan) for (index, _mp) in enumerate(result_multipliers): - if self.date_range is not None: + if len(self.date_range) != 0: # Date is given in DD-MM, convert to MM-DD for comparison start = self._convert_datestr(self.date_range[index][0]) end = self._convert_datestr(self.date_range[index][1]) diff --git a/decoimpact/data/entities/multiply_rule_data.py b/decoimpact/data/entities/multiply_rule_data.py index 9848b428..22055e5c 100644 --- a/decoimpact/data/entities/multiply_rule_data.py +++ b/decoimpact/data/entities/multiply_rule_data.py @@ -12,7 +12,7 @@ """ -from typing import List, Optional +from typing import List from decoimpact.data.api.i_multiply_rule_data import IMultiplyRuleData from decoimpact.data.entities.rule_data import RuleData @@ -28,7 +28,7 @@ def __init__( input_variable: str, output_variable: str = "output", description: str = "", - date_range: Optional[List[List[str]]] = None, + date_range: List[List[str]] = [], ): super().__init__(name, output_variable, description) self._input_variable = input_variable diff --git a/tests/business/entities/rules/test_multiply_rule.py b/tests/business/entities/rules/test_multiply_rule.py index 1205c9b3..e24f0fa4 100644 --- a/tests/business/entities/rules/test_multiply_rule.py +++ b/tests/business/entities/rules/test_multiply_rule.py @@ -11,8 +11,8 @@ from unittest.mock import Mock -import numpy as _np import xarray as _xr +import numpy as _np from decoimpact.business.entities.rules.multiply_rule import MultiplyRule from decoimpact.crosscutting.i_logger import ILogger @@ -29,7 +29,7 @@ def test_create_multiply_rule_should_set_defaults(): assert rule.input_variable_names == ["foo"] assert rule.output_variable_name == "output" assert rule.multipliers == [[0.5, 3.0]] - assert rule.date_range == None + assert rule.date_range == [] assert isinstance(rule, MultiplyRule)