Skip to content

Commit

Permalink
Merge pull request #866 from CitrineInformatics/maintain/update-enume…
Browse files Browse the repository at this point in the history
…ration

Maintain/update enumeration
  • Loading branch information
kroenlein authored Jun 13, 2023
2 parents 40f1ef7 + 65fde3a commit dda544f
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 37 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
gemd==1.13.0
gemd==1.15.0
requests==2.31.0
pyjwt==2.4.0
arrow==0.15.4
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"requests>=2.31.0,<3",
"pyjwt>=2,<3",
"arrow>=0.15.4,<2",
"gemd>=1.13.0,<2",
"gemd>=1.15.0,<2",
"boto3>=1.17.93,<2",
"botocore>=1.20.95,<2",
"deprecation>=2.1.0,<3",
Expand Down
2 changes: 1 addition & 1 deletion src/citrine/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.24.0'
__version__ = '2.24.1'
6 changes: 3 additions & 3 deletions src/citrine/_serialization/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,11 +689,11 @@ def underlying_types(self):
def serialized_types(self):
return str

def _deserialize(self, value: str) -> uuid.UUID:
return self.klass.get_enum(value)
def _deserialize(self, value: str) -> BaseEnumeration:
return self.klass.from_str(value, exception=True)

def _serialize(self, value: typing.Any) -> str:
return self.klass.get_value(value)
return self.klass.from_str(value, exception=True).value


@lru_cache(maxsize=1024)
Expand Down
15 changes: 6 additions & 9 deletions src/citrine/gemtables/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,8 @@ def __init__(self,
self.type_selector = type_selector

# Cast to make sure the string is valid
if not isinstance(quantity_dimension, IngredientQuantityDimension):
quantity_dimension = IngredientQuantityDimension.get_enum(quantity_dimension)
self.quantity_dimension = quantity_dimension
self.quantity_dimension = IngredientQuantityDimension.from_str(quantity_dimension,
exception=True)

if quantity_dimension == IngredientQuantityDimension.ABSOLUTE:
if unit is None:
Expand Down Expand Up @@ -927,9 +926,8 @@ def __init__(self,
self.type_selector = type_selector

# Cast to make sure the string is valid
if not isinstance(quantity_dimension, IngredientQuantityDimension):
quantity_dimension = IngredientQuantityDimension.get_enum(quantity_dimension)
self.quantity_dimension = quantity_dimension
self.quantity_dimension = IngredientQuantityDimension.from_str(quantity_dimension,
exception=True)

if quantity_dimension == IngredientQuantityDimension.ABSOLUTE:
if unit is None:
Expand Down Expand Up @@ -1086,9 +1084,8 @@ def __init__(self,
self.type_selector = type_selector

# Cast to make sure the string is valid
if not isinstance(quantity_dimension, IngredientQuantityDimension):
quantity_dimension = IngredientQuantityDimension.get_enum(quantity_dimension)
self.quantity_dimension = quantity_dimension
self.quantity_dimension = IngredientQuantityDimension.from_str(quantity_dimension,
exception=True)

if quantity_dimension == IngredientQuantityDimension.ABSOLUTE:
if unit is None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ def __init__(self, *,
self.label: Optional[str] = label

def __str__(self):
return '<IngredientCountConstraint {!r}>'.format(self.formulation_descriptor.key)
return f"<IngredientCountConstraint '{self.formulation_descriptor.key}'>"
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self, *,
self.is_required: bool = is_required

def __str__(self):
return '<IngredientFractionConstraint {!r}::{!r}>'.format(
self.formulation_descriptor.key,
self.ingredient
return (
f"<IngredientFractionConstraint "
f"'{self.formulation_descriptor.key}'::'{self.ingredient}'>"
)
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,4 @@ def _numerator_validate(self, value, input_type):
return {}

def __str__(self):
return f'<IngredientRatioConstraint {self.formulation_descriptor.key!r}>'
return f"<IngredientRatioConstraint '{self.formulation_descriptor.key}'>"
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,4 @@ def __init__(self, *,
self.is_required: bool = is_required

def __str__(self):
return '<LabelFractionConstraint {!r}::{!r}>'.format(
self.formulation_descriptor.key,
self.label
)
return f"<LabelFractionConstraint '{self.formulation_descriptor.key}'::'{self.label}'>"
6 changes: 2 additions & 4 deletions src/citrine/informatics/descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,13 @@ class FormulationDescriptor(Serializable['FormulationDescriptor'], Descriptor):
)

def __init__(self, key: Union[FormulationKey, str]):
if not isinstance(key, FormulationKey):
key = FormulationKey.get_enum(key)
self.key: str = key.value
self.key = FormulationKey.from_str(key, exception=True)

def __eq__(self, other):
return self._equals(other, ["key", "typ"])

def __str__(self):
return "<FormulationDescriptor {!r}>".format(self.key)
return f"<FormulationDescriptor '{self.key}'>"

def __repr__(self):
return "FormulationDescriptor(key={})".format(self.key)
Expand Down
3 changes: 1 addition & 2 deletions src/citrine/resources/file_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import mimetypes
import os
from pathlib import Path
from enum import Enum
from logging import getLogger
from tempfile import TemporaryDirectory
from typing import Optional, Tuple, Union, List, Dict, Iterable, Sequence
Expand Down Expand Up @@ -68,7 +67,7 @@ def __init__(self):
self.s3_addressing_style = 'auto'


class FileProcessingType(Enum):
class FileProcessingType(BaseEnumeration):
"""The supported File Processing Types."""

VALIDATE_CSV = "VALIDATE_CSV"
Expand Down
4 changes: 1 addition & 3 deletions src/citrine/resources/predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,7 @@ def _create_default_payload(training_data: DataSource,
pattern: Union[str, AutoConfigureMode] = AutoConfigureMode.INFER,
prefer_valid: bool = True) -> dict:
# Continue handling string pattern inputs
if not isinstance(pattern, AutoConfigureMode):
pattern = AutoConfigureMode.get_enum(pattern)
pattern = pattern.value
pattern = AutoConfigureMode.from_str(pattern, exception=True)

return {"data_source": training_data.dump(), "pattern": pattern,
"prefer_valid": prefer_valid}
Expand Down
5 changes: 1 addition & 4 deletions src/citrine/resources/status_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ class StatusDetail(Serializable[StatusDetailType]):
level = properties.String("level")

def __init__(self, *, msg: str, level: Union[str, StatusLevelEnum]):
if not isinstance(level, StatusLevelEnum):
level = StatusLevelEnum.get_enum(level)

self.msg = msg
self.level = level.value
self.level = StatusLevelEnum.from_str(level, exception=True)

def __str__(self):
return f"[{self.level.upper()}] {self.msg}" # pragma: no cover

0 comments on commit dda544f

Please sign in to comment.