Skip to content

Commit

Permalink
Fixed invalid Composition values
Browse files Browse the repository at this point in the history
Rewritten the validation of compositions, should fix inability to model processes and curves, which finished at invalid compositions. Added version attribute to init.
  • Loading branch information
Membrizard committed Dec 2, 2022
1 parent b13248b commit 9b4d0d0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 2 additions & 0 deletions pyvaporation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,5 @@
"Component",
"Components",
]

__version__ = "1.1.6"
13 changes: 7 additions & 6 deletions pyvaporation/mixtures/mixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
from ..utils import NRTLParameters, R


def _is_in_0_to_1_range(instance: typing.Any, attribute, value: float) -> None:
if not 0 <= value <= 1:
raise ValueError("Give %s value is not in [0, 1] range" % value)


class CompositionType:
"""
A class to describe type of the composition
Expand Down Expand Up @@ -39,9 +34,15 @@ class Composition:
A class to represent composition of the mixtures
"""

p: float = attr.ib(validator=_is_in_0_to_1_range)
p: float
type: str

def __attrs_post_init__(self):
if self.p < 0:
self.p = 0
if self.p > 1:
self.p = 1

@property
def first(self) -> float:
"""
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
setup(
name="pyvaporation",
packages=find_packages(),
version="1.1.5",
version="1.1.6",
license="Apache license 2.0",
description="Set of tools for modelling pervaporation processes",
author="Denis Sapegin, Aleksei Chekmachev",
author_email="a.checkmachev@gmail.com",
author_email="dasapegin@sr-systems.ru",
url="https://github.com/Membrizard/PyVaporation",
download_url="https://github.com/Membrizard/PyVaporation/archive/refs/tags/v1.1.5.tar.gz",
long_description=open("README.md", "r").read(),
Expand Down
5 changes: 5 additions & 0 deletions tests/test_mixtures/test_mixture_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,8 @@ def test_get_nrtl_partial_pressures_from_weight_composition():
)
< 1e-3
)


def test_invalid_compositions():
assert Composition(p=-1, type="weight") == Composition(p=0, type="weight")
assert Composition(p=2, type="weight") == Composition(p=1, type="weight")

0 comments on commit 9b4d0d0

Please sign in to comment.