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)name	Estimatormsg r,   z/var/www/www-root/data/www/176.119.141.140/sports-predictor/venv/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      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   r0   r1   r,   )selfr,   r,   r-   __call__S   r5   zCallableEstimator.__call__N)__name__
__module____qualname____doc__r8   r,   r,   r,   r-   r6   M   s    r6   zval, expected)r3   z_sample_func(y=1)worldg       @)CzLogisticRegression(C=2.0)z	newton-cgbalancedT)random_statesolverclass_weight
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_idsW   s   rF   )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
   

"rP   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)generate_onlyN)pytestwarnsrK   r   r   r   )all_instance_gen_checksr,   r,   r-   .test_check_estimator_generate_only_deprecation}   s   rW   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   r0   r1   r,   _r,   r,   r-   <lambda>       z-test_import_all_consistency.<locals>.<lambda>)pathprefixonerrorc                 S   s   g | ]\}}}|qS r,   r,   ).0rZ   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}')osr]   dirnamerc   __file__pkgutilwalk_packages
__import__getattrhasattrr&   )sklearn_pathpkgssubmodsra   packager)   r,   r,   r-   test_import_all_consistency   s"   	
rs   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%   conftestc                 S   r0   r1   r,   rY   r,   r,   r-   r[      r\   z3test_root_import_all_completeness.<locals>.<lambda>)r]   r_   .rZ   )	rg   r]   rh   rc   ri   rj   rk   r(   rf   )ro   
EXCEPTIONSrZ   ra   r,   r,   r-   !test_root_import_all_completeness   s   ry   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(\.|$)|
                                      \._
                                      >   sklearn.datasets.datasklearn.datasets.descrsklearn.datasets.imagesc                 S   s   i | ]\}}}||qS r,   r,   )r`   rZ   r)   ispkgr,   r,   r-   
<dictcomp>   s    z1test_all_tests_are_importable.<locals>.<dictcomp>rX   )r^   c                    s6   g | ]\}}|r|vr  |s|d  vr|qS )z.tests)search)r`   r)   r}   HAS_TESTS_EXCEPTIONSlookupresource_modulesr,   r-   rb      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compilerg   r]   rh   rc   ri   rj   rk   itemsr&   )ro   missing_testsr,   r   r-   test_all_tests_are_importable   s   
r   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 anymorerQ   )rT   raises	TypeErrorr   r   r$   r+   r,   r,   r-   test_class_support_removed   s   
"r   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)r   	bootstrapearly_stoppingr/   )r   n_iter_no_change>   MLPRegressorMLPClassifierzMLP still validates in fitr   )marksr   )r   )
r   set
get_params
set_params	__class__r9   rT   parammarkxfail)rM   
est_paramsestr,   r,   r-   _estimators_that_predict_in_fit   s    

r   rM   )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_consistencyrI   T)recordz was fitted without feature names)
isinstancer   rT   skipr   r   rK   warningscatch_warningsr   r   r9   strmessage)rM   r   warningr,   r,   r-   #test_pandas_column_name_consistency   s$   

"r   ensemblekernel_approximationc                 C   s&   t | drdS | jdd }|tvS )Nget_feature_names_outTrw   r/   )rn   r:   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   r`   r   r,   r,   r-   rb   #  s    rb   r   c                 C   sL   t td t| jj|  t| jj|  W d    d S 1 sw   Y  d S rH   )r   rK   r"   r   r9   r#   )r   r,   r,   r-   'test_transformers_get_feature_names_out*  s   "r   c                 C   s   g | ]	}t |d r|qS )r   )rn   r   r,   r,   r-   rb   7  s
    
c                 C   s   | j j}t||  d S r1   )r   r9   r   )rM   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   rT   r   r   r9   r   rM   r)   r,   r,   r-   test_check_param_validationD  s   

r   F)sparse_outputz
one-to-one)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 APIrI   )r   r9   rn   rT   r   r   rK   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 yetrI   )r   r9   rn   rT   r   r   rK   )rM   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.HDBSCANprecomputedbrute)metric	algorithmPCAfull)
svd_solver	KernelPCA)kernel)r   r9   rn   r   r   r   r   r,   r,   r-   #test_check_inplace_ensure_writeable  s   

r   )r/   )Ur<   rg   rj   r   r   	functoolsr   inspectr   	itertoolsr   rT   scipy.linalgr   rc   sklearn.baser   sklearn.composer   sklearn.exceptionsr   sklearn.experimentalr	   r
   sklearn.linear_modelr   sklearn.pipeliner   r   sklearn.preprocessingr   r   r   r   sklearn.utilsr   -sklearn.utils._test_common.instance_generatorr   r   r   sklearn.utils._testingr   r   sklearn.utils.estimator_checksr   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r.   r4   r6   r   parametrizerF   listrP   rW   filterwarningsrs   ry   r   r   r   column_name_estimatorsr   r   r   GET_FEATURES_OUT_ESTIMATORSr   %ESTIMATORS_WITH_GET_FEATURE_NAMES_OUTr   r   SET_OUTPUT_ESTIMATORSr   r   r   r,   r,   r,   r-   <module>   s    <
	



	
&	





	