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 3 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
4 changes: 2 additions & 2 deletions ecologits/_ecologits.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

from packaging.version import Version

from ecologits.exceptions import EcoLogitsError
from ecologits.log import logger
from ecologits.utils.exceptions import EcoLogitsError
from ecologits.utils.log import logger


def init_openai_instrumentor() -> None:
Expand Down
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
4 changes: 2 additions & 2 deletions ecologits/impacts/modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from pydantic import BaseModel

from ecologits.exceptions import ModelingError
from ecologits.range_value import ValueOrRange
from ecologits.utils.exceptions import ModelingError
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
2 changes: 1 addition & 1 deletion ecologits/tracers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from ecologits.electricity_mix_repository import electricity_mixes
from ecologits.impacts.llm import compute_llm_impacts
from ecologits.impacts.modeling import Impacts
from ecologits.log import logger
from ecologits.model_repository import ArchitectureTypes, models
from ecologits.utils.log import logger


def _avg(value_range: tuple) -> float:
Expand Down
Empty file added ecologits/utils/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
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]
4 changes: 2 additions & 2 deletions tests/test_modeling_impacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import pytest

from ecologits.impacts.modeling import Impact, Energy, GWP, ADPe, PE
from ecologits.exceptions import ModelingError
from ecologits.range_value import RangeValue
from ecologits.utils.exceptions import ModelingError
from ecologits.utils.range_value import RangeValue


impact_config = dict(
Expand Down
Empty file added tests/utils/__init__.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the directory utils/ in tests/

Empty file.
10 changes: 10 additions & 0 deletions tests/utils/range_value.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move the test file to tests/ directory and rename to 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