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 1 commit
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
Next Next commit
fix: range can now be included in f-strings
  • Loading branch information
NP4567-dev committed Nov 6, 2024
commit 8712eb023a2e52c2c441e8ee6955c764af288a1c
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
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
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