o
    i3                     @   sp  d Z ddlZ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
 ddlZddlm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mZ ddlmZ ddlmZmZ ddlmZmZm Z m!Z! ddl"m#Z# ddl$m%Z%m&Z&m'Z' ddl(m)Z)m*Z* ddl+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8 dd Z9dVddZ:G dd deZ;ej<=dee:dddfe:dfee:ddfedddfedd d!d"d#d$fe; d%fgd&d' Z>e8e?e' e&d(d)d* Z@d+d, ZAej<Bd-ej<Bd.d/d0 ZCd1d2 ZDd3d4 ZEd5d6 ZFd7d8 ZGe?e
e' eeddgeG ZHej<j=d9eHe%d:d;d< ZId=d>gZJd?d@ ZKdAdB e'dCD ZLej<j=dCeLe%d:dDdE ZMdFdB e' D ZNej<j=d9eNe%d:dGdH ZOej<j=d9e?e' e%d:dIdJ ZPe?e
e'dCee! e e dKdLedMdNgZQej<j=d9eQe%d:dOdP ZRej<j=d9eQe%d:ej<=dQe4e/e5e0gdRdS ZSej<j=d9e' e%d:dTdU ZTdS )Wz.
General tests for all estimators in sklearn.
    N)partial)isgenerator)chain)LinAlgWarning)BaseEstimator)ColumnTransformer)ConvergenceWarning)enable_halving_search_cvenable_iterative_imputer)LogisticRegression)FeatureUnionmake_pipeline)FunctionTransformerMinMaxScalerOneHotEncoderStandardScaler)all_estimators)_get_check_estimator_ids_get_expected_failed_checks_tested_estimators)SkipTestignore_warnings)(check_dataframe_column_names_consistencycheck_estimator!check_get_feature_names_out_error$check_global_output_transform_pandas(check_global_set_output_transform_polarscheck_inplace_ensure_writeablecheck_param_validationcheck_set_output_transform!check_set_output_transform_pandas!check_set_output_transform_polars'check_transformer_get_feature_names_out.check_transformer_get_feature_names_out_pandasparametrize_with_checksc                  C   s4   t  D ]\} }d| }|  drJ |qd S )NzDBase estimators such as {0} should not be included in all_estimatorsbase)r   formatlower
startswith)nameZ	Estimatormsg r+   h/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/sklearn/tests/test_common.py test_all_estimator_no_base_class@   s   r-      c                 C      d S Nr+   )xyr+   r+   r,   _sample_funcI      r3   c                   @   s   e Zd ZdZdd ZdS )CallableEstimatorzqDummy development stub for an estimator.

    This is to make sure a callable estimator passes common tests.
    c                 C   r/   r0   r+   )selfr+   r+   r,   __call__S   r4   zCallableEstimator.__call__N)__name__
__module____qualname____doc__r7   r+   r+   r+   r,   r5   M   s    r5   zval, expected)r2   z_sample_func(y=1)Zworldg       @)CzLogisticRegression(C=2.0)z	newton-cgZbalancedT)Zrandom_stateZsolverZclass_weightZ
warm_startz]LogisticRegression(class_weight='balanced',random_state=1,solver='newton-cg',warm_start=True)zCallableEstimator()c                 C   s   t | |ksJ d S r0   )r   )valexpectedr+   r+   r,   test_get_check_estimator_idsW   s   r?   )Zexpected_failed_checksc                 C   s@   t ttttfd ||  W d    d S 1 sw   Y  d S Ncategory)r   FutureWarningr   UserWarningr   )	estimatorcheckrequestr+   r+   r,   test_estimatorsq   s
   

"rH   c                  C   sL   t jtdd tt dd} W d   n1 sw   Y  t| s$J dS )zTCheck that check_estimator with generate_only=True raises a deprecation
    warning.z$`generate_only` is deprecated in 1.6matchT)Zgenerate_onlyN)pytestZwarnsrC   r   r   r   )Zall_instance_gen_checksr+   r+   r,   .test_check_estimator_generate_only_deprecation}   s   rL   zZignore:Since version 1.0, it is not needed to import enable_hist_gradient_boosting anymorezGignore:Importing from sklearn.utils._estimator_html_repr is deprecated.c                  C   s   t jtjg} tj| ddd d}dd |D }|dg D ],}d|v s(d	|v r)qd
|v r.qt|dd}t|ddD ]}t	||sIJ d
||q:qd S )Nsklearn.c                 S   r/   r0   r+   _r+   r+   r,   <lambda>       z-test_import_all_consistency.<locals>.<lambda>)pathprefixonerrorc                 S   s   g | ]\}}}|qS r+   r+   ).0rO   modnamer+   r+   r,   
<listcomp>   s    z/test_import_all_consistency.<locals>.<listcomp>sklearnz.tests.zsklearn.externalszsklearn._build_utilsdummy)fromlist__all__r+   z#Module '{0}' has no attribute '{1}')osrR   dirnamerX   __file__pkgutilwalk_packages
__import__getattrhasattrr&   )sklearn_pathZpkgsZsubmodsrV   packager)   r+   r+   r,   test_import_all_consistency   s"   	
rf   c                  C   s`   t jtjg} d}tj| dd dD ]\}}}d|v s%|ds%||v r&q|tjv s-J qd S )N)utilstestsr%   Zconftestc                 S   r/   r0   r+   rN   r+   r+   r,   rP      rQ   z3test_root_import_all_completeness.<locals>.<lambda>)rR   rT   .rO   )	r\   rR   r]   rX   r^   r_   r`   r(   r[   )rd   Z
EXCEPTIONSrO   rV   r+   r+   r,   !test_root_import_all_completeness   s   rj   c                     sn   t d h dtjtjg} dd tj| ddD  fdd	 D }|g ks5J d	
|d S )
Nz(?x)
                                      \.externals(\.|$)|
                                      \.tests(\.|$)|
                                      \._
                                      >   zsklearn.datasets.descrzsklearn.datasets.datazsklearn.datasets.imagesc                 S   s   i | ]\}}}||qS r+   r+   )rU   rO   r)   ispkgr+   r+   r,   
<dictcomp>   s    z1test_all_tests_are_importable.<locals>.<dictcomp>rM   )rS   c                    s6   g | ]\}}|r|vr  |s|d  vr|qS )z.tests)search)rU   r)   rk   ZHAS_TESTS_EXCEPTIONSlookupZresource_modulesr+   r,   rW      s    z1test_all_tests_are_importable.<locals>.<listcomp>zn{0} do not have `tests` subpackages. Perhaps they require __init__.py or a meson.build in the parent directory)recompiler\   rR   r]   rX   r^   r_   r`   itemsr&   )rd   Zmissing_testsr+   rn   r,   test_all_tests_are_importable   s   
rs   c                  C   sx   d} t jt| d tt W d    n1 sw   Y  t jt| d ttg W d    d S 1 s5w   Y  d S )Nz8Passing a class was deprecated.* isn't supported anymorerI   )rK   Zraises	TypeErrorr   r   r$   r*   r+   r+   r,   test_class_support_removed   s   
"rv   c                  c   s    t  D ]C} t|  }d|v r| jdddV  qd|v r<| jddd}|jjdv r8tj|tjj	dd	d
V  q|V  qd|v rG| jddV  qd S )N	oob_scoreT)rw   Z	bootstrapearly_stoppingr.   )rx   n_iter_no_change>   ZMLPClassifierZMLPRegressorzMLP still validates in fitru   )Zmarksry   )ry   )
r   set
get_params
set_params	__class__r8   rK   parammarkZxfail)rE   Z
est_paramsestr+   r+   r,   _estimators_that_predict_in_fit   s    

r   rE   )Zidsc              	   C   s   t | tr
td dt| v rtd ttd4 tjdd}t	| j
j|  W d    n1 s3w   Y  |D ]}dt|jvsEJ q:W d    d S 1 sQw   Y  d S )Nz$ColumnTransformer is not tested herer   zCEstimator does not support check_dataframe_column_names_consistencyrA   T)recordz was fitted without feature names)
isinstancer   rK   skipr   r   rC   warningscatch_warningsr   r}   r8   strmessage)rE   r   warningr+   r+   r,   #test_pandas_column_name_consistency   s$   

"r   ZensembleZkernel_approximationc                 C   s&   t | drdS | jdd }|tvS )Nget_feature_names_outTri   r.   )rc   r9   split"GET_FEATURES_OUT_MODULES_TO_IGNORE)transformermoduler+   r+   r,   '_include_in_get_feature_names_out_check  s   
r   c                 C   s   g | ]}t |r|qS r+   )r   rU   r   r+   r+   r,   rW   #  s    rW   r   c                 C   sL   t td t| jj|  t| jj|  W d    d S 1 sw   Y  d S r@   )r   rC   r"   r}   r8   r#   )r   r+   r+   r,   'test_transformers_get_feature_names_out*  s   "r   c                 C   s   g | ]	}t |d r|qS )r   )rc   r   r+   r+   r,   rW   7  s
    
c                 C   s   | j j}t||  d S r0   )r}   r8   r   )rE   Zestimator_namer+   r+   r,   +test_estimators_get_feature_names_out_error<  s   r   c                 C   s*   t | tr
td | jj}t||  d S )NzFeatureUnion is not tested here)r   r   rK   r   r}   r8   r   rE   r)   r+   r+   r,   test_check_param_validationD  s   

r   F)Zsparse_outputz
one-to-one)Zfeature_names_outc                 C   sb   | j j}t| dstd| d ttd t| j j|  W d    d S 1 s*w   Y  d S )N
set_outputz(Skipping check_set_output_transform for z!: Does not support set_output APIrA   )r}   r8   rc   rK   r   r   rC   r   r   r+   r+   r,   test_set_output_transformZ  s   

"r   
check_funcc                 C   sj   | j j}t| dstd|j d| d ttd || j j|  W d    d S 1 s.w   Y  d S )Nr   z	Skipping z for z%: Does not support set_output API yetrA   )r}   r8   rc   rK   r   r   rC   )rE   r   r)   r+   r+   r,   $test_set_output_transform_configuredh  s   
"r   c                 C   s   | j j}t| dr| jdd nt| dr| jdd nt| d|dkr.| jdd	d
 |dkr8| jdd |dkrB| jdd t||  d S )NcopyF)r   copy_X)r   z! doesn't require writeable input.ZHDBSCANZprecomputedZbrute)Zmetric	algorithmZPCAfull)Z
svd_solverZ	KernelPCA)Zkernel)r}   r8   rc   r|   r   r   r   r+   r+   r,   #test_check_inplace_ensure_writeable  s   

r   )r.   )Ur;   r\   r_   rp   r   	functoolsr   inspectr   	itertoolsr   rK   Zscipy.linalgr   rX   Zsklearn.baser   Zsklearn.composer   Zsklearn.exceptionsr   Zsklearn.experimentalr	   r
   Zsklearn.linear_modelr   Zsklearn.pipeliner   r   Zsklearn.preprocessingr   r   r   r   Zsklearn.utilsr   Z-sklearn.utils._test_common.instance_generatorr   r   r   Zsklearn.utils._testingr   r   Zsklearn.utils.estimator_checksr   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r-   r3   r5   r   Zparametrizer?   listrH   rL   filterwarningsrf   rj   rs   rv   r   Zcolumn_name_estimatorsr   r   r   ZGET_FEATURES_OUT_ESTIMATORSr   Z%ESTIMATORS_WITH_GET_FEATURE_NAMES_OUTr   r   ZSET_OUTPUT_ESTIMATORSr   r   r   r+   r+   r+   r,   <module>   s    <
	



	
&	





	