
     h"                         d dl m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dZd Zd Zd Z G d d          ZdddZdS )    wraps)issparse   )check_pandas_support   )
get_config)available_ifN)indexc                &   t          |           rt          d          t          |          r	  |            }n# t          $ r d}Y nw xY wt	          d          }t          | |j                  r||| _        | S |                    | ||          S )aA  Create a Pandas DataFrame.

    If `data_to_wrap` is a DataFrame, then the `columns` and `index` will be changed
    inplace. If `data_to_wrap` is a ndarray, then a new DataFrame is created with
    `columns` and `index`.

    Parameters
    ----------
    data_to_wrap : {ndarray, dataframe}
        Data to be wrapped as pandas dataframe.

    columns : callable, ndarray, or None
        The column names or a callable that returns the column names. The
        callable is useful if the column names require some computation.
        If `columns` is a callable that raises an error, `columns` will have
        the same semantics as `None`. If `None` and `data_to_wrap` is already a
        dataframe, then the column names are not changed. If `None` and
        `data_to_wrap` is **not** a dataframe, then columns are
        `range(n_features)`.

    index : array-like, default=None
        Index for data. `index` is ignored if `data_to_wrap` is already a DataFrame.

    Returns
    -------
    dataframe : DataFrame
        Container with column names or unchanged `output`.
    z+Pandas output does not support sparse data.Nz$Setting output container to 'pandas')r   columns)r   
ValueErrorcallable	Exceptionr   
isinstance	DataFramer   )data_to_wrapr   r   pds       U/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/sklearn/utils/_set_output.py_wrap_in_pandas_containerr   
   s    D  HFGGG 	giiGG 	 	 	GGG	 
D	E	EB,-- #*L <<E7<CCCs   
: A	A	c                     t          |di           }| |v r	||          }nt                      |  d         }|dvrt          d|           d|iS )a  Get output config based on estimator and global configuration.

    Parameters
    ----------
    method : {"transform"}
        Estimator's method for which the output container is looked up.

    estimator : estimator instance or None
        Estimator to get the output configuration from. If `None`, check global
        configuration is used.

    Returns
    -------
    config : dict
        Dictionary with keys:

        - "dense": specifies the dense container for `method`. This can be
          `"default"` or `"pandas"`.
    _sklearn_output_config_output>   pandasdefaultz0output config must be 'default' or 'pandas' got dense)getattrr	   r   )method	estimatorest_sklearn_output_configdense_configs       r   _get_output_configr"   ?   s|    ( !(	3KR P P***08!||v$6$6$67000M|MM
 
 	
 \""    c                     t          | |          }|d         dk    st          |          s|S t          |t          |dd          |j                  S )a  Wrap output with container based on an estimator's or global config.

    Parameters
    ----------
    method : {"transform"}
        Estimator's method to get container output for.

    data_to_wrap : {ndarray, dataframe}
        Data to wrap with container.

    original_input : {ndarray, dataframe}
        Original input of function.

    estimator : estimator instance
        Estimator with to get the output configuration from.

    Returns
    -------
    output : {ndarray, dataframe}
        If the output config is "default" or the estimator is not configured
        for wrapping return `data_to_wrap` unchanged.
        If the output config is "pandas", return `data_to_wrap` as a pandas
        DataFrame.
    r   r   r   N)r   r   r   )r"   _auto_wrap_is_configuredr   r   get_feature_names_out)r   r   original_inputr   output_configs        r   _wrap_data_with_containerr)   a   sh    2 'vy99MW**2J92U2U* %!ngt44/   r#   c                 @     t                      fd            }|S )z@Wrapper used by `_SetOutputMixin` to automatically wrap methods.c                      | |g|R i |}t          |t                    r$t          |d         ||           g|dd          R S t          |||           S )Nr   r   )r   tupler)   )selfXargskwargsr   fr   s        r   wrappedz$_wrap_method_output.<locals>.wrapped   s    qq24222622lE** 	 *&,q/1dKKabb!  
 )q$GGGr#   r   )r1   r   r2   s   `` r   _wrap_method_outputr3      sA     1XX	H 	H 	H 	H 	H X	H Nr#   c                 d    t          | dt                                }t          | d          od|v S )zReturn True if estimator is configured for auto-wrapping the transform method.

    `_SetOutputMixin` sets `_sklearn_auto_wrap_output_keys` to `set()` if auto wrapping
    is manually disabled.
    _sklearn_auto_wrap_output_keysr&   	transform)r   sethasattr)r   auto_wrap_output_keyss     r   r%   r%      s?     $I/OQTQVQVWW	233 	100r#   c                   R     e Zd ZdZd fd	Z ee          ddd            Z xZS )_SetOutputMixina\  Mixin that dynamically wraps methods to return container based on config.

    Currently `_SetOutputMixin` wraps `transform` and `fit_transform` and configures
    it based on `set_output` of the global configuration.

    `set_output` is only defined if `get_feature_names_out` is defined and
    `auto_wrap_output_keys` is the default value.
    r6   c                     t                      j        di | t          |t                    s|t	          d          |t                      | _        d S ddd}t                      | _        |                                D ]m\  }}t          | |          r||vr| j        	                    |           || j
        vr>t          t          | |          |          }t          | ||           nd S )Nz6auto_wrap_output_keys must be None or a tuple of keys.r6   )r6   fit_transform )super__init_subclass__r   r,   r   r7   r5   itemsr8   add__dict__r3   r   setattr)clsr9   r0   method_to_keyr   keywrapped_method	__class__s          r   rA   z!_SetOutputMixin.__init_subclass__   s$   !!++F+++
 ,e44	W8M8UUVVV (14C.F %(
 
 .1UU*(..00 		1 		1KFC3'' 36K+K+K.223777 S\))0f1E1EsKKNC0000		1 		1r#   Nc                P    || S t          | d          si | _        || j        d<   | S )aD  Set output container.

        See :ref:`sphx_glr_auto_examples_miscellaneous_plot_set_output.py`
        for an example on how to use the API.

        Parameters
        ----------
        transform : {"default", "pandas"}, default=None
            Configure output of `transform` and `fit_transform`.

            - `"default"`: Default output format of a transformer
            - `"pandas"`: DataFrame output
            - `None`: Transform configuration is unchanged

        Returns
        -------
        self : estimator instance
            Estimator instance.
        Nr   r6   )r8   r   )r-   r6   s     r   
set_outputz_SetOutputMixin.set_output   s<    * Kt566 	-*,D'3<#K0r#   )r<   )	__name__
__module____qualname____doc__rA   r
   r%   rL   __classcell__)rJ   s   @r   r;   r;      s|         1 1 1 1 1 1@ \*++&*     ,+    r#   r;   r<   c                    t          | d          pt          | d          o|du}|sdS t          | d          st          d|  d          |                     |          S )a  Safely call estimator.set_output and error if it not available.

    This is used by meta-estimators to set the output for child estimators.

    Parameters
    ----------
    estimator : estimator instance
        Estimator instance.

    transform : {"default", "pandas"}, default=None
        Configure output of the following estimator's methods:

        - `"transform"`
        - `"fit_transform"`

        If `None`, this operation is a no-op.

    Returns
    -------
    estimator : estimator instance
        Estimator instance.
    r6   r>   NrL   zUnable to configure output for z' because `set_output` is not available.r<   )r8   r   rL   )r   r6   set_output_for_transforms      r   _safe_set_outputrT      s    0 		;'' 	"9o.. "T! 
 $  	9l++ 
 i      
 
 	
 )444r#   )N)	functoolsr   scipy.sparser    r   _configr	   _available_ifr
   r   r"   r)   r3   r%   r;   rT   r?   r#   r   <module>rZ      s         ! ! ! ! ! ! " " " " " "             ' ' ' ' ' ' 	2D 2D 2D 2D 2Dj# # # #D# # #L  $
 
 
F F F F F F F FR .2 &5 &5 &5 &5 &5 &5 &5r#   