Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix range formatting #89

Merged
merged 5 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ecologits/impacts/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion ecologits/impacts/modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ecologits/model_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from pydantic import BaseModel

from ecologits.range_value import ValueOrRange
from ecologits.utils.range_value import ValueOrRange


class Providers(Enum):
Expand Down
Empty file added ecologits/utils/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions ecologits/range_value.py → ecologits/utils/range_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
2 changes: 1 addition & 1 deletion tests/test_modeling_impacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 10 additions & 0 deletions tests/test_range_value.py
Original file line number Diff line number Diff line change
@@ -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
Loading