Skip to content

Commit

Permalink
Adjust type of ChemicalFormulaFeaturizer.powers.
Browse files Browse the repository at this point in the history
The backend is opening up the type of powers to be floats. As such, this
commit will deserialize powers as a list of floats. However, to preserve
backwards compatability, the type of powers will be preserved, and a
new field (powers_float) with the list as floats is introduced. In
v4.0.0, the type of 'powers' will be changed, and 'powers_float' will be
deprecated before its removal in v5.0.0.
  • Loading branch information
anoto-moniz committed Sep 18, 2024
1 parent 9e15919 commit a812f20
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/citrine/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "3.5.4"
__version__ = "3.6.0"
23 changes: 21 additions & 2 deletions src/citrine/informatics/predictors/chemical_formula_featurizer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import List, Optional
from typing import List, Optional, Union
from warnings import warn

from citrine._rest.resource import Resource
from citrine._serialization import properties
Expand Down Expand Up @@ -133,7 +134,7 @@ class ChemicalFormulaFeaturizer(Resource["ChemicalFormulaFeaturizer"], Predictor
input_descriptor = properties.Object(ChemicalFormulaDescriptor, 'input')
features = properties.List(properties.String, 'features')
excludes = properties.List(properties.String, 'excludes', default=[])
powers = properties.List(properties.Integer, 'powers')
_powers = properties.List(properties.Float, 'powers')

typ = properties.String('type', default='ChemicalFormulaFeaturizer', deserializable=False)

Expand All @@ -152,5 +153,23 @@ def __init__(self,
self.excludes = excludes if excludes is not None else []
self.powers = powers if powers is not None else [1]

@property
def powers(self) -> List[int]:
"""The list of powers when computing generalized weighted means of element properties."""
warn("The type of 'powers' will change to a list of floats in v4.0.0. To retrieve them as "
"floats now, use 'powers_float'.")
return [int(p) for p in self._powers]

@powers.setter
def powers(self, value: List[Union[int, float]]):
self._powers = value

@property
def powers_float(self) -> List[float]:
"""Powers when computing generalized weighted means of element properties."""
warn("'powers_float' will be deprecated in v4.0.0 for 'powers', and removed in v5.0.0",
PendingDeprecationWarning)
return self._powers

def __str__(self):
return '<ChemicalFormulaFeaturizer {!r}>'.format(self.name)
5 changes: 4 additions & 1 deletion tests/informatics/test_predictors.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,10 @@ def test_chemical_featurizer(chemical_featurizer):
assert chemical_featurizer.input_descriptor == ChemicalFormulaDescriptor("formula")
assert chemical_featurizer.features == ["standard"]
assert chemical_featurizer.excludes == []
assert chemical_featurizer.powers == [1, 2]
with pytest.warns(UserWarning):
assert chemical_featurizer.powers == [1, 2]
with pytest.warns(PendingDeprecationWarning):
assert chemical_featurizer.powers_float == [1.0, 2.0]

assert str(chemical_featurizer) == "<ChemicalFormulaFeaturizer 'Chemical featurizer'>"

Expand Down

0 comments on commit a812f20

Please sign in to comment.