Ë
    5¾ªj+  ã                   ó|   — d Z ddlmZmZ ddlZddlZddlm	Z	 ddl
mZ ddlmZ ddlmZ ddlmZ  G d	„ d
ee	«      Zy)z£Generic transformer utilities for MySQL Connector/Python.

Provides a scikit-learn compatible Transformer using HeatWave for fit/transform
and scoring operations.
é    )ÚOptionalÚUnionN)ÚTransformerMixin)ÚMyBaseMLModel)ÚML_TASK)Ú	copy_dict)ÚMySQLConnectionAbstractc                   ó(  — e Zd ZdZej
                  dddddfdedeeef   dede	e   de	e
   d	e	e
   d
e	e
   fd„Zdej                  dej                  fd„Zdeej                  ej                   f   deej                  ej                   f   defd„Zy)ÚMyGenericTransformera  
    MySQL HeatWave scikit-learn compatible generic transformer.

    Can be used as the transformation step in an sklearn pipeline. Implements fit, transform,
    explain, and scoring capability, passing options for server-side transform logic.

    Args:
        db_connection (MySQLConnectionAbstract): Active MySQL connector database connection.
        task (str): ML task type for transformer (default: "classification").
        score_metric (str): Scoring metric to request from backend (default: "balanced_accuracy").
        model_name (str, optional): Custom name for the deployed model.
        fit_extra_options (dict, optional): Extra fit options.
        transform_extra_options (dict, optional): Extra options for transformations.
        score_extra_options (dict, optional): Extra options for scoring.

    Attributes:
        score_metric (str): Name of the backend metric to use for scoring
            (e.g. "balanced_accuracy").
        score_extra_options (dict): Dictionary of optional scoring parameters;
            passed to backend score.
        transform_extra_options (dict): Dictionary of inference (/predict)
            parameters for the backend.
        fit_extra_options (dict): See MyBaseMLModel.
        _model (MyModel): Underlying interface for database model operations.

    Methods:
        fit(X, y): Fit the underlying model using the provided features/targets.
        transform(X): Transform features using the backend model.
        score(X, y): Score data using backend metric and options.
    Úbalanced_accuracyNÚdb_connectionÚtaskÚscore_metricÚ
model_nameÚfit_extra_optionsÚtransform_extra_optionsÚscore_extra_optionsc                 ó†   — t        j                  | ||||¬«       || _        t        |«      | _        t        |«      | _        y)aÉ  
        Initialize transformer with required and optional arguments.

        Args:
            db_connection: Active MySQL backend database connection.
            task: ML task type for transformer.
            score_metric: Requested backend scoring metric.
            model_name: Optional model name for storage.
            fit_extra_options: Optional extra options for fitting.
            transform_extra_options: Optional extra options for transformation/inference.
            score_extra_options: Optional extra scoring options.

        Raises:
            DatabaseError:
                If a database connection issue occurs.
                If an operational error occurs during execution.
        )r   r   N)r   Ú__init__r   r   r   r   )Úselfr   r   r   r   r   r   r   s           úV/var/www/html/serviGia/entorno/lib/python3.12/site-packages/mysql/ai/ml/transformer.pyr   zMyGenericTransformer.__init__M   sG   € ô6 	×ÑØØØØ!Ø/õ	
ð )ˆÔÜ#,Ð-@Ó#AˆÔ ä'0Ð1HÓ'IˆÕ$ó    ÚXÚreturnc                 óP   — | j                   j                  || j                  ¬«      S )aP  
        Transform input data to model predictions using the underlying helper.

        Args:
            X: DataFrame of features to predict/transform.

        Returns:
            pd.DataFrame: Results of transformation as returned by backend.

        Raises:
            DatabaseError:
                If provided options are invalid or unsupported,
                or if the model is not initialized, i.e., fit or import has not
                been called
                If a database connection issue occurs.
                If an operational error occurs during execution.
        ©Úoptions)Ú_modelÚpredictr   )r   r   s     r   Ú	transformzMyGenericTransformer.transformu   s$   € ð( �{‰{×"Ñ" 1¨d×.JÑ.JÐ"ÓKÐKr   Úyc                 óh   — | j                   j                  ||| j                  | j                  ¬«      S )aK  
        Score the transformed data using the backend scoring interface.

        Args:
            X: Transformed features.
            y: Target labels or data for scoring.

        Returns:
            float: Score based on backend metric.

        Raises:
            DatabaseError:
                If provided options are invalid or unsupported,
                or if the model is not initialized, i.e., fit or import has not
                been called
                If a database connection issue occurs.
                If an operational error occurs during execution.
        r   )r   Úscorer   r   )r   r   r!   s      r   r#   zMyGenericTransformer.score‹   s5   € ð. �{‰{× Ñ Øˆq�$×#Ñ#¨T×-EÑ-Eð !ó 
ð 	
r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚCLASSIFICATIONr	   r   Ústrr   Údictr   ÚpdÚ	DataFramer    ÚnpÚndarrayÚfloatr#   © r   r   r   r   -   sò   „ ñðD %,×$:Ñ$:Ø/Ø$(Ø,0Ø26Ø.2ñ&Jà.ð&Jð �C˜�LÑ!ð&Jð ð	&Jð
 ˜S‘Mð&Jð $ D™>ð&Jð "*¨$¡ð&Jð & d™^ó&JðPLØ—‘ðLà	�‰óLð,
à�—‘˜rŸz™zÐ)Ñ*ð
ð �—‘˜rŸz™zÐ)Ñ*ð
ð 
ô	
r   r   )r'   Útypingr   r   Únumpyr-   Úpandasr+   Úsklearn.baser   Úmysql.ai.ml.baser   Úmysql.ai.ml.modelr   Úmysql.ai.utilsr   Úmysql.connector.abstractsr	   r   r0   r   r   ú<module>r9      s5   ðñ8÷
 #ã Û Ý )å *Ý %Ý $Ý =ôw
˜=Ð*:õ w
r   