Skip to content

Commit 94d1622

Browse files
committed
Adjust type of ChemicalFormulaFeaturizer.powers.
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.
1 parent 9e15919 commit 94d1622

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

src/citrine/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.5.4"
1+
__version__ = "3.6.0"

src/citrine/informatics/predictors/chemical_formula_featurizer.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import List, Optional
2+
from warnings import warn
23

34
from citrine._rest.resource import Resource
45
from citrine._serialization import properties
@@ -133,7 +134,7 @@ class ChemicalFormulaFeaturizer(Resource["ChemicalFormulaFeaturizer"], Predictor
133134
input_descriptor = properties.Object(ChemicalFormulaDescriptor, 'input')
134135
features = properties.List(properties.String, 'features')
135136
excludes = properties.List(properties.String, 'excludes', default=[])
136-
powers = properties.List(properties.Integer, 'powers')
137+
_powers = properties.List(properties.Float, 'powers')
137138

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

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

156+
@property
157+
def powers(self) -> List[int]:
158+
"""The list of powers when computing generalized weighted means of element properties."""
159+
warn("The type of 'powers' will change to a list of floats in v4.0.0. To retrieve them as "
160+
"floats now, use 'powers_float'.")
161+
return [int(p) for p in self._powers]
162+
163+
@powers.setter
164+
def powers(self, value: List[int | float]):
165+
self._powers = value
166+
167+
@property
168+
def powers_float(self) -> List[float]:
169+
"""Powers when computing generalized weighted means of element properties."""
170+
warn("'powers_float' will be deprecated in v4.0.0 for 'powers', and removed in v5.0.0",
171+
PendingDeprecationWarning)
172+
return self._powers
173+
155174
def __str__(self):
156175
return '<ChemicalFormulaFeaturizer {!r}>'.format(self.name)

tests/informatics/test_predictors.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,10 @@ def test_chemical_featurizer(chemical_featurizer):
259259
assert chemical_featurizer.input_descriptor == ChemicalFormulaDescriptor("formula")
260260
assert chemical_featurizer.features == ["standard"]
261261
assert chemical_featurizer.excludes == []
262-
assert chemical_featurizer.powers == [1, 2]
262+
with pytest.warns(UserWarning):
263+
assert chemical_featurizer.powers == [1, 2]
264+
with pytest.warns(PendingDeprecationWarning):
265+
assert chemical_featurizer.powers_float == [1.0, 2.0]
263266

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

0 commit comments

Comments
 (0)