
    {Kg                         d Z ddlmZmZ ddlm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 d
dlmZ dgZ G d dee      ZddZy)zUtilities for meta-estimators.    )ABCMetaabstractmethod)suppress)AnyListN   )BaseEstimator)_safe_indexing)
_safe_tags   )available_ifr   c                   \     e Zd ZU dZee   ed<   ed        Zd fd	Z	 fdZ
d Zd Z xZS )	_BaseCompositionzJHandles parameter management for classifiers composed of named estimators.stepsc                      y N )selfs    `/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/sklearn/utils/metaestimators.py__init__z_BaseComposition.__init__   s        c                 ,   t         	|   |      }|s|S t        | |      }	 |j                  |       |D ]D  \  }}t        |d      s|j                  d      j                         D ]  \  }}|||d|<    F |S # t        t
        f$ r |cY S w xY w)Ndeep
get_paramsT__)superr   getattrupdate	TypeError
ValueErrorhasattritems)
r   attrr   out
estimatorsname	estimatorkeyvalue	__class__s
            r   _get_paramsz_BaseComposition._get_params   s    g d +JT4(
	JJz"  *OD)y,/"+"6"6D"6"A"G"G"IJC27CD#./ #J  * 
 :& 	 J	s   A? ?BBc           	         ||v rt        | ||j                  |             t        | |      }t        |t              rp|rnt        t              5  t        | \  }}t	        |j                               D ].  }d|vs||v s| j                  |||j                  |             0 	 d d d        t        | ,  di | | S # 1 sw Y   xY w)Nr   r   )setattrpopr   
isinstancelistr   r    zipkeys_replace_estimatorr   
set_params)r   r$   paramsr#   
item_names_r'   r+   s          r   _set_paramsz_BaseComposition._set_params3   s     6>D$

4 01d#eT"u )$ #U
A /D4'DJ,>//dFJJt<LM 0 % 	$V$ %$s   ,B?<B?$B??Cc                     t        t        | |            }t        |      D ]  \  }\  }}||k(  s||f||<    n t        | ||       y r   )r1   r   	enumerater.   )r   r$   r'   new_valnew_estimatorsiestimator_namer8   s           r   r4   z#_BaseComposition._replace_estimatorH   sT    gdD12&/&?"A"%%)7Oq! '@ 	dN+r   c                    t        t        |            t        |      k7  r#t        dj                  t	        |                  t        |      j                  | j                  d            }|r#t        dj                  t        |                  |D cg c]	  }d|v s| }}|rt        dj                  |            y c c}w )Nz$Names provided are not unique: {0!r}Fr   z:Estimator names conflict with constructor arguments: {0!r}r   z.Estimator names must not contain __: got {0!r})lensetr!   formatr1   intersectionr   sorted)r   namesinvalid_namesr'   s       r   _validate_namesz _BaseComposition._validate_namesQ   s    s5z?c%j(CJJ4PU;WXXE
//U0KLLSS=) 
 +0@%$44<%@@GGV   As   	C!C)T)__name__
__module____qualname____doc__r   r   __annotations__r   r   r,   r9   r4   rH   __classcell__)r+   s   @r   r   r      s6    T9 ,*,r   r   )	metaclassc                 R   t        | d      rwt        |d      st        d      |j                  d   |j                  d   k7  rt        d      ||t	        j
                  ||         }n&|t	        j
                  ||         }nt        ||      }|t        ||      }||fS d}||fS )	a  Create subset of dataset and properly handle kernels.

    Slice X, y according to indices for cross-validation, but take care of
    precomputed kernel-matrices or pairwise affinities / distances.

    If ``estimator._pairwise is True``, X needs to be square and
    we slice rows and columns. If ``train_indices`` is not None,
    we slice rows using ``indices`` (assumed the test set) and columns
    using ``train_indices``, indicating the training set.

    Labels y will always be indexed only along the first axis.

    Parameters
    ----------
    estimator : object
        Estimator to determine whether we should slice only rows or rows and
        columns.

    X : array-like, sparse matrix or iterable
        Data to be indexed. If ``estimator._pairwise is True``,
        this needs to be a square array-like or sparse matrix.

    y : array-like, sparse matrix or iterable
        Targets to be indexed.

    indices : array of int
        Rows to select from X and y.
        If ``estimator._pairwise is True`` and ``train_indices is None``
        then ``indices`` will also be used to slice columns.

    train_indices : array of int or None, default=None
        If ``estimator._pairwise is True`` and ``train_indices is not None``,
        then ``train_indices`` will be use to slice the columns of X.

    Returns
    -------
    X_subset : array-like, sparse matrix or list
        Indexed data.

    y_subset : array-like, sparse matrix or list
        Indexed targets.

    pairwise)r)   shapezXPrecomputed kernels or affinity matrices have to be passed as arrays or sparse matrices.r   r   z"X should be a square kernel matrixN)r   r"   r!   rR   npix_r
   )r(   Xyindicestrain_indicesX_subsety_subsets          r   _safe_splitr[   b   s    X ),q'"= 
 771:#ABB 12H78H!!W-}!!W- X Xr   r   )rL   abcr   r   
contextlibr   typingr   r   numpyrS   baser	   utilsr
   utils._tagsr   _available_ifr   __all__r   r[   r   r   r   <module>re      sA    $
 (      " $ '
K} K\Ar   