
    Z|i                     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)
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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        J/var/www/html/python/venv/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 	1d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!> SM	>
 $D>>6 %)<< BLL! 
	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   