diff --git a/ecologits/impacts/llm.py b/ecologits/impacts/llm.py index f403d30a..52add327 100644 --- a/ecologits/impacts/llm.py +++ b/ecologits/impacts/llm.py @@ -4,7 +4,7 @@ from ecologits.impacts.dag import DAG from ecologits.impacts.modeling import GWP, PE, ADPe, Embodied, Energy, Impacts, Usage -from ecologits.range_value import RangeValue, ValueOrRange +from ecologits.utils.range_value import RangeValue, ValueOrRange MODEL_QUANTIZATION_BITS = 4 diff --git a/ecologits/impacts/modeling.py b/ecologits/impacts/modeling.py index 2d35a36b..af114be1 100644 --- a/ecologits/impacts/modeling.py +++ b/ecologits/impacts/modeling.py @@ -3,7 +3,7 @@ from pydantic import BaseModel from ecologits.exceptions import ModelingError -from ecologits.range_value import ValueOrRange +from ecologits.utils.range_value import ValueOrRange @total_ordering diff --git a/ecologits/model_repository.py b/ecologits/model_repository.py index 87ffba8d..d4c1bd36 100644 --- a/ecologits/model_repository.py +++ b/ecologits/model_repository.py @@ -5,7 +5,7 @@ from pydantic import BaseModel -from ecologits.range_value import ValueOrRange +from ecologits.utils.range_value import ValueOrRange class Providers(Enum): diff --git a/ecologits/utils/__init__.py b/ecologits/utils/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/ecologits/range_value.py b/ecologits/utils/range_value.py similarity index 93% rename from ecologits/range_value.py rename to ecologits/utils/range_value.py index 9d385fbc..3229cec9 100644 --- a/ecologits/range_value.py +++ b/ecologits/utils/range_value.py @@ -63,5 +63,10 @@ def __gt__(self, other: Any) -> bool: else: return self.min > other + def __format__(self,format_spec:str)-> str: + return f"{format(self.min,format_spec)} to {format(self.max,format_spec)}" + + + ValueOrRange = Union[int, float, RangeValue] diff --git a/tests/test_modeling_impacts.py b/tests/test_modeling_impacts.py index 3205bfc4..59b9bf12 100644 --- a/tests/test_modeling_impacts.py +++ b/tests/test_modeling_impacts.py @@ -4,7 +4,7 @@ from ecologits.impacts.modeling import Impact, Energy, GWP, ADPe, PE from ecologits.exceptions import ModelingError -from ecologits.range_value import RangeValue +from ecologits.utils.range_value import RangeValue impact_config = dict( diff --git a/tests/test_range_value.py b/tests/test_range_value.py new file mode 100644 index 00000000..55c02a18 --- /dev/null +++ b/tests/test_range_value.py @@ -0,0 +1,10 @@ +from ecologits.utils.range_value import RangeValue + + +def test_range_formats_ok(): + + range = RangeValue(min =0.00000006, max=0.00008) + + expected = f"{range.min:.2f} to {range.max:.2f}" + + assert f"{range:.2f}" == expected \ No newline at end of file