diff --git a/src/citrine/__version__.py b/src/citrine/__version__.py index 7a829927f..85197cb4a 100644 --- a/src/citrine/__version__.py +++ b/src/citrine/__version__.py @@ -1 +1 @@ -__version__ = "3.5.4" +__version__ = "3.6.0" diff --git a/src/citrine/informatics/predictors/chemical_formula_featurizer.py b/src/citrine/informatics/predictors/chemical_formula_featurizer.py index 76273fcbc..45213ab17 100644 --- a/src/citrine/informatics/predictors/chemical_formula_featurizer.py +++ b/src/citrine/informatics/predictors/chemical_formula_featurizer.py @@ -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 @@ -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) @@ -152,5 +153,27 @@ 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_as_float'.") + truncated = [int(p) for p in self._powers] + if truncated != self._powers: + diffs = [f"{x} => {y}" for x, y in zip(self._powers, truncated) if x != y] + warn(f"The following powers were cast to ints: {'; '.join(diffs)}.") + return truncated + + @powers.setter + def powers(self, value: List[Union[int, float]]): + self._powers = value + + @property + def powers_as_float(self) -> List[float]: + """Powers when computing generalized weighted means of element properties.""" + warn("'powers_as_float' will be deprecated in v4.0.0 for 'powers', and removed in v5.0.0", + PendingDeprecationWarning) + return self._powers + def __str__(self): return ''.format(self.name) diff --git a/tests/informatics/test_predictors.py b/tests/informatics/test_predictors.py index 392438163..0645fe4a7 100644 --- a/tests/informatics/test_predictors.py +++ b/tests/informatics/test_predictors.py @@ -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_as_float == [1.0, 2.0] assert str(chemical_featurizer) == "" @@ -272,6 +275,12 @@ def test_chemical_featurizer(chemical_featurizer): 'powers': [1, 2], 'type': 'ChemicalFormulaFeaturizer' } + + chemical_featurizer.powers = [0.5, -1] + with pytest.warns(PendingDeprecationWarning): + assert chemical_featurizer.powers_as_float == [0.5, -1.0] + with pytest.warns(UserWarning): + assert chemical_featurizer.powers == [0, -1] def test_auto_ml(auto_ml):