Ë
    5¾ªj®  ã                   ój   — d Z ddlmZmZ ddlZddlmZ ddlm	Z	 ddl
mZmZ ddlmZ  G d„ d	e«      Zy)
z’Base classes for MySQL HeatWave ML estimators for Connector/Python.

Implements a scikit-learn-compatible base estimator wrapping server-side ML.
é    )ÚOptionalÚUnionN)ÚBaseEstimator)ÚMySQLConnectionAbstract)ÚML_TASKÚMyModel)Ú	copy_dictc            
       ó¨   — e Zd ZdZ	 	 ddedeeef   dee   dee	   fd„Z
	 ddej                  d	eej                     d
d fd„Zd
efd„Zd
ee	   fd„Zy)ÚMyBaseMLModela  
    Base class for MySQL HeatWave machine learning estimators.

    Implements the scikit-learn API and core model management logic,
    including fit, explain, serialization, and dynamic option handling.
    For use as a base class by classifiers, regressors, transformers, and outlier models.

    Args:
        db_connection (MySQLConnectionAbstract): An active MySQL connector database connection.
        task (str): ML task type, e.g. "classification" or "regression".
        model_name (str, optional): Custom name for the deployed model.
        fit_extra_options (dict, optional): Extra options for fitting.

    Attributes:
        _model: Underlying database helper for fit/predict/explain.
        fit_extra_options: User-provided options for fitting.
    NÚdb_connectionÚtaskÚ
model_nameÚfit_extra_optionsc                 óJ   — t        |||¬«      | _        t        |«      | _        y)a  
        Initialize a MyBaseMLModel with connection, task, and option parameters.

        Args:
            db_connection: Active MySQL connector database connection.
            task: String label of ML task (e.g. "classification").
            model_name: Optional custom model name.
            fit_extra_options: Optional extra fit options.

        Raises:
            DatabaseError:
                If a database connection issue occurs.
                If an operational error occurs during execution.
        )r   r   N)r   Ú_modelr	   r   )Úselfr   r   r   r   s        úO/var/www/html/serviGia/entorno/lib/python3.12/site-packages/mysql/ai/ml/base.pyÚ__init__zMyBaseMLModel.__init__?   s"   € ô* ˜m°$À:ÔNˆŒÜ!*Ð+<Ó!=ˆÕó    ÚXÚyÚreturnc                 óT   — | j                   j                  ||| j                  «       | S )aZ  
        Fit the underlying ML model using pandas DataFrames.
        Delegates to MyMLModelPandasHelper.fit.

        Args:
            X: Features DataFrame.
            y: (Optional) Target labels DataFrame or Series.

        Returns:
            self

        Raises:
            DatabaseError:
                If provided options are invalid or unsupported.
                If a database connection issue occurs.
                If an operational error occurs during execution.

        Notes:
            Additional temp SQL resources may be created and cleaned up during the operation.
        )r   Úfitr   )r   r   r   s      r   r   zMyBaseMLModel.fitW   s#   € ð2 	�‰�‰˜˜1˜d×4Ñ4Ô5Øˆr   c                 ó6   — | j                   j                  «       S )a%  
        Deletes the model from the model catalog if present

        Raises:
            DatabaseError:
                If a database connection issue occurs.
                If an operational error occurs during execution.

        Returns:
            Whether the model was deleted
        )r   Ú_delete_model©r   s    r   r   zMyBaseMLModel._delete_models   s   € ð �{‰{×(Ñ(Ó*Ð*r   c                 ó6   — | j                   j                  «       S )a’  
        Checks if the model name is available. Model info will only be present in the
        catalog if the model has previously been fitted.

        Returns:
            True if the model name is not part of the model catalog

        Raises:
            DatabaseError:
                If a database connection issue occurs.
                If an operational error occurs during execution.
        )r   Úget_model_infor   s    r   r   zMyBaseMLModel.get_model_info�   s   € ð �{‰{×)Ñ)Ó+Ð+r   )NN)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Ústrr   r   Údictr   ÚpdÚ	DataFramer   Úboolr   r   © r   r   r   r   ,   sš   „ ñð, %)Ø,0ñ>à.ð>ð �C˜�LÑ!ð>ð ˜S‘Mð	>ð
 $ D™>ó>ð6 %)ñà�<‰<ðð �B—L‘LÑ!ðð 
ó	ð8+˜tó +ð, ¨¡ô ,r   r   )r#   Útypingr   r   Úpandasr&   Úsklearn.baser   Úmysql.connector.abstractsr   Úmysql.ai.ml.modelr   r   Úmysql.ai.utilsr	   r   r)   r   r   ú<module>r0      s,   ðñ:÷ #ã å &å =ß .Ý $ôb,�Mõ b,r   