o
    U|%i                     @   sd   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	 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                
   @   s   e Zd ZdZ		ddedeeef dee dee	 fddZ
	dd	ejd
eej dd fddZdefddZdee	 fd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                 C   s   t |||d| _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    r   M/home/air/sos_test/back/venv/lib/python3.10/site-packages/mysql/ai/ml/base.py__init__?   s   zMyBaseMLModel.__init__Xyreturnc                 C   s   | 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   r   r   r   r   W   s   zMyBaseMLModel.fitc                 C   
   | 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   r   r   r   r   s   s   
zMyBaseMLModel._delete_modelc                 C   r   )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   r   r   r   r      s   
zMyBaseMLModel.get_model_info)NN)N)__name__
__module____qualname____doc__r   r   strr   r   dictr   pd	DataFramer   boolr   r   r   r   r   r   r	   ,   s.    


r	   )r   typingr   r   pandasr!   sklearn.baser   mysql.connector.abstractsr   mysql.ai.ml.modelr   r   mysql.ai.utilsr   r	   r   r   r   r   <module>   s   