diff options
| author | Павел Жуков <33721692+LeaveMyYard@users.noreply.github.com> | 2023-05-11 17:18:29 +0300 |
|---|---|---|
| committer | Павел Жуков <33721692+LeaveMyYard@users.noreply.github.com> | 2023-05-11 17:18:29 +0300 |
| commit | 08f5471dd9977254ca9e1a461dbab9126e20fa7e (patch) | |
| tree | 31919b24ddf97e3d85adf8c84a795c4c5b28ae10 | |
| parent | a5deea864ae9622f20a376a42227aa21978f86af (diff) | |
Minor typing fixes & improvements
| -rw-r--r-- | robusta_krr/core/models/allocations.py | 5 | ||||
| -rw-r--r-- | robusta_krr/core/runner.py | 1 | ||||
| -rw-r--r-- | robusta_krr/strategies/simple.py | 4 | ||||
| -rw-r--r-- | robusta_krr/utils/resource_units.py | 6 |
4 files changed, 9 insertions, 7 deletions
diff --git a/robusta_krr/core/models/allocations.py b/robusta_krr/core/models/allocations.py index e3e0e14..1d1a272 100644 --- a/robusta_krr/core/models/allocations.py +++ b/robusta_krr/core/models/allocations.py @@ -21,6 +21,7 @@ class ResourceType(str, enum.Enum): RecommendationValue = Union[float, Literal["?"], None] +RecommendationValueRaw = Union[float, str, None] Self = TypeVar("Self", bound="ResourceAllocations") @@ -30,7 +31,7 @@ class ResourceAllocations(pd.BaseModel): limits: dict[ResourceType, RecommendationValue] @staticmethod - def __parse_resource_value(value: float | str | None) -> RecommendationValue: + def __parse_resource_value(value: RecommendationValueRaw) -> RecommendationValue: if value is None: return None @@ -44,7 +45,7 @@ class ResourceAllocations(pd.BaseModel): @pd.validator("requests", "limits", pre=True) def validate_requests( - cls, value: dict[ResourceType, float | str | None] + cls, value: dict[ResourceType, RecommendationValueRaw] ) -> dict[ResourceType, RecommendationValue]: return { resource_type: cls.__parse_resource_value(resource_value) for resource_type, resource_value in value.items() diff --git a/robusta_krr/core/runner.py b/robusta_krr/core/runner.py index 7246ae4..5ac6d15 100644 --- a/robusta_krr/core/runner.py +++ b/robusta_krr/core/runner.py @@ -57,6 +57,7 @@ class Runner(Configurable): if value is None or math.isnan(value): return value + prec_power: Union[float, int] if resource == ResourceType.CPU: # NOTE: We use 10**3 as the minimal value for CPU is 1m prec_power = 10**3 diff --git a/robusta_krr/strategies/simple.py b/robusta_krr/strategies/simple.py index b8fa8d9..aaf31d7 100644 --- a/robusta_krr/strategies/simple.py +++ b/robusta_krr/strategies/simple.py @@ -26,7 +26,7 @@ class SimpleStrategySettings(StrategySettings): if len(data_) == 0: return float("NaN") - return float(max(data_) * (1 + self.memory_buffer_percentage / 100)) + return max(data_) * (1 + self.memory_buffer_percentage / 100) def calculate_cpu_proposal(self, data: dict[str, NDArray[np.float64]]) -> float: if len(data) == 0: @@ -37,7 +37,7 @@ class SimpleStrategySettings(StrategySettings): else: data_ = list(data.values())[0][:, 1] - return float(np.percentile(data_, self.cpu_percentile)) + return np.percentile(data_, self.cpu_percentile) class SimpleStrategy(BaseStrategy[SimpleStrategySettings]): diff --git a/robusta_krr/utils/resource_units.py b/robusta_krr/utils/resource_units.py index cf61df7..5b33601 100644 --- a/robusta_krr/utils/resource_units.py +++ b/robusta_krr/utils/resource_units.py @@ -1,4 +1,4 @@ -from typing import Literal +from typing import Literal, Union UNITS = { "m": 0.001, @@ -17,7 +17,7 @@ UNITS = { } -def parse(x: str, /) -> float | int: +def parse(x: str, /) -> Union[float, int]: """Converts a string to an integer with respect of units.""" for unit, multiplier in UNITS.items(): @@ -37,7 +37,7 @@ def get_base(x: str, /) -> Literal[1024, 1000]: return 1000 if "." in x else 1024 -def format(x: float | int, /, *, base: Literal[1024, 1000] = 1024) -> str: +def format(x: Union[float, int], /, *, base: Literal[1024, 1000] = 1024) -> str: """Converts an integer to a string with respect of units.""" if x < 1: |
