
    Ki                     r    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dS )
zBase 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dS )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                 \    t          |||          | _        t          |          | _        dS )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        L/var/www/html/analyses/venv/lib/python3.11/site-packages/mysql/ai/ml/base.py__init__zMyBaseMLModel.__init__?   s1    * m$:NNN!*+<!=!=    Xyreturnc                 H    | 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 	1d4555r   c                 4    | 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                 4    | 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!> SM	>
 $D>> > > >6 %) < BL! 
	   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, b, b, b, b,M b, b, b, b, b,r   