a
    �ù»jö9  ã                   @   s”  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 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/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z: ddl;m<Z< dd„ Z=d[dd„Z>G dd„ deƒZ?ej@ Ad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)„ ƒZBe:eCe)ƒ ƒe(d*�d+d,„ ƒZDd-d.„ ZEej@jFe<d/d0�ej@ Gd1¡d2d3„ ƒƒZHd4d5„ ZId6d7„ ZJd8d9„ ZKd:d;„ ZLeCe
e)ƒ eedd �ƒgeLƒ ƒƒZMej@jAd<eMe'd=�d>d?„ ƒZNd@dAgZOdBdC„ ZPdDdE„ e)dFƒD ƒZQej@jAdFeQe'd=�dGdH„ ƒZRdIdE„ e)ƒ D ƒZSej@jAd<eSe'd=�dJdK„ ƒZTej@jAd<eCe)ƒ ƒe'd=�dLdM„ ƒZUeCe
e)dFƒee#ƒ e!ƒ ƒe"dNdO�e dPdQ�gƒƒZVej@jAd<eVe'd=�dRdS„ ƒZWej@jAd<eVe'd=�ej@ AdTe6e1e7e2g¡dUdV„ ƒƒZXej@jAd<e)ƒ e'd=�dWdX„ ƒZYdYdZ„ ZZdS )\z.
General tests for all estimators in sklearn.
é    N)Úpartial)Úisgenerator)Úchain)ÚLinAlgWarning)ÚBaseEstimator)ÚColumnTransformer)Úmake_classification)Ú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_checks)Ú_IS_WASMc                  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-   ú?E:\soccer\ml_env\Lib\site-packages\sklearn/tests/test_common.pyÚ test_all_estimator_no_base_classB   s    ÿþr/   é   c                 C   s   d S ©Nr-   )ÚxÚyr-   r-   r.   Ú_sample_funcK   s    r4   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   s   d S r1   r-   )Úselfr-   r-   r.   Ú__call__U   s    zCallableEstimator.__call__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r7   r-   r-   r-   r.   r5   O   s   r5   zval, expected)r3   z_sample_func(y=1)Zworldg       @)ÚCzLogisticRegression(C=2.0)z	newton-cgZbalancedT)Ú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 r1   )r   )ÚvalÚexpectedr-   r-   r.   Útest_get_check_estimator_idsY   s    r@   )Zexpected_failed_checksc                 C   s>   t ttttfd�� || ƒ W d   ƒ n1 s00    Y  d S ©N©Úcategory)r   ÚFutureWarningr	   ÚUserWarningr   )Ú	estimatorÚcheckÚrequestr-   r-   r.   Útest_estimatorss   s    
ÿrI   c                  C   sL   t jtdd�� ttƒ dd�} W d  ƒ n1 s20    Y  t| ƒsHJ ‚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)ÚpytestÚwarnsrD   r   r   r   )Zall_instance_gen_checksr-   r-   r.   Ú.test_check_estimator_generate_only_deprecation   s
    ÿ$rN   z,importlib not supported for Pyodide packages)ÚreasonzZignore:Since version 1.0, it is not needed to import enable_hist_gradient_boosting anymorec                  C   s’   t j tj¡g} tj| ddd„ d�}dd„ |D ƒ}|dg D ]P}d|v rJq<d	|v rTq<t|d
d�}t|ddƒD ]}t	||ƒslJ d 
||¡ƒ‚qlq<d S )Núsklearn.c                 S   s   d S r1   r-   ©Ú_r-   r-   r.   Ú<lambda>“   ó    z-test_import_all_consistency.<locals>.<lambda>)ÚpathÚprefixÚonerrorc                 S   s   g | ]\}}}|‘qS r-   r-   )Ú.0rR   Úmodnamer-   r-   r.   Ú
<listcomp>•   rT   z/test_import_all_consistency.<locals>.<listcomp>Úsklearnz.tests.zsklearn._build_utilsÚdummy)ÚfromlistÚ__all__r-   z#Module '{0}' has no attribute '{1}')ÚosrU   Údirnamer[   Ú__file__ÚpkgutilÚwalk_packagesÚ
__import__ÚgetattrÚhasattrr(   )Úsklearn_pathÚpkgsZsubmodsrY   Úpackager+   r-   r-   r.   Útest_import_all_consistency‰   s    
ÿÿrj   c                  C   s`   t j tj¡g} d}tj| dd„ d�D ]4\}}}d|v s&| d¡s&||v rLq&|tjv s&J ‚q&d S )N)ÚutilsZtestsr'   Zconftestc                 S   s   d S r1   r-   rQ   r-   r-   r.   rS   §   rT   z3test_root_import_all_completeness.<locals>.<lambda>)rU   rW   Ú.rR   )	r_   rU   r`   r[   ra   rb   rc   r*   r^   )rg   Z
EXCEPTIONSrR   rY   r-   r-   r.   Ú!test_root_import_all_completeness£   s    ÿrm   c                     sn   t  d¡‰ h d£‰tj tj¡g} dd„ tj| dd�D ƒ‰‡ ‡‡fdd„ˆ 	¡ D ƒ}|g ksjJ d	 
|¡ƒ‚d S )
NzÃ(?x)
                                      \.externals(\.|$)|
                                      \.tests(\.|$)|
                                      \._
                                      >   zsklearn.datasets.datazsklearn.datasets.imageszsklearn.datasets.descrc                 S   s   i | ]\}}}||“qS r-   r-   )rX   rR   r+   Úispkgr-   r-   r.   Ú
<dictcomp>¿   s   ÿz1test_all_tests_are_importable.<locals>.<dictcomp>rP   )rV   c                    s6   g | ].\}}|r|ˆvrˆ   |¡s|d  ˆvr|‘qS )z.tests)Úsearch)rX   r+   rn   ©ZHAS_TESTS_EXCEPTIONSÚlookupZresource_modulesr-   r.   rZ   Ã   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_   rU   r`   r[   ra   rb   rc   Úitemsr(   )rg   Zmissing_testsr-   rq   r.   Útest_all_tests_are_importable®   s     ÿþþ
üÿrv   c                  C   sv   d} t jt| d�� ttƒ W d   ƒ n1 s00    Y  t jt| d�� ttgƒ W d   ƒ n1 sh0    Y  d S )Nz8Passing a class was deprecated.* isn't supported anymorerJ   )rL   ZraisesÚ	TypeErrorr   r   r%   ©r,   r-   r-   r.   Útest_class_support_removedÔ   s
    &ry   c                  c   s’   t ƒ D ]†} t|  ¡ ƒ}d|v r0| jddd�V  qd|v rv| jddd�}|jjdv rntj|tjj	dd	�d
�V  qŒ|V  qd|v r| jdd�V  qd S )NÚ	oob_scoreT)rz   Z	bootstrapÚearly_stoppingr0   )r{   Ún_iter_no_change>   ZMLPClassifierZMLPRegressorzMLP still validates in fitrx   )Zmarksr|   )r|   )
r   ÚsetÚ
get_paramsÚ
set_paramsÚ	__class__r8   rL   ÚparamÚmarkÚxfail)rF   Z
est_paramsÚestr-   r-   r.   Ú_estimators_that_predict_in_fità   s    
ÿ
r…   rF   )Zidsc              	   C   s®   t | tƒrt d¡ dt| ƒv r*t d¡ ttd��f tjdd��}t	| j
j| ƒ W d   ƒ n1 sf0    Y  |D ]}dt|jƒvstJ ‚qtW d   ƒ n1 s 0    Y  d S )Nz$ColumnTransformer is not tested herer   zCEstimator does not support check_dataframe_column_names_consistencyrB   T)Úrecordz was fitted without feature names)Ú
isinstancer   rL   Úskipr   r   rD   ÚwarningsÚcatch_warningsr   r€   r8   ÚstrÚmessage)rF   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_outTrl   r0   )rf   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”   ©rX   r„   r-   r-   r.   rZ   "  s   þrZ   r’   c                 C   sJ   t td��, t| jj| ƒ t| jj| ƒ W d   ƒ n1 s<0    Y  d S rA   )r   rD   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�   )rf   r•   r-   r-   r.   rZ   7  s   c                 C   s   | j j}t|| ƒ d S r1   )r€   r8   r   )rF   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   rL   rˆ   r€   r8   r   ©rF   r+   r-   r-   r.   Útest_check_param_validationD  s    

r™   F)Zsparse_outputz
one-to-one)Zfeature_names_outc                 C   s`   | j j}t| dƒs$t d|› d�¡ ttd�� t| j j| ƒ W d   ƒ n1 sR0    Y  d S )NÚ
set_outputz(Skipping check_set_output_transform for z!: Does not support set_output APIrB   )r€   r8   rf   rL   rˆ   r   rD   r    r˜   r-   r-   r.   Útest_set_output_transformZ  s    

ÿr›   Ú
check_funcc                 C   sh   | j j}t| dƒs,t d|j› d|› d�¡ ttd�� || j j| ƒ W d   ƒ n1 sZ0    Y  d S )Nrš   z	Skipping z for z%: Does not support set_output API yetrB   )r€   r8   rf   rL   rˆ   r   rD   )rF   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ƒr8| jdd� nt|› d�ƒ‚|dkr\| jdd	d
� |dkrp| jdd� |dkr„| 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   rf   r   r   r   r˜   r-   r-   r.   Ú#test_check_inplace_ensure_writeable  s    

r¢   c                  C   s¸   G dd„ dt ƒ} tdddd�\}}| ƒ }t t¡�}| |¡ W d  ƒ n1 sR0    Y  t|ƒdkslJ ‚t|d jƒ 	d	¡s„J ‚t|d
 jƒ 	d¡sœJ ‚t|d jƒ 	d¡s´J ‚dS )zŠThis test checks that we raised deprecation warning explaining how to transition
    to the new developer public API from 1.5 to 1.6.
    c                   @   s   e Zd Zddd„Zdd„ ZdS )z=test_transition_public_api_deprecations.<locals>.OldEstimatorNc                 S   s*   |   |¡}| j|dd� | j|dd� | S )NT)Úreset)Z_validate_dataZ_check_n_featuresZ_check_feature_names)r6   ÚXr3   r-   r-   r.   Úfit   s    
zAtest_transition_public_api_deprecations.<locals>.OldEstimator.fitc                 S   s   |S r1   r-   )r6   r¤   r-   r-   r.   Ú	transform¦  s    zGtest_transition_public_api_deprecations.<locals>.OldEstimator.transform)N)r8   r9   r:   r¥   r¦   r-   r-   r-   r.   ÚOldEstimatorŸ  s   
r§   é
   é   r   )Z	n_samplesZ
n_featuresr=   Né   z,`BaseEstimator._validate_data` is deprecatedr0   z/`BaseEstimator._check_n_features` is deprecatedé   z2`BaseEstimator._check_feature_names` is deprecated)
r   r   rL   rM   rD   r¥   Úlenr‹   rŒ   r*   )r§   r¤   r3   Zold_estimatorZwarning_listr-   r-   r.   Ú'test_transition_public_api_deprecationsš  s    
(ÿÿÿr­   )r0   )[r;   r_   rb   rs   r‰   Ú	functoolsr   Úinspectr   Ú	itertoolsr   rL   Zscipy.linalgr   r[   Zsklearn.baser   Zsklearn.composer   Zsklearn.datasetsr   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%   Zsklearn.utils.fixesr&   r/   r4   r5   r‚   Zparametrizer@   ÚlistrI   rN   rƒ   Úfilterwarningsrj   rm   rv   ry   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-   r.   Ú<module>   sò   <	

üøïþ

ÿ
	
ÿ&ýÿ	ÿ
þþÿ
ÿÿ
ÿ
ýþÿÿ
ÿüþ	ÿ
