"""Base functionality for all BayBE targets."""from__future__importannotationsimportgcfromabcimportABC,abstractmethodfromtypingimportTYPE_CHECKINGimportpandasaspdfromattrsimportdefine,fieldfromattrs.validatorsimportinstance_offromtyping_extensionsimportoverridefrombaybe.serializationimport(SerialMixin,)frombaybe.utils.metadataimportMeasurableMetadata,to_metadataifTYPE_CHECKING:frombaybe.objectivesimportSingleTargetObjective
[docs]@define(frozen=True)classTarget(ABC,SerialMixin):"""Abstract base class for all target variables. Stores information about the range, transformations, etc. """name:str=field(validator=instance_of(str))"""The name of the target."""metadata:MeasurableMetadata=field(factory=MeasurableMetadata,converter=lambdax:to_metadata(x,MeasurableMetadata),kw_only=True,)"""Optional metadata containing description, unit, and other information."""@propertydefdescription(self)->str|None:"""The description of the target."""returnself.metadata.description@propertydefunit(self)->str|None:"""The unit of measurement for the target."""returnself.metadata.unit
[docs]defto_objective(self)->SingleTargetObjective:"""Create a single-task objective from the target."""frombaybe.objectives.singleimportSingleTargetObjectivereturnSingleTargetObjective(self)
[docs]@abstractmethoddeftransform(self,series:pd.Series,/)->pd.Series:"""Transform target measurements to computational representation. Args: series: The target measurements in experimental representation to be transformed. Returns: A series containing the transformed measurements. The series name matches that of the input. """
[docs]@abstractmethoddefsummary(self)->dict:"""Return a custom summarization of the target."""