ó
‡ˆ\c           @   sl  d  Z  d d l m Z d d l m Z d d l Z d d l Z d d l m	 Z	 d d l
 m Z m Z d d l m Z m Z d d	 l m Z d d
 l m Z m Z m Z d d l m Z d d l m Z d d l m Z d d l m Z m Z d d g Z d Z  d e e f d „  ƒ  YZ! d „  Z" d „  Z# d „  Z$ d „  Z% d „  Z& d „  Z' d „  Z( d „  Z) d „  Z* d S(   s¦   
The :mod:`sklearn.compose._column_transformer` module implements utilities
to work with heterogeneous data and to apply different transformers to
different columns.
iÿÿÿÿ(   t   division(   t   chainN(   t   sparsei   (   t   clonet   TransformerMixin(   t   Parallelt   delayed(   t   six(   t   _fit_transform_onet   _transform_onet   _name_estimators(   t   FunctionTransformer(   t   Bunch(   t   _BaseComposition(   t   check_arrayt   check_is_fittedt   ColumnTransformert   make_column_transformers„   1D data passed to a transformer that expects 2D data. Try to specify the column selection as a list of one item instead of a scalar.c           B   sã   e  Z d  Z d d d d d „ Z e d „  ƒ Z e j d „  ƒ Z e d „ Z	 d „  Z
 e e d „ Z d	 „  Z d
 „  Z d „  Z e d „  ƒ Z d „  Z d „  Z d „  Z e d „ Z d d „ Z d d „ Z d „  Z d „  Z RS(   sz  Applies transformers to columns of an array or pandas DataFrame.

    EXPERIMENTAL: some behaviors may change between releases without
    deprecation.

    This estimator allows different columns or column subsets of the input
    to be transformed separately and the features generated by each transformer
    will be concatenated to form a single feature space.
    This is useful for heterogeneous or columnar data, to combine several
    feature extraction mechanisms or transformations into a single transformer.

    Read more in the :ref:`User Guide <column_transformer>`.

    .. versionadded:: 0.20

    Parameters
    ----------
    transformers : list of tuples
        List of (name, transformer, column(s)) tuples specifying the
        transformer objects to be applied to subsets of the data.

        name : string
            Like in Pipeline and FeatureUnion, this allows the transformer and
            its parameters to be set using ``set_params`` and searched in grid
            search.
        transformer : estimator or {'passthrough', 'drop'}
            Estimator must support `fit` and `transform`. Special-cased
            strings 'drop' and 'passthrough' are accepted as well, to
            indicate to drop the columns or to pass them through untransformed,
            respectively.
        column(s) : string or int, array-like of string or int, slice, boolean mask array or callable
            Indexes the data on its second axis. Integers are interpreted as
            positional columns, while strings can reference DataFrame columns
            by name.  A scalar string or int should be used where
            ``transformer`` expects X to be a 1d array-like (vector),
            otherwise a 2d array will be passed to the transformer.
            A callable is passed the input data `X` and can return any of the
            above.

    remainder : {'drop', 'passthrough'} or estimator, default 'drop'
        By default, only the specified columns in `transformers` are
        transformed and combined in the output, and the non-specified
        columns are dropped. (default of ``'drop'``).
        By specifying ``remainder='passthrough'``, all remaining columns that
        were not specified in `transformers` will be automatically passed
        through. This subset of columns is concatenated with the output of
        the transformers.
        By setting ``remainder`` to be an estimator, the remaining
        non-specified columns will use the ``remainder`` estimator. The
        estimator must support `fit` and `transform`.

    sparse_threshold : float, default = 0.3
        If the output of the different transfromers contains sparse matrices,
        these will be stacked as a sparse matrix if the overall density is
        lower than this value. Use ``sparse_threshold=0`` to always return
        dense.  When the transformed output consists of all dense data, the
        stacked result will be dense, and this keyword will be ignored.

    n_jobs : int or None, optional (default=None)
        Number of jobs to run in parallel.
        ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
        ``-1`` means using all processors. See :term:`Glossary <n_jobs>`
        for more details.

    transformer_weights : dict, optional
        Multiplicative weights for features per transformer. The output of the
        transformer is multiplied by these weights. Keys are transformer names,
        values the weights.

    Attributes
    ----------
    transformers_ : list
        The collection of fitted transformers as tuples of
        (name, fitted_transformer, column). `fitted_transformer` can be an
        estimator, 'drop', or 'passthrough'. In case there were no columns
        selected, this will be the unfitted transformer.
        If there are remaining columns, the final element is a tuple of the
        form:
        ('remainder', transformer, remaining_columns) corresponding to the
        ``remainder`` parameter. If there are remaining columns, then
        ``len(transformers_)==len(transformers)+1``, otherwise
        ``len(transformers_)==len(transformers)``.

    named_transformers_ : Bunch object, a dictionary with attribute access
        Read-only attribute to access any transformer by given name.
        Keys are transformer names and values are the fitted transformer
        objects.

    sparse_output_ : boolean
        Boolean flag indicating wether the output of ``transform`` is a
        sparse matrix or a dense numpy array, which depends on the output
        of the individual transformers and the `sparse_threshold` keyword.

    Notes
    -----
    The order of the columns in the transformed feature matrix follows the
    order of how the columns are specified in the `transformers` list.
    Columns of the original feature matrix that are not specified are
    dropped from the resulting transformed feature matrix, unless specified
    in the `passthrough` keyword. Those columns specified with `passthrough`
    are added at the right to the output of the transformers.

    See also
    --------
    sklearn.compose.make_column_transformer : convenience function for
        combining the outputs of multiple transformer objects applied to
        column subsets of the original feature space.

    Examples
    --------
    >>> from sklearn.compose import ColumnTransformer
    >>> from sklearn.preprocessing import Normalizer
    >>> ct = ColumnTransformer(
    ...     [("norm1", Normalizer(norm='l1'), [0, 1]),
    ...      ("norm2", Normalizer(norm='l1'), slice(2, 4))])
    >>> X = np.array([[0., 1., 2., 2.],
    ...               [1., 1., 0., 1.]])
    >>> # Normalizer scales each row of X to unit norm. A separate scaling
    >>> # is applied for the two first and two last elements of each
    >>> # row independently.
    >>> ct.fit_transform(X)    # doctest: +NORMALIZE_WHITESPACE
    array([[0. , 1. , 0.5, 0.5],
           [0.5, 0.5, 0. , 1. ]])

    t   dropg333333Ó?c         C   s1   | |  _  | |  _ | |  _ | |  _ | |  _ d  S(   N(   t   transformerst	   remaindert   sparse_thresholdt   n_jobst   transformer_weights(   t   selfR   R   R   R   R   (    (    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pyt   __init__£   s
    				c         C   s)   g  |  j  D] \ } } } | | f ^ q
 S(   sü   
        Internal list of transformer only containing the name and
        transformers, dropping the columns. This is for the implementation
        of get_params via BaseComposition._get_params which expects lists
        of tuples of len 2.
        (   R   (   R   t   namet   transt   _(    (    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pyt   _transformers«   s    c         C   sJ   g  t  | |  j ƒ D]* \ \ } } \ } } } | | | f ^ q |  _ d  S(   N(   t   zipR   (   R   t   valueR   R   R   t   col(    (    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pyR   µ   s    c         C   s   |  j  d d | ƒS(   so  Get parameters for this estimator.

        Parameters
        ----------
        deep : boolean, optional
            If True, will return the parameters for this estimator and
            contained subobjects that are estimators.

        Returns
        -------
        params : mapping of string to any
            Parameter names mapped to their values.
        R   t   deep(   t   _get_params(   R   R!   (    (    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pyt
   get_params»   s    c         K   s   |  j  d |  |  S(   sŸ   Set the parameters of this estimator.

        Valid parameter keys can be listed with ``get_params()``.

        Returns
        -------
        self
        R   (   t   _set_params(   R   t   kwargs(    (    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pyt
   set_paramsË   s    	c   	      c   s  | r |  j  } nk g  t |  j |  j ƒ D]$ \ \ } } } } | | | f ^ q( } |  j d d k	 r} t | |  j g ƒ } n  |  j p‰ i  j } x… | D]} \ } } } | rü | d k rÕ t	 d t
 d t d t
 ƒ } qü | d k rç q– qü t | ƒ rü q– qü n  | | | | | ƒ f Vq– Wd S(   s  
        Generate (name, trans, column, weight) tuples.

        If fitted=True, use the fitted transformers, else use the
        user specified transformers updated with converted column names
        and potentially appended with transformer for remainder.

        i   t   passthrought   validatet   accept_sparset   check_inverseR   N(   t   transformers_R   R   t   _columnst
   _remaindert   NoneR   R   t   getR   t   Falset   Truet   _is_empty_column_selection(	   R   t   fittedt   replace_stringsR   R   R   R   t   columnt
   get_weight(    (    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pyt   _iter×   s$    	=	c         C   s§   |  j  s d  St |  j  Œ  \ } } } |  j | ƒ xn | D]f } | d k rQ q9 n  t | d ƒ pl t | d ƒ s€ t | d ƒ r9 t d | t | ƒ f ƒ ‚ q9 q9 Wd  S(   NR   R'   t   fitt   fit_transformt	   transformsx   All estimators should implement fit and transform, or can be 'drop' or 'passthrough' specifiers. '%s' (type %s) doesn't.(   R   R'   (   R   R   t   _validate_namest   hasattrt	   TypeErrort   type(   R   t   namesR   R   t   t(    (    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pyt   _validate_transformersü   s    	c         C   sX   g  } xB |  j  D]7 \ } } } t | ƒ r: | | ƒ } n  | j | ƒ q W| |  _ d S(   s:   
        Converts callable column specifications.
        N(   R   t   callablet   appendR,   (   R   t   Xt   columnsR   R5   (    (    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pyt   _validate_column_callables  s    c         C   sæ   t  |  j d ƒ s$ t  |  j d ƒ o3 t  |  j d ƒ } |  j d
 k rb | rb t d |  j ƒ ‚ n  | j d } g  } x' |  j D] } | j t | | ƒ ƒ q Wt t t	 t
 | ƒ ƒ t	 | ƒ ƒ ƒ pÊ d	 } d |  j | f |  _ d	 S(   sm   
        Validates ``remainder`` and defines ``_remainder`` targeting
        the remaining columns.
        R8   R9   R:   R   R'   se   The remainder keyword needs to be one of 'drop', 'passthrough', or estimator. '%s' was passed insteadi   R   N(   R   R'   (   R<   R   t
   ValueErrort   shapeR,   t   extendt   _get_column_indicest   sortedt   listt   sett   rangeR.   R-   (   R   RD   t   is_transformert	   n_columnst   colsRE   t   remaining_idx(    (    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pyt   _validate_remainder  s    .c         C   s5   t  t g  |  j D] \ } } } | | f ^ q ƒ   S(   sÐ   Access the fitted transformer by name.

        Read-only attribute to access any transformer by given name.
        Keys are transformer names and values are the fitted transformer
        objects.

        (   R   t   dictR+   (   R   R   R   R   (    (    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pyt   named_transformers_2  s    
	c         C   sÒ   t  |  d ƒ g  } x¸ |  j d t ƒ D]¤ \ } } } } | d k rJ q& nR | d k re t d ƒ ‚ n7 t | d ƒ sœ t d t | ƒ t | ƒ j f ƒ ‚ n  | j	 g  | j
 ƒ  D] } | d | ^ q¯ ƒ q& W| S(	   s³   Get feature names from all transformers.

        Returns
        -------
        feature_names : list of strings
            Names of the features produced by transform.
        R+   R3   R   R'   sN   get_feature_names is not yet supported when using a 'passthrough' transformer.t   get_feature_namess<   Transformer %s (type %s) does not provide get_feature_names.t   __(   R   R7   R1   t   NotImplementedErrorR<   t   AttributeErrort   strR>   t   __name__RI   RV   (   R   t   feature_namesR   R   R   t   f(    (    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pyRV   ?  s    %"	)c   	      C   sÀ   t  | ƒ } g  } x‹ |  j ƒ  D]} \ } } } } | d k rF d } n@ | d k re t | ƒ d } n! t | ƒ rz | } n t | ƒ } | j | | | f ƒ q Wt | ƒ s³ t ‚ | |  _ d  S(   NR   R'   (   t   iterR7   t   nextR2   RC   RL   t   AssertionErrorR+   (	   R   R   t   fitted_transformersR+   R   t   oldR5   R   R   (    (    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pyt   _update_fitted_transformersX  s    	
		c         C   s‹   g  |  j  d t d t ƒ D] \ } } } } | ^ q } xM t | | ƒ D]< \ } } t | d d ƒ d k sG t d j | ƒ ƒ ‚ qG qG Wd S(   s   
        Ensure that the output of each transformer is 2D. Otherwise
        hstack can raise an error or produce incorrect results.
        R3   R4   t   ndimi    i   s\   The output of the '{0}' transformer should be 2D (scipy matrix, array, or pandas DataFrame).N(   R7   R1   R   t   getattrRG   t   format(   R   t   resultR   R   R?   t   Xs(    (    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pyt   _validate_outputo  s    %c            sƒ   yE t  d |  j ƒ ‡  ‡ ‡ ‡ f d †  |  j d ˆ d t ƒ Dƒ ƒ SWn7 t k
 r~ } d t | ƒ k rx t t ƒ ‚ q ‚  n Xd S(   sî   
        Private function to fit and/or transform on demand.

        Return value (transformers and/or transformed X data) depends
        on the passed function.
        ``fitted=True`` ensures the fitted transformers are used.
        R   c         3   sQ   |  ]G \ } } } } t  ˆ ƒ ˆ s0 t | ƒ n | t ˆ  | ƒ ˆ | ƒ Vq d  S(   N(   R   R   t   _get_column(   t   .0R   R   R5   t   weight(   RD   R3   t   funct   y(    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pys	   <genexpr>†  s   R3   R4   s'   Expected 2D array, got 1D array insteadN(   R   R   R7   R1   RG   RZ   t   _ERR_MSG_1DCOLUMN(   R   RD   Rn   Rm   R3   t   e(    (   RD   R3   Rm   Rn   sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pyt   _fit_transform|  s    	c         C   s   |  j  | d | ƒ|  S(   s¸  Fit all transformers using X.

        Parameters
        ----------
        X : array-like or DataFrame of shape [n_samples, n_features]
            Input data, of which specified subsets are used to fit the
            transformers.

        y : array-like, shape (n_samples, ...), optional
            Targets for supervised learning.

        Returns
        -------
        self : ColumnTransformer
            This estimator

        Rn   (   R9   (   R   RD   Rn   (    (    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pyR8     s    c   	      C   s  t  | ƒ } |  j ƒ  |  j | ƒ |  j | ƒ |  j | | t ƒ } | sr |  j g  ƒ t j | j	 d d f ƒ St
 | Œ  \ } } t d „  | Dƒ ƒ rå t d „  | Dƒ ƒ } t d „  | Dƒ ƒ } | | } | |  j k  |  _ n	 t |  _ |  j | ƒ |  j | ƒ |  j t | ƒ ƒ S(   sç  Fit all transformers, transform the data and concatenate results.

        Parameters
        ----------
        X : array-like or DataFrame of shape [n_samples, n_features]
            Input data, of which specified subsets are used to fit the
            transformers.

        y : array-like, shape (n_samples, ...), optional
            Targets for supervised learning.

        Returns
        -------
        X_t : array-like or sparse matrix, shape (n_samples, sum_n_components)
            hstack of results of transformers. sum_n_components is the
            sum of n_components (output dimension) over transformers. If
            any result is a sparse matrix, everything will be converted to
            sparse matrices.

        i    c         s   s   |  ] } t  j | ƒ Vq d  S(   N(   R   t   issparse(   Rk   RD   (    (    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pys	   <genexpr>Ë  s    c         s   s0   |  ]& } t  j | ƒ r! | j n | j Vq d  S(   N(   R   Rr   t   nnzt   size(   Rk   RD   (    (    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pys	   <genexpr>Ì  s    c         s   s?   |  ]5 } t  j | ƒ r0 | j d  | j d n | j Vq d S(   i    i   N(   R   Rr   RH   Rt   (   Rk   RD   (    (    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pys	   <genexpr>Í  s   (   t   _check_XRA   RF   RS   Rq   R   Rc   t   npt   zerosRH   R   t   anyt   sumR   t   sparse_output_R0   Ri   t   _hstackRL   (	   R   RD   Rn   Rg   Rh   R   Rs   t   totalt   density(    (    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pyR9   §  s&    
	
	c         C   st   t  |  d ƒ t | ƒ } |  j | d t d t ƒ} |  j | ƒ | sa t j | j	 d d f ƒ S|  j
 t | ƒ ƒ S(   sP  Transform X separately by each transformer, concatenate results.

        Parameters
        ----------
        X : array-like or DataFrame of shape [n_samples, n_features]
            The data to be transformed by subset.

        Returns
        -------
        X_t : array-like or sparse matrix, shape (n_samples, sum_n_components)
            hstack of results of transformers. sum_n_components is the
            sum of n_components (output dimension) over transformers. If
            any result is a sparse matrix, everything will be converted to
            sparse matrices.

        R+   R3   i    N(   R   Ru   Rq   R.   R	   R1   Ri   Rv   Rw   RH   R{   RL   (   R   RD   Rh   (    (    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pyR:   Ù  s    c         C   s°   |  j  rk y/ g  | D] } t | d t d t ƒ^ q } Wn t k
 rW t d ƒ ‚ n Xt j | ƒ j ƒ  Sg  | D]' } t j | ƒ r“ | j	 ƒ  n | ^ qr } t
 j | ƒ Sd S(   s  Stacks Xs horizontally.

        This allows subclasses to control the stacking behavior, while reusing
        everything else from ColumnTransformer.

        Parameters
        ----------
        Xs : List of numpy arrays, sparse arrays, or DataFrames
        R)   t   force_all_finitesQ   For a sparse output, all columns should be a numeric or convertible to a numeric.N(   Rz   R   R1   R0   RG   R   t   hstackt   tocsrRr   t   toarrayRv   (   R   Rh   RD   t   converted_XsR]   (    (    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pyR{   ö  s    
	,4N(   R[   t
   __module__t   __doc__R.   R   t   propertyR   t   setterR1   R#   R&   R0   R7   RA   RF   RS   RU   RV   Rc   Ri   Rq   R8   R9   R:   R{   (    (    (    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pyR   #   s(   ~
	%						2	c         C   s;   t  |  d ƒ s t j |  ƒ r" |  St |  d d d t j ƒS(   s@   Use check_array only on lists and other non-array-likes / sparset	   __array__R~   s	   allow-nant   dtype(   R<   R   Rr   R   Rv   t   object(   RD   (    (    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pyRu     s    c            sÇ   t  |  ˆ  ƒ r t St  |  t ƒ r\ t  |  j ˆ  t d ƒ f ƒ o[ t  |  j ˆ  t d ƒ f ƒ St  |  t ƒ r… t ‡  f d †  |  Dƒ ƒ St	 |  d ƒ rÃ ˆ  t
 k r° |  j j d k S|  j j d k Sn  t S(	   s¡  
    Check that scalar, list or slice is of a certain type.

    This is only used in _get_column and _get_column_indices to check
    if the `key` (column specification) is fully integer or fully string-like.

    Parameters
    ----------
    key : scalar, list, slice, array-like
        The column specification to check
    superclass : int or six.string_types
        The type for which to check the `key`

    c         3   s   |  ] } t  | ˆ  ƒ Vq d  S(   N(   t
   isinstance(   Rk   t   x(   t
   superclass(    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pys	   <genexpr>/  s    Rˆ   t   it   Ot   Ut   SN(   RŽ   R   R   (   RŠ   R1   t   slicet   startR>   R.   t   stopRL   t   allR<   t   intRˆ   t   kindR0   (   t   keyRŒ   (    (   RŒ   sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pyt   _check_key_type  s    c         C   s   t  | t ƒ r t } no t  | t j ƒ r3 t } nT t | d ƒ r{ t j | j	 t j
 ƒ r{ t } t |  d ƒ r‡ t } q‡ n t d ƒ ‚ | rÂ t |  d ƒ r³ |  j d d … | f St d ƒ ‚ n: t |  d ƒ rè |  j d d … | f S|  d d … | f Sd S(   s_  
    Get feature column(s) from input data X.

    Supported input types (X): numpy arrays, sparse arrays and DataFrames

    Supported key types (key):
    - scalar: output is 1D
    - lists, slices, boolean masks: output is 2D
    - callable that returns any of the above

    Supported key data types:

    - integer or boolean mask (positional):
        - supported for arrays, sparse matrices and dataframes
    - string (key-based):
        - only supported for dataframes
        - So no keys other than strings are allowed (while in principle you
          can use any hashable object as key).

    Rˆ   t   locs~   No valid specification of the columns. Only a scalar, list or slice of all integers or all strings, or boolean mask is allowedNsL   Specifying the columns using strings is only supported for pandas DataFramest   iloc(   R˜   R•   R0   R   t   string_typesR1   R<   Rv   t
   issubdtypeRˆ   t   bool_RG   R™   Rš   (   RD   R—   t   column_names(    (    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pyRj   9  s     		'c   	      C   s‘  |  j  d } t | t ƒ sC t | d ƒ ri t j | j t j ƒ ri t j | ƒ | } t j	 | ƒ j
 ƒ  St | t j ƒ ry t |  j ƒ } Wn t k
 r­ t d ƒ ‚ n Xt | t j ƒ rÌ | g } n• t | t ƒ rU| j | j } } | d k	 r| j | ƒ } n  | d k	 r.| j | ƒ d } n
 | d } t t | ƒ t | | ƒ ƒ St | ƒ } g  | D] } | j | ƒ ^ qhSt d ƒ ‚ d S(   sƒ   
    Get feature column indices for input data X and key.

    For accepted values of `key`, see the docstring of _get_column

    i   Rˆ   sL   Specifying the columns using strings is only supported for pandas DataFramess~   No valid specification of the columns. Only a scalar, list or slice of all integers or all strings, or boolean mask is allowedN(   RH   R˜   R•   R<   Rv   Rœ   Rˆ   R   t   aranget
   atleast_1dt   tolistR   R›   RL   RE   RY   RG   RŠ   R‘   R’   R“   R.   t   indexRN   (	   RD   R—   RP   t   idxt   all_columnsRE   R’   R“   R    (    (    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pyRJ   n  s.    '
 c         C   sY   t  |  d ƒ r2 t j |  j t j ƒ r2 |  j ƒ  St  |  d ƒ rQ t |  ƒ d k St Sd S(   sd   
    Return True if the column selection is empty (empty list or all-False
    boolean array).

    Rˆ   t   __len__i    N(   R<   Rv   Rœ   Rˆ   R   Rx   t   lenR0   (   R5   (    (    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pyR2   ˜  s
    'c         C   sv   |  s
 t  Sxe |  D]] } t | t j ƒ r; | d k r; q n  t | d ƒ pV t | d ƒ sj t | d ƒ r t Sq Wt  S(   sŠ   Checks if given transformers are valid.

    This is a helper function to support the deprecated tuple order.
    XXX Remove in v0.22
    R   R'   R8   R9   R:   (   R   R'   (   R1   RŠ   R   R›   R<   R0   (   R   R@   (    (    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pyRA   ¦  s    c         C   s3   t  |  Œ  \ } } t | ƒ r/ t | ƒ r/ t St S(   s,  Checks if the input follows the deprecated tuple order.

    Returns
    -------
    Returns true if (transformer, columns) is not a valid assumption for the
    input, but (columns, transformer) is valid. The latter is deprecated and
    its support will stop in v0.22.

    XXX Remove in v0.22
    (   R   RA   R1   R0   (   t   tuplesR   RE   (    (    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pyt   _is_deprecated_tuple_order¹  s
    c         C   sx   d } t  |  Œ  \ } } t |  ƒ rD | | } } t j | t ƒ n  t  t | ƒ Œ  \ } } t t  | | | ƒ ƒ } | S(   s;   
    Construct (name, trans, column) tuples from list

    sø   `make_column_transformer` now expects (transformer, columns) as input tuples instead of (columns, transformer). This has been introduced in v0.20.1. `make_column_transformer` will stop accepting the deprecated (columns, transformer) order in v0.22.(   R   R¨   t   warningst   warnt   DeprecationWarningR
   RL   (   t
   estimatorst   messageR   RE   R?   R   t   transformer_list(    (    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pyt   _get_transformer_listÌ  s    c          O   sŒ   | j  d d ƒ } | j  d d ƒ } | j  d d ƒ } | rd t d j t | j ƒ  ƒ d ƒ ƒ ‚ n  t |  ƒ } t | d | d | d | ƒS(	   sX  Construct a ColumnTransformer from the given transformers.

    This is a shorthand for the ColumnTransformer constructor; it does not
    require, and does not permit, naming the transformers. Instead, they will
    be given names automatically based on their types. It also does not allow
    weighting with ``transformer_weights``.

    Parameters
    ----------
    *transformers : tuples of transformers and column selections

    remainder : {'drop', 'passthrough'} or estimator, default 'drop'
        By default, only the specified columns in `transformers` are
        transformed and combined in the output, and the non-specified
        columns are dropped. (default of ``'drop'``).
        By specifying ``remainder='passthrough'``, all remaining columns that
        were not specified in `transformers` will be automatically passed
        through. This subset of columns is concatenated with the output of
        the transformers.
        By setting ``remainder`` to be an estimator, the remaining
        non-specified columns will use the ``remainder`` estimator. The
        estimator must support `fit` and `transform`.

    sparse_threshold : float, default = 0.3
        If the transformed output consists of a mix of sparse and dense data,
        it will be stacked as a sparse matrix if the density is lower than this
        value. Use ``sparse_threshold=0`` to always return dense.
        When the transformed output consists of all sparse or all dense data,
        the stacked result will be sparse or dense, respectively, and this
        keyword will be ignored.

    n_jobs : int or None, optional (default=None)
        Number of jobs to run in parallel.
        ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
        ``-1`` means using all processors. See :term:`Glossary <n_jobs>`
        for more details.

    Returns
    -------
    ct : ColumnTransformer

    See also
    --------
    sklearn.compose.ColumnTransformer : Class that allows combining the
        outputs of multiple transformer objects used on column subsets
        of the data into a single feature space.

    Examples
    --------
    >>> from sklearn.preprocessing import StandardScaler, OneHotEncoder
    >>> from sklearn.compose import make_column_transformer
    >>> make_column_transformer(
    ...     (StandardScaler(), ['numerical_column']),
    ...     (OneHotEncoder(), ['categorical_column']))
    ...     # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
    ColumnTransformer(n_jobs=None, remainder='drop', sparse_threshold=0.3,
             transformer_weights=None,
             transformers=[('standardscaler',
                            StandardScaler(...),
                            ['numerical_column']),
                           ('onehotencoder',
                            OneHotEncoder(...),
                            ['categorical_column'])])

    R   R   R   R   g333333Ó?s   Unknown keyword arguments: "{}"i    N(   t   popR.   R=   Rf   RL   t   keysR¯   R   (   R   R%   R   R   R   R®   (    (    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pyR   ä  s    D	(+   R„   t
   __future__R    t	   itertoolsR   t   numpyRv   R©   t   scipyR   t   baseR   R   t   utils._joblibR   R   t	   externalsR   t   pipelineR   R	   R
   t   preprocessingR   t   utilsR   t   utils.metaestimatorsR   t   utils.validationR   R   t   __all__Ro   R   Ru   R˜   Rj   RJ   R2   RA   R¨   R¯   R   (    (    (    sB   lib/python2.7/site-packages/sklearn/compose/_column_transformer.pyt   <module>   s4   ÿ ñ			5	*				