Skip to content

Commit 0e454fe

Browse files
authored
Merge pull request #964 from CitrineInformatics/bugfix/powers-type
Adjust type of ChemicalFormulaFeaturizer.powers.
2 parents 9e15919 + 497ba9f commit 0e454fe

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
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

+25-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import List, Optional
1+
from typing import List, Optional, Union
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,27 @@ 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_as_float'.")
161+
truncated = [int(p) for p in self._powers]
162+
if truncated != self._powers:
163+
diffs = [f"{x} => {y}" for x, y in zip(self._powers, truncated) if x != y]
164+
warn(f"The following powers were cast to ints: {'; '.join(diffs)}.")
165+
return truncated
166+
167+
@powers.setter
168+
def powers(self, value: List[Union[int, float]]):
169+
self._powers = value
170+
171+
@property
172+
def powers_as_float(self) -> List[float]:
173+
"""Powers when computing generalized weighted means of element properties."""
174+
warn("'powers_as_float' will be deprecated in v4.0.0 for 'powers', and removed in v5.0.0",
175+
PendingDeprecationWarning)
176+
return self._powers
177+
155178
def __str__(self):
156179
return '<ChemicalFormulaFeaturizer {!r}>'.format(self.name)

tests/informatics/test_predictors.py

+10-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_as_float == [1.0, 2.0]
263266

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

@@ -272,6 +275,12 @@ def test_chemical_featurizer(chemical_featurizer):
272275
'powers': [1, 2],
273276
'type': 'ChemicalFormulaFeaturizer'
274277
}
278+
279+
chemical_featurizer.powers = [0.5, -1]
280+
with pytest.warns(PendingDeprecationWarning):
281+
assert chemical_featurizer.powers_as_float == [0.5, -1.0]
282+
with pytest.warns(UserWarning):
283+
assert chemical_featurizer.powers == [0, -1]
275284

276285

277286
def test_auto_ml(auto_ml):

0 commit comments

Comments
 (0)