"""Base classes for all objectives."""fromabcimportABC,abstractmethodimportpandasaspdfromattrsimportdefinefromcattrsimportoverridefrombaybe.objectives.deprecationimportstructure_objectivefrombaybe.serialization.coreimport(converter,unstructure_base,)frombaybe.serialization.mixinimportSerialMixinfrombaybe.targets.baseimportTarget# TODO: Reactive slots in all classes once cached_property is supported:# https://github.com/python-attrs/attrs/issues/164
[docs]@define(frozen=True,slots=False)classObjective(ABC,SerialMixin):"""Abstract base class for all objectives."""@property@abstractmethoddeftargets(self)->tuple[Target,...]:"""The targets included in the objective."""
[docs]@abstractmethoddeftransform(self,data:pd.DataFrame)->pd.DataFrame:"""Transform target values from experimental to computational representation. Args: data: The data to be transformed. Must contain columns for all targets but can contain additional columns. Returns: A new dataframe with the targets in computational representation. """
[docs]defto_objective(x:Target|Objective,/)->Objective:"""Convert a target into an objective (with objective passthrough)."""returnxifisinstance(x,Objective)elsex.to_objective()