
    bcg                     l    d Z ddlm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y)z
This module contains the abstractions for keeping small amount of data. It provides the interface for classes and a few
realisations.
    )print_functionN   )CatBoostError)get_eval_logger   )make_dirs_if_not_existsc                   T    e Zd ZdZdZed        Zd Zd Zd Z	d Z
d Zd	 Zd
 Zd Zy)FoldStoragez
    Base class.
    foldsc                     	 t         j                  j                  t        j                        r$t        j
                  t        j                         yy# t        $ r-} t               j                  | j                         Y d} ~ yd} ~ ww xY w)z
        Remove default directory for folds if there're no files nut models. In other way it raises warning.

        Args:
            :return: Nothing.

        N)
ospathexists	_FoldFiledefault_dirrmdirOSErrorr   warningmessage)errs    V/var/www/html/bid-api/venv/lib/python3.12/site-packages/catboost/eval/_fold_storage.py
remove_dirzFoldStorage.remove_dir   s\    	3ww~~i334../ 5 	3%%ckk22	3s   AA 	B
#BB
c                 J    || _         || _        || _        || _        d| _        y )Nr   )_fold_storage_name_column_description_sep_size)selffoldstorage_namesepcolumn_descriptions        r   __init__zFoldStorage.__init__%   s'    
)#5 	
    c                     | j                   S )zg
        Args:
            :return: (str) Delimiter for data used when we saved fold to file.

        )r   r   s    r   get_separatorzFoldStorage.get_separator,   s     yyr%   c                     | j                   S N)r   r'   s    r   __str__zFoldStorage.__str__4   s    !!!r%   c                     | j                   S )zS
        Args:
            :return: (str) Path to the column description.

        )r   r'   s    r   r#   zFoldStorage.column_description7   s     '''r%   c                     || j                   v S )z
        Args:
            :param group_id: (int) The number of group we want to check.
            :return: True if fold contains line or lines with that group id.

        )r   )r   group_ids     r   contains_group_idzFoldStorage.contains_group_id?   s     4::%%r%   c                     t        d      Nz?The base class don't have delete method. Please, use successor.NotImplementedErrorr'   s    r   openzFoldStorage.openH       !"cddr%   c                     t        d      r1   r2   r'   s    r   closezFoldStorage.closeK   r5   r%   c                     t        d      r1   r2   r'   s    r   deletezFoldStorage.deleteN   r5   r%   N)__name__
__module____qualname____doc__r   staticmethodr   r$   r(   r+   r#   r/   r4   r7   r9    r%   r   r
   r
      sK     K3 3"(&eeer%   r
   c                   R     e Zd ZdZ fdZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Z xZS )r   z
    FoldFile is the realisation of the interface of FoldStorage. It always saves data to file before reset them.
    All files place to the special directory 'folds'.
    c                     t         t        |   ||||       t        j                  j                  | j                  |      | _        | j                          g | _	        d | _
        y )N)r"   r#   )superr   r$   r   r   joinr   
_file_path_prepare_path_lines_file)r   r    r!   r"   r#   	__class__s        r   r$   z_FoldFile.__init__X   s]    i',(: 	( 	
 '',,t'7'7'35
r%   c                 v    t        | j                         t        | j                  d      j	                          y )Nw)r   r   r4   rD   r7   r'   s    r   rE   z_FoldFile._prepare_pathc   s'     0 01T__c"((*r%   c                     | j                   S r*   )rD   r'   s    r   r   z_FoldFile.pathg   s    r%   c                 ^    | xj                   dz  c_         t        || j                  d       y )Nr    )fileend)r   printrG   )r   lines     r   addz_FoldFile.addj   s    

a
d,r%   c                 L    |D cg c]  }| j                  |       c} y c c}w r*   )rR   )r   linesrQ   s      r   add_allz_FoldFile.add_alln   s    $)*ED$E**s   !c                     | j                   t        | j                  d      | _         y t        dj	                  | j                              )Na)modezFile already opened {})rG   r4   rD   r   formatr'   s    r   r4   z_FoldFile.openq   s9    ::dooC8DJ 8 ? ? PQQr%   c                     | j                   d uS r*   )rG   r'   s    r   	is_openedz_FoldFile.is_openedw   s    zz%%r%   c                     | j                   $t        dj                  | j                              | j                   j	                          d | _         y )NzTrying to close None {})rG   r   rY   rD   r7   r'   s    r   r7   z_FoldFile.closez   s>    :: 9 @ @ QRR


r%   c                     | j                   t        d      t        j                  j	                  | j
                        r t        j                  | j
                         y y )NzClose file before delete)rG   r   r   r   r   rD   remover'   s    r   r9   z_FoldFile.delete   sA    ::! :;;77>>$//*IIdoo& +r%   )r:   r;   r<   r=   r$   rE   r   rR   rU   r4   r[   r7   r9   __classcell__)rH   s   @r   r   r   R   s6    
	+-+R&'r%   r   )r=   
__future__r   r   rM   r   eval.log_configr   utilsr   objectr
   r   r?   r%   r   <module>rd      s6   
 & 	  - *?e& ?eD4' 4'r%   