
    >[g>8                        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 Z=dGdZ> G d de      Z?ej                  j                  d ee>d      dfe>df ee>d      df ed      d f edd!d"d#$      d%f e?       d&fg      d'        ZB e: eC e)             e((      d)        ZDd* ZEej                  j                  e<d+,      ej                  j                  d-      d.               ZHd/ ZId0 ZJd1 ZKd2 ZL eC e
 e)        e ed            g eL                   ZMej                  j                  d3eMe'4      d5        ZNd6d7gZOd8 ZP e)d9      D  cg c]  }  eP|       r|  c} ZQej                  j                  d9eQe'4      d:        ZR e)       D  cg c]  }  eS| d;      s|  c} ZTej                  j                  d3eTe'4      d<        ZUej                  j                  d3 eC e)             e'4      d=        ZV eC e
 e)d9       e e#        e!              e"d>?       e d@A      g            ZWej                  j                  d3eWe'4      dB        ZXej                  j                  d3eWe'4      ej                  j                  dCe6e1e7e2g      dD               ZYej                  j                  d3 e)       e'4      dE        ZZdF Z[yc c} w c c} w )Hz.
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                      t               D ]<  \  } }dj                  |       }| j                         j                  d      s7J |        y )NzDBase estimators such as {0} should not be included in all_estimatorsbase)r   formatlower
startswith)name	Estimatormsgs      T/var/www/html/bid-api/venv/lib/python3.12/site-packages/sklearn/tests/test_common.py test_all_estimator_no_base_classr1   B   sE    )+iR
&, 	 ::<**627C72	 ,       c                      y N )xys     r0   _sample_funcr9   K   s    r2   c                       e Zd ZdZd Zy)CallableEstimatorzqDummy development stub for an estimator.

    This is to make sure a callable estimator passes common tests.
    c                      y r5   r6   )selfs    r0   __call__zCallableEstimator.__call__U   s    r2   N)__name__
__module____qualname____doc__r>   r6   r2   r0   r;   r;   O   s    
r2   r;   zval, expected)r8   z_sample_func(y=1)r9   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                 $    t        |       |k(  sJ y r5   )r   )valexpecteds     r0   test_get_check_estimator_idsrM   Y   s    . $C(H444r2   )expected_failed_checksc                 ~    t        t        t        t        t        f      5   ||        d d d        y # 1 sw Y   y xY wNcategory)r   FutureWarningr
   UserWarningr   )	estimatorcheckrequests      r0   test_estimatorsrX   s   s3    
 
!3[-P
 	i
 
 
s   	3<c                      t        j                  t        d      5  t        t	               d      } ddd       t               sJ y# 1 sw Y   xY w)zTCheck that check_estimator with generate_only=True raises a deprecation
    warning.z$`generate_only` is deprecated in 1.6matchT)generate_onlyN)pytestwarnsrS   r   r   r   )all_instance_gen_checkss    r0   .test_check_estimator_generate_only_deprecationr`      sG     
m+Q	R"1 #
 
S .///	 
S	Rs   AAz,importlib not supported for Pyodide packages)reasonzZignore:Since version 1.0, it is not needed to import enable_hist_gradient_boosting anymorec                  v   t         j                  j                  t        j                        g} t        j                  | dd       }|D cg c]  \  }}}|
 }}}|dgz   D ]N  }d|v rd|v rt        |d      }t        |d	d
      D ]%  }t        ||      rJ dj                  ||              P y c c}}w )Nsklearn.c                      y r5   r6   _s    r0   <lambda>z-test_import_all_consistency.<locals>.<lambda>   s    r2   )pathprefixonerrorsklearnz.tests.zsklearn._build_utilsdummy)fromlist__all__r6   z#Module '{0}' has no attribute '{1}')osrh   dirnamerk   __file__pkgutilwalk_packages
__import__getattrhasattrr*   )sklearn_pathpkgsrf   modnamesubmodspackager-   s          r0   test_import_all_consistencyr|      s     GGOOG$4$456L   *nD -11D=1gqwDG1i[(!W,Ww7GY3D7D) +P+W+W, ) 4 ) 2s   B5c                     t         j                  j                  t        j                        g} d}t        j                  | d       D ]4  \  }}}d|v s|j                  d      s||v r!|t        j                  v r4J  y )N)utilstestsr)   conftestc                      y r5   r6   re   s    r0   rg   z3test_root_import_all_completeness.<locals>.<lambda>   s    Tr2   )rh   rj   .rf   )	ro   rh   rp   rk   rq   rr   rs   r,   rn   )rw   
EXCEPTIONSrf   ry   s       r0   !test_root_import_all_completenessr      st    GGOOG$4$456L7J ..>7A '>W//4:8M'//)))r2   c                     t        j                  d      } h d}t        j                  j	                  t
        j                        g}t        j                  |d      D ci c]	  \  }}}|| }}}}|j                         D cg c]%  \  }}|r||vr| j                  |      s	|dz   |vr|' }}}|g k(  sJ dj                  |             y c c}}}w c c}}w )Nz(?x)
                                      \.externals(\.|$)|
                                      \.tests(\.|$)|
                                      \._
                                      >   sklearn.datasets.datasklearn.datasets.descrsklearn.datasets.imagesrc   )ri   z.testszn{0} do not have `tests` subpackages. Perhaps they require __init__.py or a meson.build in the parent directory)recompilero   rh   rp   rk   rq   rr   rs   itemssearchr*   )HAS_TESTS_EXCEPTIONSresource_modulesrw   rf   r-   ispkglookupmissing_testss           r0   test_all_tests_are_importabler      s     ::	*
 GGOOG$4$456L &33LTTNAtU 	eT   "<<>)KD%(($++D18O6) 	)   B 	 F=)s   #C*Cc                     d} t        j                  t        |       5  t        t               d d d        t        j                  t        |       5  t        t        g       d d d        y # 1 sw Y   >xY w# 1 sw Y   y xY w)Nz8Passing a class was deprecated.* isn't supported anymorerZ   )r]   raises	TypeErrorr   r   r&   r/   s    r0   test_class_support_removedr      s\     EC	y	,*+ 
- 
y	,!3 45 
-	, 
-	, 
-	,s   A+A7+A47B c               #     K   t               D ]  } t        | j                               }d|v r| j                  dd       6d|v rh| j                  dd      }|j                  j
                  dv r8t        j                  |t        j                  j                  d	      
       | d|v s| j                  d        y w)N	oob_scoreT)r   	bootstrapearly_stoppingr3   )r   n_iter_no_change>   MLPRegressorMLPClassifierzMLP still validates in fitr   )marksr   )r   )
r   set
get_params
set_params	__class__r?   r]   parammarkxfail)rU   
est_paramsests      r0   _estimators_that_predict_in_fitr      s     ')	--/0
*$&&&FF+&&dQ&OC}}%%)JJllv{{005Q0R  	:-&&&:: *s   B1C4CrU   )idsc                    t        | t              rt        j                  d       dt	        |       v rt        j                  d       t        t              5  t        j                  d      5 }t        | j                  j                  |        d d d        D ]  }dt        |j                        vrJ  	 d d d        y # 1 sw Y   3xY w# 1 sw Y   y xY w)Nz$ColumnTransformer is not tested herer   zCEstimator does not support check_dataframe_column_names_consistencyrQ   T)recordz was fitted without feature names)
isinstancer   r]   skipr   r   rS   warningscatch_warningsr   r   r?   strmessage)rU   r   warnings      r0   #test_pandas_column_name_consistencyr      s     )./:;15P6  	Q	
 
=	2$$D1V4##,,i 2 G5S=QQQQ  
3	211 
3	2s*   C/!C$C5CC	CCensemblekernel_approximationc                 h    t        | d      ry| j                  j                  d      d   }|t        vS )Nget_feature_names_outTr   r3   )rv   r@   split"GET_FEATURES_OUT_MODULES_TO_IGNORE)transformermodules     r0   '_include_in_get_feature_names_out_checkr     s7    {34##))#.q1F;;;r2   r   c                     t        t              5  t        | j                  j                  |        t        | j                  j                  |        d d d        y # 1 sw Y   y xY wrP   )r   rS   r$   r   r?   r%   )r   s    r0   'test_transformers_get_feature_names_outr   )  sL    
 
=	2/!!**K	
 	7!!**K	
	 
3	2	2s   AAA$r   c                 H    | j                   j                  }t        ||        y r5   )r   r?   r   )rU   estimator_names     r0   +test_estimators_get_feature_names_out_errorr   <  s     ((11N%ni@r2   c                     t        | t              rt        j                  d       | j                  j
                  }t        ||        y )NzFeatureUnion is not tested here)r   r   r]   r   r   r?   r    rU   r-   s     r0   test_check_param_validationr   D  s6     )\*56''D4+r2   F)sparse_outputz
one-to-one)feature_names_outc                    | j                   j                  }t        | d      st        j                  d| d       t        t              5  t        | j                   j                  |        d d d        y # 1 sw Y   y xY w)N
set_outputz(Skipping check_set_output_transform for z!: Does not support set_output APIrQ   )r   r?   rv   r]   r   r   rS   r!   r   s     r0   test_set_output_transformr   Z  sh     ''D9l+6tf = 	
 
=	2"9#6#6#?#?K 
3	2	2s   !A66A?
check_funcc                    | j                   j                  }t        | d      s&t        j                  d|j                   d| d       t        t              5   || j                   j                  |        d d d        y # 1 sw Y   y xY w)Nr   z	Skipping z for z%: Does not support set_output API yetrQ   )r   r?   rv   r]   r   r   rS   )rU   r   r-   s      r0   $test_set_output_transform_configuredr   h  su     ''D9l+
++,E$ 8" "	
 
=	29&&//; 
3	2	2s   B  B	c                 l   | j                   j                  }t        | d      r| j                  d       n-t        | d      r| j                  d       nt	        | d      |dk(  r| j                  dd	
       |dk(  r| j                  d       |dk(  r| j                  d       t        ||        y )NcopyF)r   copy_X)r   z! doesn't require writeable input.HDBSCANprecomputedbrute)metric	algorithmPCAfull)
svd_solver	KernelPCA)kernel)r   r?   rv   r   r   r   r   s     r0   #test_check_inplace_ensure_writeabler     s     ''Dy&!%(	H	%E*$@ABB yMWEu}/{M2"43r2   c                      G d dt               } t        ddd      \  }} |        }t        j                  t              5 }|j                  |       ddd       t              dk(  sJ t        |d   j                        j                  d	      sJ t        |d
   j                        j                  d      sJ t        |d   j                        j                  d      sJ y# 1 sw Y   xY w)zThis test checks that we raised deprecation warning explaining how to transition
    to the new developer public API from 1.5 to 1.6.
    c                       e Zd ZddZd Zy)=test_transition_public_api_deprecations.<locals>.OldEstimatorNc                 t    | j                  |      }| j                  |d       | j                  |d       | S )NT)reset)_validate_data_check_n_features_check_feature_names)r=   Xr8   s      r0   fitzAtest_transition_public_api_deprecations.<locals>.OldEstimator.fit  s=    ##A&A""1D"1%%at%4Kr2   c                     |S r5   r6   )r=   r   s     r0   	transformzGtest_transition_public_api_deprecations.<locals>.OldEstimator.transform  s    Hr2   r5   )r?   r@   rA   r   r   r6   r2   r0   OldEstimatorr     s    		r2   r   
      r   )	n_samples
n_featuresrF   N   z,`BaseEstimator._validate_data` is deprecatedr3   z/`BaseEstimator._check_n_features` is deprecated   z2`BaseEstimator._check_feature_names` is deprecated)
r   r	   r]   r^   rS   r   lenr   r   r,   )r   r   r8   old_estimatorwarning_lists        r0   'test_transition_public_api_deprecationsr     s    
}  JDAq NM	m	$! 
% |!!!|A&&'226   |A&&'229   |A&&'22<   
%	$s   C''C0)r3   )\rB   ro   rr   r   r   	functoolsr   inspectr   	itertoolsr   r]   scipy.linalgr   rk   sklearn.baser   sklearn.composer   sklearn.datasetsr	   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&   sklearn.utils.fixesr'   r1   r9   r;   r   parametrizerM   listrX   r`   r   filterwarningsr|   r   r   r   r   column_name_estimatorsr   r   r   GET_FEATURES_OUT_ESTIMATORSr   rv   %ESTIMATORS_WITH_GET_FEATURE_NAMES_OUTr   r   SET_OUTPUT_ESTIMATORSr   r   r   r   )r   s   0r0   <module>r     s(   
  	      &  & - 0 1 4 8  ) 
    )8	  		#%89	~&	w	'8	c	"$?@"'	6	
 
	34#,5-,5 		7R0 8$RS,	 T
**#L	6;* 		)A.	/0')  '-E  RR* & "< "-00.s3 0  .4L  

 &')'C738O+PC') %
 6<T  AA
 (*+1I  ,, 	=).*LN;.,?	
	  &,D  LL &,D   ),)0	<< #%+C  440q*)s   MM,M