
    3;ji9                        d dl 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 Zd Ze G d	 d
e                      Z G d d          Z G d d          Z G d d          Z e            Ze                     e                       e                     e                       d ZddZddZd Zd Zd Z G d d          ZdddZdS )    Nwraps)Protocolruntime_checkable)issparse)
get_config)available_ifc                 ~    	 t          j        |           S # t          $ r}t          d|  d|  d          |d}~ww xY w)zCheck library is installed.zSetting output container to 'z' requires z to be installedN)	importlibimport_moduleImportError)libraryexcs     S/root/voice-cloning/.venv/lib/python3.11/site-packages/sklearn/utils/_set_output.pycheck_library_installedr      sp    &w///   G     
 
 	s    
<7<c                 \    t          |           r	  |             S # t          $ r Y d S w xY w| S N)callable	Exceptioncolumnss    r   get_columnsr      sJ     	799 	 	 	44	Ns   	 
))c                   4    e Zd ZU eed<   ddZd Zd Zd ZdS )	ContainerAdapterProtocolcontainer_libFc                     dS )a  Create container from `X_output` with additional metadata.

        Parameters
        ----------
        X_output : {ndarray, dataframe}
            Data to wrap.

        X_original : {ndarray, dataframe}
            Original input dataframe. This is used to extract the metadata that should
            be passed to `X_output`, e.g. pandas row index.

        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 `None`,
            then no columns are passed to the container's constructor.

        inplace : bool, default=False
            Whether or not we intend to modify `X_output` in-place. However, it does
            not guarantee that we return the same object if the in-place operation
            is not possible.

        Returns
        -------
        wrapped_output : container_type
            `X_output` wrapped into the container type.
        N )selfX_output
X_originalr   inplaces        r   create_containerz)ContainerAdapterProtocol.create_container'             c                     dS )a  Return True if X is a supported container.

        Parameters
        ----------
        Xs: container
            Containers to be checked.

        Returns
        -------
        is_supported_container : bool
            True if X is a supported container.
        Nr   )r   Xs     r   is_supported_containerz/ContainerAdapterProtocol.is_supported_containerC   r#   r$   c                     dS )aQ  Rename columns in `X`.

        Parameters
        ----------
        X : container
            Container which columns is updated.

        columns : ndarray of str
            Columns to update the `X`'s columns with.

        Returns
        -------
        updated_container : container
            Container with new names.
        Nr   r   r&   r   s      r   rename_columnsz'ContainerAdapterProtocol.rename_columnsQ   r#   r$   c                     dS )a  Stack containers horizontally (column-wise).

        Parameters
        ----------
        Xs : list of containers
            List of containers to stack.

        Returns
        -------
        stacked_Xs : container
            Stacked containers.
        Nr   )r   Xss     r   hstackzContainerAdapterProtocol.hstackb   r#   r$   N)F)	__name__
__module____qualname__str__annotations__r"   r'   r*   r-   r   r$   r   r   r   #   sc            8    "    r$   r   c                   ,    e Zd ZdZddZd Zd Zd ZdS )	PandasAdapterpandasTc                 X   t          d          }t          |          }|rt          ||j                  s\t          ||j                  r|j        }n&t          ||j        |j        f          r|j        }nd }|                    |||           }||                     ||          S |S )Nr5   )indexcopy)r   r   
isinstance	DataFramer7   Seriesr*   )r   r   r    r   r!   pdr7   s          r   r"   zPandasAdapter.create_containert   s    $X..g&& 	Mj2<@@ 	M
 (BL11  Jry(ABB "( ||HEG|LLH&&x999r$   c                 J    t          d          }t          ||j                  S )Nr5   r   r9   r:   )r   r&   r<   s      r   r'   z$PandasAdapter.is_supported_container   !    $X..!R\***r$   c                     ||_         |S r   r   r)   s      r   r*   zPandasAdapter.rename_columns        	r$   c                 N    t          d          }|                    |d          S )Nr5      )axisr   concat)r   r,   r<   s      r   r-   zPandasAdapter.hstack   s%    $X..yy!y$$$r$   NTr.   r/   r0   r   r"   r'   r*   r-   r   r$   r   r4   r4   q   sZ        M   0+ + +  % % % % %r$   r4   c                   ,    e Zd ZdZddZd Zd Zd ZdS )	PolarsAdapterpolarsTc                 0   t          d          }t          |          }t          |t          j                  r|                                n|}|rt          ||j                  s|                    ||d          S ||                     ||          S |S )NrK   row)schemaorient)r   r   r9   npndarraytolistr:   r*   )r   r   r    r   r!   pls         r   r"   zPolarsAdapter.create_container   s    $X..g&&&0"*&E&ER'.."""7 	Hj2<@@ 	H<<<GGG&&x999r$   c                 J    t          d          }t          ||j                  S )NrK   r>   )r   r&   rS   s      r   r'   z$PolarsAdapter.is_supported_container   r?   r$   c                     ||_         |S r   r   r)   s      r   r*   zPolarsAdapter.rename_columns   rA   r$   c                 N    t          d          }|                    |d          S )NrK   
horizontal)howrE   )r   r,   rS   s      r   r-   zPolarsAdapter.hstack   s%    $X..yyy...r$   NrG   rH   r   r$   r   rJ   rJ      sZ        M   + + +  / / / / /r$   rJ   c                   0    e Zd Zd Zed             Zd ZdS )ContainerAdaptersManagerc                     i | _         d S r   )adaptersr   s    r   __init__z!ContainerAdaptersManager.__init__   s    r$   c                 2    dht          | j                  z  S )Ndefault)setr\   r]   s    r   supported_outputsz*ContainerAdaptersManager.supported_outputs   s    {S////r$   c                 $    || j         |j        <   d S r   )r\   r   )r   adapters     r   registerz!ContainerAdaptersManager.register   s    /6g+,,,r$   N)r.   r/   r0   r^   propertyrb   re   r   r$   r   rZ   rZ      sM           0 0 X07 7 7 7 7r$   rZ   c                    | j         j                            d          d         }	 t          j        |         S # t
          $ rG}t          t          j                                                  }t          d| d| d          |d}~ww xY w)zGet the adapter that knows how to handle such container.

    See :class:`sklearn.utils._set_output.ContainerAdapterProtocol` for more
    details.
    .r   zZThe container does not have a registered adapter in scikit-learn. Available adapters are: z" while the container provided is: N)		__class__r/   splitADAPTERS_MANAGERr\   KeyErrorlistkeys
ValueError)	containermodule_namer   available_adapterss       r   _get_adapter_from_containerrs      s     %066s;;A>K(55   !"2";"@"@"B"BCC+'9+ +%+ + +
 
 		s   9 
B
ABB
c                 v    t          | |          d         }	 t          j        |         S # t          $ r Y dS w xY w)zGet container adapter.denseN)_get_output_configrk   r\   rl   )method	estimatordense_configs      r   _get_container_adapterrz      sK    %fi88AL(66   tts   * 
88c                     t          |di           }| |v r	||          }nt                      |  d         }t          j        }||vr"t	          d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_outputzoutput config must be in z, got ru   )getattrr   rk   rb   ro   sorted)rw   rx   est_sklearn_output_configry   rb   s        r   rv   rv      s    ( !(	3KR P P***08!||v$6$6$67(:,,,W/@(A(AWWWW
 
 	
 \""r$   c                 2   t          | |          }|d         dk    st          |          s|S |d         }t          |          r%t          d|                                 d          t
          j        |         }|                    |||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.
    ru   r`   zmThe transformer outputs a scipy sparse matrix. Try to set the transformer output to a dense array or disable z- output with set_output(transform='default').r   )	rv   _auto_wrap_is_configuredr   ro   
capitalizerk   r\   r"   get_feature_names_out)rw   data_to_wraporiginal_inputrx   output_configry   rd   s          r   _wrap_data_with_containerr   	  s    2 'vy99MW**2J92U2U* )L 
X&&((X X X
 
 	
 '5G##/ $   r$   c                 @     t                      fd            }|S )z@Wrapper used by `_SetOutputMixin` to automatically wrap methods.c                 6    | |g|R i |}t          |t                    ret          |d         ||           g|dd          R }t          t	          |          d          r"t	          |                              |          S |S t          |||           S )Nr   rC   _make)r9   tupler   hasattrtyper   )r   r&   argskwargsr   return_tuplefrw   s         r   wrappedz$_wrap_method_output.<locals>.wrapped:  s    qq24222622lE** 
	  *&,q/1dKKabb! L tL))733 >L))//===(q$GGGr$   r   )r   rw   r   s   `` r   _wrap_method_outputr   7  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~   ra   r   )rx   auto_wrap_output_keyss     r   r   r   N  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.
    r   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.r   )r   fit_transformr   )super__init_subclass__r9   r   ro   ra   r   itemsr   add__dict__r   r~   setattr)clsr   r   method_to_keyrw   keywrapped_methodri   s          r   r   z!_SetOutputMixin.__init_subclass__e  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 )a  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", "polars"}, default=None
            Configure output of `transform` and `fit_transform`.

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

            .. versionadded:: 1.4
                `"polars"` option was added.

        Returns
        -------
        self : estimator instance
            Estimator instance.
        Nr|   r   )r   r|   )r   r   s     r   
set_outputz_SetOutputMixin.set_output  s<    2 Kt566 	-*,D'3<#K0r$   )r   )	r.   r/   r0   __doc__r   r	   r   r   __classcell__)ri   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", "polars"}, 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.
    r   r   Nr   zUnable to configure output for z' because `set_output` is not available.r   )r   ro   r   )rx   r   set_output_for_transforms      r   _safe_set_outputr     s    .  'y+>>  	?++E	0E  $  	9l++ 
 i      
 
 	
 )444r$   r   )r   	functoolsr   typingr   r   numpyrP   scipy.sparser   sklearn._configr   sklearn.utils._available_ifr	   r   r   r   r4   rJ   rZ   rk   re   rs   rz   rv   r   r   r   r   r   r   r$   r   <module>r      sZ             . . . . . . . .     ! ! ! ! ! ! & & & & & & 4 4 4 4 4 4     J J J J Jx J J JZ'% '% '% '% '% '% '% '%T/ / / / / / / />	7 	7 	7 	7 	7 	7 	7 	7 ,+--    --// * * *   --// * * *  $    #  #  #  #F+ + +\  .
 
 
J J J J J J J JZ .2 $5 $5 $5 $5 $5 $5 $5r$   