a
    h                     @   s   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 deedZdddZdS )zUtilities for meta-estimators.    )ABCMetaabstractmethod)suppress)AnyListN   )BaseEstimator)_safe_indexing)get_tags   )available_ifr   c                       sX   e Zd ZU dZee ed< edd Zd fdd	Z	 fdd	Z
d
d Zdd Z  ZS )_BaseCompositionzJHandles parameter management for classifiers composed of named estimators.Zstepsc                 C   s   d S N )selfr   r   X/var/www/html/assistant/venv/lib/python3.9/site-packages/sklearn/utils/metaestimators.py__init__   s    z_BaseComposition.__init__Tc           	   	      s   t  j|d}|s|S t| |}z|| W n ttfyH   | Y S 0 |D ]<\}}t|drN|jdd D ]\}}||d||f < qpqN|S )Ndeep
get_paramsTz%s__%s)superr   getattrupdate	TypeError
ValueErrorhasattritems)	r   attrr   outZ
estimatorsname	estimatorkeyvalue	__class__r   r   _get_params   s    


z_BaseComposition._get_paramsc              	      s   ||v rt | ||| t| |}t|tr|rttR t| \}}t| D ](}d|vrT||v rT| 	|||| qTW d    n1 s0    Y  t
 jf i | | S )N__)setattrpopr   
isinstancelistr   r   zipkeys_replace_estimatorr   Z
set_params)r   r   paramsr   Z
item_names_r   r#   r   r   _set_params3   s    

4z_BaseComposition._set_paramsc                 C   sL   t t| |}t|D ]$\}\}}||kr||f||<  q<qt| || d S r   )r*   r   	enumerater'   )r   r   r   new_valZnew_estimatorsiZestimator_namer/   r   r   r   r-   H   s    z#_BaseComposition._replace_estimatorc                 C   sv   t t|t |kr&tdt|t|| jdd}|rRtdt|dd |D }|rrtd|d S )Nz$Names provided are not unique: {0!r}Fr   z:Estimator names conflict with constructor arguments: {0!r}c                 S   s   g | ]}d |v r|qS )r&   r   ).0r   r   r   r   
<listcomp>[       z4_BaseComposition._validate_names.<locals>.<listcomp>z.Estimator names must not contain __: got {0!r})lensetr   formatr*   intersectionr   sorted)r   namesinvalid_namesr   r   r   _validate_namesQ   s    z _BaseComposition._validate_names)T)__name__
__module____qualname____doc__r   r   __annotations__r   r   r%   r0   r-   r>   __classcell__r   r   r#   r   r      s   

	r   )	metaclassc                 C   s   t | jjrft|dstd|jd |jd kr:td|du rT|t|| }qp|t|| }n
t||}|durt||}n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.

    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
   Z
input_tagspairwiser   r   rF   npZix_r	   )r    XyindicesZtrain_indicesZX_subsetZy_subsetr   r   r   _safe_splitb   s    ,

rL   )N)rB   abcr   r   
contextlibr   typingr   r   numpyrH   baser   utilsr	   Zutils._tagsr
   Z_available_ifr   __all__r   rL   r   r   r   r   <module>   s   N