
    ,YHh*                        d Z ddlZddlZddlmZ ddlmZ ddlmZ  G d de	      Z
 G d d	e	      Z G d
 de	      Z G d de	      Z G d de	      Z G d de	      Z G d de	      Z G d de	      Z G d de	      Z G d de	      Z G d de	      Z G d de	      Ze
eeeeeeeeeeegZ	 	 d+deded ed!ed"ed#ed$dfd%Z	 	 d+deded ed!ed"ed#ed$dfd&Zd,d(ed$dfd)Z ed'*       y)-zn
The skforecast.exceptions module contains all the custom warnings and error 
classes used across skforecast.
    N)Console)Panel)Textc                       e Zd ZdZd Zd Zy)DataTypeWarningz
    Warning used to notify there are dtypes in the exogenous data that are not
    'int', 'float', 'bool' or 'category'. Most machine learning models do not
    accept other data types, therefore the forecaster `fit` and `predict` may fail.
    c                     || _         y Nmessageselfr   s     Y/var/www/html/planif/env/lib/python3.12/site-packages/skforecast/exceptions/exceptions.py__init__zDataTypeWarning.__init__   	        c                 *    d}| j                   dz   |z   S )Nz^You can suppress this warning using: warnings.simplefilter('ignore', category=DataTypeWarning)
r
   r   extra_messages     r   __str__zDataTypeWarning.__str__   s#    H 	 ||d"]22r   N__name__
__module____qualname____doc__r   r    r   r   r   r          
3r   r   c                       e Zd ZdZd Zd Zy)DataTransformationWarningzR
    Warning used to notify that the output data is in the transformed space.
    c                     || _         y r	   r
   r   s     r   r   z"DataTransformationWarning.__init__(   r   r   c                 *    d}| j                   dz   |z   S )NzhYou can suppress this warning using: warnings.simplefilter('ignore', category=DataTransformationWarning)r   r
   r   s     r   r   z!DataTransformationWarning.__str__+   #    R 	 ||d"]22r   Nr   r   r   r   r   r   $       3r   r   c                       e Zd ZdZd Zd Zy)IgnoredArgumentWarningzd
    Warning used to notify that an argument is ignored when using a method 
    or a function.
    c                     || _         y r	   r
   r   s     r   r   zIgnoredArgumentWarning.__init__8   r   r   c                 *    d}| j                   dz   |z   S )NzeYou can suppress this warning using: warnings.simplefilter('ignore', category=IgnoredArgumentWarning)r   r
   r   s     r   r   zIgnoredArgumentWarning.__str__;   s#    O 	 ||d"]22r   Nr   r   r   r   r%   r%   3       3r   r%   c                       e Zd ZdZd Zd Zy)IndexWarningz^
    Warning used to notify that the index of the input data is not a
    expected type. 
    c                     || _         y r	   r
   r   s     r   r   zIndexWarning.__init__H   r   r   c                 *    d}| j                   dz   |z   S )Nz[You can suppress this warning using: warnings.simplefilter('ignore', category=IndexWarning)r   r
   r   s     r   r   zIndexWarning.__str__K   s#    E 	 ||d"]22r   Nr   r   r   r   r*   r*   C   r(   r   r*   c                       e Zd ZdZd Zd Zy)LongTrainingWarningz
    Warning used to notify that a large number of models will be trained and the
    the process may take a while to run.
    c                     || _         y r	   r
   r   s     r   r   zLongTrainingWarning.__init__X   r   r   c                 *    d}| j                   dz   |z   S )NzbYou can suppress this warning using: warnings.simplefilter('ignore', category=LongTrainingWarning)r   r
   r   s     r   r   zLongTrainingWarning.__str__[   #    L 	 ||d"]22r   Nr   r   r   r   r.   r.   S   r(   r   r.   c                       e Zd ZdZd Zd Zy)MissingExogWarningz
    Warning used to indicate that there are missing exogenous variables in the
    data. Most machine learning models do not accept missing values, so the
    Forecaster's `fit' and `predict' methods may fail.
    c                     || _         y r	   r
   r   s     r   r   zMissingExogWarning.__init__i   r   r   c                 *    d}| j                   dz   |z   S )NzaYou can suppress this warning using: warnings.simplefilter('ignore', category=MissingExogWarning)r   r
   r   s     r   r   zMissingExogWarning.__str__l   s#    K 	 ||d"]22r   Nr   r   r   r   r3   r3   c   r   r   r3   c                       e Zd ZdZd Zd Zy)MissingValuesWarningaA  
    Warning used to indicate that there are missing values in the data. This 
    warning occurs when the input data contains missing values, or the training
    matrix generates missing values. Most machine learning models do not accept
    missing values, so the Forecaster's `fit' and `predict' methods may fail.
    c                     || _         y r	   r
   r   s     r   r   zMissingValuesWarning.__init__{   r   r   c                 *    d}| j                   dz   |z   S )NzcYou can suppress this warning using: warnings.simplefilter('ignore', category=MissingValuesWarning)r   r
   r   s     r   r   zMissingValuesWarning.__str__~   s#    M 	 ||d"]22r   Nr   r   r   r   r7   r7   t   s    3r   r7   c                       e Zd ZdZd Zd Zy)OneStepAheadValidationWarningzR
    Warning used to notify that the one-step-ahead validation is being used.
    c                     || _         y r	   r
   r   s     r   r   z&OneStepAheadValidationWarning.__init__   r   r   c                 *    d}| j                   dz   |z   S )NzlYou can suppress this warning using: warnings.simplefilter('ignore', category=OneStepAheadValidationWarning)r   r
   r   s     r   r   z%OneStepAheadValidationWarning.__str__   s#    V 	 ||d"]22r   Nr   r   r   r   r;   r;      r#   r   r;   c                       e Zd ZdZd Zd Zy)ResidualsUsageWarningzu
    Warning used to notify that a residual are not correctly used in the
    probabilistic forecasting process.
    c                     || _         y r	   r
   r   s     r   r   zResidualsUsageWarning.__init__   r   r   c                 *    d}| j                   dz   |z   S )NzdYou can suppress this warning using: warnings.simplefilter('ignore', category=ResidualsUsageWarning)r   r
   r   s     r   r   zResidualsUsageWarning.__str__   s#    N 	 ||d"]22r   Nr   r   r   r   r?   r?      r(   r   r?   c                       e Zd ZdZd Zd Zy)UnknownLevelWarningzd
    Warning used to notify that a level being predicted was not part of the
    training data.
    c                     || _         y r	   r
   r   s     r   r   zUnknownLevelWarning.__init__   r   r   c                 *    d}| j                   dz   |z   S )NzbYou can suppress this warning using: warnings.simplefilter('ignore', category=UnknownLevelWarning)r   r
   r   s     r   r   zUnknownLevelWarning.__str__   r1   r   Nr   r   r   r   rC   rC      r(   r   rC   c                       e Zd ZdZd Zd Zy)SaveLoadSkforecastWarningzc
    Warning used to notify any issues that may arise when saving or loading
    a forecaster.
    c                     || _         y r	   r
   r   s     r   r   z"SaveLoadSkforecastWarning.__init__   r   r   c                 *    d}| j                   dz   |z   S )NzhYou can suppress this warning using: warnings.simplefilter('ignore', category=SaveLoadSkforecastWarning)r   r
   r   s     r   r   z!SaveLoadSkforecastWarning.__str__   r"   r   Nr   r   r   r   rG   rG      r(   r   rG   c                       e Zd ZdZd Zd Zy)SkforecastVersionWarningz
    Warning used to notify that the skforecast version installed in the 
    environment differs from the version used to initialize the forecaster.
    c                     || _         y r	   r
   r   s     r   r   z!SkforecastVersionWarning.__init__   r   r   c                 *    d}| j                   dz   |z   S )NzgYou can suppress this warning using: warnings.simplefilter('ignore', category=SkforecastVersionWarning)r   r
   r   s     r   r   z SkforecastVersionWarning.__str__   s#    Q 	 ||d"]22r   Nr   r   r   r   rK   rK      r(   r   rK   r   categoryfilenamelinenofilelinereturnc           
         t        | t        t                    r"d}t        |       j                  }dg}t        j                  t        |       |dz
  dd      }	dd|t        |      z
  dz
  dz  z   d| dd|t        |      z
  dz
  dz  z   d	}
t        |      dz  d
k7  r|
dd dz   d	z   }
dd|z   d}|j                  |
       |	j                  d      D ])  }|j                  d|j                  |dz
         d       + |j                  |       dj                  |      }d}d}| | | }t        |       yt        j                  | |||||       y)a  
    Custom warning handler to format warnings in a box for skforecast custom
    warnings.

    Parameters
    ----------
    message : str
        Warning message.
    category : str
        Warning category.
    filename : str
        Filename where the warning was raised.
    lineno : int
        Line number where the warning was raised.
    file : file, default None
        File where the warning was raised.
    line : str, default None
        Line where the warning was raised.

    Returns
    -------
    None

    X   r      T)widthexpand_tabsreplace_whitespaceu   ╭u   ─ u   ╮r   Nu   ╰u   ╯u   │ u    │z[38;5;208mz[0m)
isinstancetuplewarn_skforecast_categoriestyper   textwrapfillstrlenappendsplitljustjoinprintwarnings_original_showwarning)r   rN   rO   rP   rQ   rR   rW   titleoutput_textwrapped_messagetitle_top_borderbottom_bordercolorresets                 r   format_warning_handlerrr      s   B '5!;<=W&&f"--GEAISWlpq 53u:+=+Aa*G!H I5'QRSX]behineo]ors]sxy\ySzR{{~u:>Q/4u<uDeem_C0+,#))$/ 	CDdjj&;%<DAB	C 	=)ii, }UG4k 	&&w(FDRVWr   c           
      &   t        | t        t                    r^t               }|j                  }| j
                   d| d| d| d| d
}t        t        |d      |dd	d
      }	|j                  |	       yt        j                  | |||||       y)a  
    Custom handler for warnings that uses rich to display formatted panels.

    Parameters
    ----------
    message : str
        Warning message.
    category : str
        Warning category.
    filename : str
        Filename where the warning was raised.
    lineno : int
        Line number where the warning was raised.
    file : file, default None
        File where the warning was raised.
    line : str, default None
        Line where the warning was raised.

    Returns
    -------
    None

    z

Category : z
Location : :z5
Suppress : warnings.simplefilter('ignore', category=)left)justifycenterz
color(214)rU   )rk   title_alignborder_stylerW   N)r\   r]   r^   r   r   r   r   r   rh   ri   rj   )
r   rN   rO   rP   rQ   rR   consolecategory_nametextpanels
             r   rich_warning_handlerr      s    @ '5!;<=) ))  ' )"1VH -CCP/QRT 	 v&(#'
 	e 	&&w(FDRVWr   
skforecaststylec                     | dk(  r9t        t        d      st        j                  t        _        t        t        _        yt        j                  t        _        y)z
    Set the warning handler based on the provided style.

    Parameters
    ----------
    style : str, default='skforecast'
        The style of the warning handler. Either 'skforecast' or 'default'.
    
    Returns
    -------
    None

    r   rj   N)hasattrri   showwarningrj   r   r   s    r   set_warnings_styler   Y  s;     x!89-5-A-AH*3'==r   r   )NN)r   )r   ri   r`   rich.consoler   
rich.panelr   	rich.textr   UserWarningr   r   r%   r*   r.   r3   r7   r;   r?   rC   rG   rK   r^   rb   objectrr   r   r   r   r   r   <module>r      s        3k 3"3 33[ 3 3; 3 3+ 3 3 3"3; 3$3K 33K 3 3+ 3 3 3 3{ 3" ! * 8X8X8X 8X 	8X
 8X 8X 
8X@ 6X6X6X 6X 	6X
 6X 6X 
6Xr>c >T >,  &r   