B
    ¦	\”  ć               @   sJ   d 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ddZdS )zHelpers for preprocessingé    N)Śsparseé   )Ścheck_array)ŚFLOAT_DTYPES)ŚsixŚallTFc             C   s\  t | d|td} t | ”r&|r&tdt|tjrB|dkrB|| S t|dkrR| S | j	d }t
 |”}t
j|td}d|t
 |”< t
 |”}	t
 |”}
|
dkr¢| S |
|kr²|| S || d	d	|| f }| d	d	||	 f  |”}|r$|j	d |j	d  |krtd
|| d	d	|| f< | S t |”s<t |”rJt ||f”S t
 ||f”S d	S )a÷  Apply a transform function to portion of selected features.

    Returns an array Xt, where the non-selected features appear on the right
    side (largest column indices) of Xt.

    Parameters
    ----------
    X : {array-like, sparse matrix}, shape [n_samples, n_features]
        Dense array or sparse matrix.

    transform : callable
        A callable transform(X) -> X_transformed

    dtype : number type
        Desired dtype of output.

    copy : boolean, default=True
        Copy X even if it could be avoided.

    selected : "all" or array of indices or mask
        Specify which features to apply the transform to.

    retain_order : boolean, default=False
        If True, the non-selected features will not be displaced to the right
        side of the transformed array. The number of features in Xt must
        match the number of features in X. Furthermore, X and Xt cannot be
        sparse.

    Returns
    -------
    Xt : array or sparse matrix, shape=(n_samples, n_features_new)
    Zcsc)Zaccept_sparseŚcopyŚdtypezCThe retain_order option can only be set to True for dense matrices.r   r   é   )r	   TNzThe retain_order option can only be set to True if the dimensions of the input array match the dimensions of the transformed array.)r   r   r   ZissparseŚ
ValueErrorŚ
isinstancer   Zstring_typesŚlenŚshapeŚnpZarangeZzerosŚboolZasarrayZlogical_notŚsumZastypeZhstack)ŚXZ	transformr	   Zselectedr   Zretain_orderZ
n_featuresZindZselZnot_selZ
n_selectedZX_selZ	X_not_sel© r   ś9lib/python3.7/site-packages/sklearn/preprocessing/base.pyŚ_transform_selected   s6    "



r   )r   TF)Ś__doc__Znumpyr   Zscipyr   Zutilsr   Zutils.validationr   Z	externalsr   r   r   r   r   r   Ś<module>   s    