o
    i                     @   s  d dl Z d dlZd dlZd dlmZ d dlmZ d dlm	Z	m
Z
mZmZmZmZ d dlm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 d dlmZ d dl m!Z! d dl"m#Z#m$Z$ d dl%m&Z& d dl'm(Z( ej)dd Z*ej)dd Z+ej,-de dfe dfe!e$ e dfe!e$ e dfe$ dfe dfe dfee$ d gfe# dgfdfgej,-dg ddd Z.edddd Z/dd Z0d d! Z1d"d# Z2d$d% Z3d&d' Z4dS )(    N)assert_array_equal)config_context)BaseEstimatorcloneis_classifieris_clustereris_outlier_detectoris_regressor)KMeans)make_column_transformer)make_classificationmake_regression)NotFittedErrorUnsetMetadataPassedError)FrozenEstimator)LinearRegressionLogisticRegression)LocalOutlierFactor)make_pipeline)RobustScalerStandardScaler)set_random_state)check_is_fittedc                   C      t  S N)r    r   r   o/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/sklearn/frozen/tests/test_frozen.pyregression_dataset       r   c                   C   r   r   )r   r   r   r   r   classification_dataset%   r   r   zestimator, dataset   method)predictZpredict_probaZpredict_log_probaZdecision_functionZ	transformc                 C   s   | |\}}t|  | || t| }|dggdg t| |r2tt| ||t||| t| t|ks<J t| t|ksFJ t	| t	|ksPJ t
| t
|ksZJ dS )zTest that frozen.fit doesn't do anything, and that all other methods are
    exposed by the frozen estimator and return the same values as the estimator.
    r    N)Zgetfixturevaluer   fitr   hasattrr   getattrr   r	   r   r   )	estimatorZdatasetrequestr!   Xyfrozenr   r   r   test_frozen_methods*   s   
r+   T)Zenable_metadata_routingc                 C   s  G dd dt }| \}}t|dddjddjdd}|j||dd t|}|j|dd |j|dd |d jdd tjt	t
d	d
 |j|dd W d   n1 sZw   Y  |d jdd tt |j|dd W d   dS 1 sw   Y  dS )z8Test that metadata routing works with frozen estimators.c                   @   s*   e Zd ZdddZd	ddZd	ddZdS )
z6test_frozen_metadata_routing.<locals>.ConsumesMetadataNc                 S   s   || _ || _d S r   on_fit
on_predict)selfr-   r.   r   r   r   __init__]   s   
z?test_frozen_metadata_routing.<locals>.ConsumesMetadata.__init__c                 S   s   | j r	|d us	J d| _| S NT)r-   Zfitted_)r/   r(   r)   metadatar   r   r   r#   a   s   z:test_frozen_metadata_routing.<locals>.ConsumesMetadata.fitc                 S   s    | j r	|d us	J tt|S r   )r.   npZoneslen)r/   r(   r2   r   r   r   r"   g   s   z>test_frozen_metadata_routing.<locals>.ConsumesMetadata.predict)NNr   )__name__
__module____qualname__r0   r#   r"   r   r   r   r   ConsumesMetadata\   s    

r8   Tr,   )r2   testZconsumesmetadataFz]Pipeline.predict got unexpected argument(s) {'metadata'}, which are not routed to any object.matchN)r   r   Zset_fit_requestZset_predict_requestr#   r   r"   pytestraises	TypeErrorreescaper   )r   r8   r(   r)   Zpipeliner*   r   r   r   test_frozen_metadata_routingX   s4   
	"rA   c                 C   s   G dd dt }| \}}| ||}t|}tt ||| W d   n1 s-w   Y  tt ||| W d   n1 sHw   Y  |jdksTJ dS )zATest that calling fit_transform and fit_predict doesn't call fit.c                   @   s(   e Zd Zdd ZdddZdddZdS )	z%test_composite_fit.<locals>.Estimatorc                 S   s0   z
|  j d7  _ W | S  ty   d| _ Y | S w )Nr    )_fit_counterAttributeErrorr/   r(   r)   r   r   r   r#      s   z)test_composite_fit.<locals>.Estimator.fitNc                 S      d S r   r   rD   r   r   r   fit_transform      z3test_composite_fit.<locals>.Estimator.fit_transformc                 S   rE   r   r   rD   r   r   r   fit_predict   rG   z1test_composite_fit.<locals>.Estimator.fit_predictr   )r5   r6   r7   r#   rF   rH   r   r   r   r   	Estimator   s    
rI   Nr    )	r   r#   r   r<   r=   rC   rH   rF   rB   )r   rI   r(   r)   estr*   r   r   r   test_composite_fit   s   rK   c                 C   s8   | \}}t  ||}t|}t|}|j|u sJ dS )z<Test that cloning a frozen estimator keeps the frozen state.N)r   r#   r   r   r&   )r   r(   r)   r&   r*   Zclonedr   r   r   test_clone_frozen   s
   rL   c                 C   sj   | \}}t  }t|}tt t| W d   n1 sw   Y  t  ||}t|}t| dS )z5Test that check_is_fitted works on frozen estimators.N)r   r   r<   r=   r   r   r#   )r   r(   r)   r&   r*   r   r   r   test_check_is_fitted   s   
rM   c                  C   sn   G dd dt } |  }t|}| }| }|jdu sJ |jdu s%J |jjdu s-J |jjdu s5J dS )zjTest that frozen estimators have the same tags as the original estimator
    except for the skip_test tag.c                       s   e Zd Z fddZ  ZS )z#test_frozen_tags.<locals>.Estimatorc                    s   t   }d|j_|S r1   )super__sklearn_tags__
input_tagscategorical)r/   tags	__class__r   r   rO      s   
z4test_frozen_tags.<locals>.Estimator.__sklearn_tags__)r5   r6   r7   rO   __classcell__r   r   rS   r   rI      s    rI   TFN)r   r   rO   Z
_skip_testrP   rQ   )rI   r&   r*   Zfrozen_tagsZestimator_tagsr   r   r   test_frozen_tags   s   rV   c                  C   s   t  } t| }tjtdd |jdd W d   n1 sw   Y  | d| iks.J t }|j|d | d|iksAJ dS )z?Test that FrozenEstimator only exposes the estimator parameter.z&You cannot set parameters of the innerr:   r    )Zestimator__CNr&   )r&   )r   r   r<   r=   
ValueErrorZ
set_params
get_paramsr   )rJ   r*   Z	other_estr   r   r   test_frozen_params   s   rY   )5r?   numpyr3   r<   Znumpy.testingr   Zsklearnr   Zsklearn.baser   r   r   r   r   r	   Zsklearn.clusterr
   Zsklearn.composer   Zsklearn.datasetsr   r   Zsklearn.exceptionsr   r   Zsklearn.frozenr   Zsklearn.linear_modelr   r   Zsklearn.neighborsr   Zsklearn.pipeliner   Zsklearn.preprocessingr   r   Zsklearn.utils._testingr   Zsklearn.utils.validationr   Zfixturer   r   markZparametrizer+   rA   rK   rL   rM   rV   rY   r   r   r   r   <module>   sh    




.	