
    lri-3                     N   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	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%m&Z& ddl'm(Z(m)Z) ddl*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7 e	j8        j9        d             Z:dBdZ; G d de          Z<e	j8        =                    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$             Z> e7 e? e%                      e$%          d&             Z@e	j8        A                    d'          e	j8        j9        d(                         ZBd) ZCe	j8        j9        d*             ZDd+ ZEd, ZF e? e e%             e ed                    g eF                                ZGe	j8        =                    d-eGe#.          d/             ZHd0d1gZId2 ZJd3  e%d4          D             ZKe	j8        =                    d4eKe#.          d5             ZLd6  e%            D             ZMe	j8        =                    d7eMe#.          d8             ZNe	j8        =                    d7 e? e%                      e#.          d9             ZO e? e e%d4           e e             e                       ed:;           ed<=          g                    ZPe	j8        =                    d-ePe#.          d>             ZQe	j8        =                    d-ePe#.          e	j8        =                    d?e3e.e4e/g          d@                         ZRe	j8        =                    d7 e%            e#.          dA             ZSdS )Cz.
General tests for all estimators in sklearn.
    N)partial)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_yield_instances_for_check)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                      t                      D ]K\  } }d                    |           }|                                                     d          r
J |            Ld S )NzDBase estimators such as {0} should not be included in all_estimatorsbase)r   formatlower
startswith)name	Estimatormsgs      y/var/www/html/bestrading.cuttalo.com/services/ml-inference/venv/lib/python3.11/site-packages/sklearn/tests/test_common.py test_all_estimator_no_base_classr/   @   si     *++ 8 8iR
&,, 	 ::<<**62277C7777	8 8       c                     d S N )xys     r.   _sample_funcr7   J   s    Dr0   c                       e Zd ZdZd ZdS )CallableEstimatorzqDummy development stub for an estimator.

    This is to make sure a callable estimator passes common tests.
    c                     d S r3   r4   )selfs    r.   __call__zCallableEstimator.__call__T   s    r0   N)__name__
__module____qualname____doc__r<   r4   r0   r.   r9   r9   N   s-         
    r0   r9   zval, expected)r6   z_sample_func(y=1)r7   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                 0    t          |           |k    sJ d S r3   )r   )valexpecteds     r.   test_get_check_estimator_idsrK   X   s#    . $C((H444444r0   )expected_failed_checksc                     t          t          t          t          t          f          5   ||            d d d            d S # 1 swxY w Y   d S Ncategory)r   FutureWarningr   UserWarningr   )	estimatorcheckrequests      r.   test_estimatorsrV   r   s    
 
!3[-P
 
 
   	i                 s   AA	AzZignore:Since version 1.0, it is not needed to import enable_hist_gradient_boosting anymorec                  v   t           j                            t          j                  g} t          j        | dd           }d |D             }|dgz   D ]c}d|v sd|v rd|v rt          |d	
          }t          |dd          D ]0}t          ||          sJ d
                    ||                      1dd S )Nsklearn.c                     d S r3   r4   _s    r.   <lambda>z-test_import_all_consistency.<locals>.<lambda>   s     r0   )pathprefixonerrorc                     g | ]\  }}}|	S r4   r4   ).0r[   modnames      r.   
<listcomp>z/test_import_all_consistency.<locals>.<listcomp>   s    111=1gqw111r0   sklearnz.tests.zsklearn.externalszsklearn._build_utilsdummy)fromlist__all__r4   z#Module '{0}' has no attribute '{1}')osr]   dirnamerd   __file__pkgutilwalk_packages
__import__getattrhasattrr(   )sklearn_pathpkgssubmodsrb   packager+   s         r.   test_import_all_consistencyrt   }   s    GOOG$4556L  *nn  D 21D111Gi[( 
 
#6'#A#A!W,,Ww777GY33 	 	D7D))  +P+W+W, ,    	
 
r0   c                      t           j                            t          j                  g} d}t          j        | d           D ]4\  }}}d|v s|                    d          s||v r$|t          j        v sJ 5d S )N)utilstestsr'   conftestc                     d S r3   r4   rZ   s    r.   r\   z3test_root_import_all_completeness.<locals>.<lambda>   s    T r0   )r]   r_   .r[   )	rh   r]   ri   rd   rj   rk   rl   r*   rg   )rp   
EXCEPTIONSr[   rb   s       r.   !test_root_import_all_completenessr|      s    GOOG$4556L7J .>>   * *7A '>>W//44>:8M8M'/)))))* *r0   c                  Z   t          j        d          h dt          j                            t
          j                  g} d t          j        | d          D             fd	                                D             }|g k    sJ d
                    |                      d S )NzK(?x)
        \.externals(\.|$)|
        \.tests(\.|$)|
        \._
        >   sklearn.datasets.datasklearn.datasets.descrsklearn.datasets.imagesc                     i | ]	\  }}}||
S r4   r4   )ra   r[   r+   ispkgs       r.   
<dictcomp>z1test_all_tests_are_importable.<locals>.<dictcomp>   s0       AtU 	e  r0   rX   )r^   c                 ^    g | ])\  }}|r"|vr                     |          s	|d z   v'|*S )z.tests)search)ra   r+   r   HAS_TESTS_EXCEPTIONSlookupresource_moduless      r.   rc   z1test_all_tests_are_importable.<locals>.<listcomp>   sd       D% ((($++D11 )8O6)) 	
 *))r0   zn{0} do not have `tests` subpackages. Perhaps they require __init__.py or a meson.build in the parent directory)recompilerh   r]   ri   rd   rj   rk   rl   itemsr(   )rp   missing_testsr   r   r   s     @@@r.   test_all_tests_are_importabler      s    
 :	   
 GOOG$4556L %3LTTT  F     !<<>>  M B	 F=)) r0   c                  *   d} t          j        t          |           5  t          t                     d d d            n# 1 swxY w Y   t          j        t          |           5  t          t          g           d d d            d S # 1 swxY w Y   d S )Nz8Passing a class was deprecated.* isn't supported anymore)match)pytestraises	TypeErrorr   r   r%   r-   s    r.   test_class_support_removedr      s    EC	y	,	,	, , ,*+++, , , , , , , , , , , , , , , 
y	,	,	, 6 6!3 45556 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6s!   ?AA%BBBc               #     K   t                      D ]} t          |                                           }d|v r|                     dd          V  Ad|v ra|                     dd          }|j        j        dv r7t          j        |t          j        	                    d	          
          V  |V  d|v r|                     d          V  d S )N	oob_scoreT)r   	bootstrapearly_stoppingr1   )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)rS   
est_paramsests      r.   _estimators_that_predict_in_fitr      s     ')) ; ;	--//00
*$$&&&FFFFFF++&&dQ&OOC}%)JJJlv{005Q0RR       				:--&&&:::::; ;r0   estimator_orig)idsc                    t          | t                    rt          j        d           dt	          |           v rt          j        d           t          t          |           D ]}t          t                    5  t          j
        d          5 }t          |j        j        |           d d d            n# 1 swxY w Y   |D ]}dt          |j                  vsJ 	 d d d            n# 1 swxY w Y   d S )Nz$ColumnTransformer is not tested herer   zCEstimator does not support check_dataframe_column_names_consistencyrO   T)recordz was fitted without feature names)
isinstancer   r   skipr   r   r   r   rQ   warningscatch_warningsr   r=   strmessage)r   rS   r   warnings       r.   #test_pandas_column_name_consistencyr      s    ."344 <:;;;15P6 6   	Q	
 	
 	
 00.  	V 	V	 }666 	V 	V(555 8'0)                 " V V9W_AUAUUUUUUV	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V	V 	Vs6   ;C-B8,C-8B<<C-?B<  C--C1	4C1	ensemblekernel_approximationc                 x    t          | d          rdS | j                            d          d         }|t          vS )Nget_feature_names_outTrz   r1   )ro   r>   split"GET_FEATURES_OUT_MODULES_TO_IGNORE)transformermodules     r.   '_include_in_get_feature_names_out_checkr     sA    {344 t#))#..q1F;;;r0   c                 0    g | ]}t          |          |S r4   )r   ra   r   s     r.   rc   rc     s6       .s33  r0   r   c                     t          t                    5  t          | j        j        |            t          | j        j        |            d d d            d S # 1 swxY w Y   d S rN   )r   rQ   r#   r   r=   r$   )r   s    r.   'test_transformers_get_feature_names_outr   !  s     
=	2	2	2 
 
/!*K	
 	
 	
 	7!*K	
 	
 	
	
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s   5AAAc                 2    g | ]}t          |d           |S )r   )ro   r   s     r.   rc   rc   .  s8     ) ) )738O+P+P)) ) )r0   rS   c                 >    | j         j        }t          ||            d S r3   )r   r=   r   )rS   estimator_names     r.   +test_estimators_get_feature_names_out_errorr   3  s%     (1N%ni@@@@@r0   c                     t          | t                    rt          j        d           | j        j        }t          ||            d S )NzFeatureUnion is not tested here)r   r   r   r   r   r=   r   rS   r+   s     r.   test_check_param_validationr   ;  sH     )\** 75666'D4+++++r0   F)sparse_outputz
one-to-one)feature_names_outc                 ,   | j         j        }t          | d          st          j        d| d           t          t          |           D ]I}t          t                    5  t          |j         j        |           d d d            n# 1 swxY w Y   Jd S )N
set_outputz(Skipping check_set_output_transform for z!: Does not support set_output APIrO   )	r   r=   ro   r   r   r   r    r   rQ   )r   r+   rS   s      r.   test_set_output_transformr   Q  s	    #,D><00 
t   	
 	
 	
 0"N  P P	 }666 	P 	P&y':'CYOOO	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	PP Ps   !BB	B	
check_funcc                 *   | j         j        }t          | d          s t          j        d|j         d| d           t          ||           D ]E}t          t                    5   ||j         j        |           d d d            n# 1 swxY w Y   Fd S )Nr   z	Skipping z for z%: Does not support set_output API yetrO   )r   r=   ro   r   r   r   r   rQ   )r   r   r+   rS   s       r.   $test_set_output_transform_configuredr   b  s    #,D><00 
"
+ " "$ " " "	
 	
 	
 0
NKK @ @	}666 	@ 	@Jy*3Y???	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@@ @s   $BB	B	c                    | j         j        }t          | d          r|                     d           n9t          | d          r|                     d           nt	          | d          |dk    r|                     dd	
           |dk    r|                     d           |dk    r|                     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   r=   ro   r   r   r   r   s     r.   #test_check_inplace_ensure_writeabler   z  s     'Dy&!! C%((((	H	%	% CE****$AAABBB yMWEEEu}}///{M222"433333r0   )r1   )Tr@   rh   rk   r   r   	functoolsr   	itertoolsr   r   scipy.linalgr   rd   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   r   sklearn.utils._testingr   r   sklearn.utils.estimator_checksr   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r   thread_unsafer/   r7   r9   parametrizerK   listrV   filterwarningsrt   r|   r   r   r   column_name_estimatorsr   r   r   GET_FEATURES_OUT_ESTIMATORSr   %ESTIMATORS_WITH_GET_FEATURE_NAMES_OUTr   r   SET_OUTPUT_ESTIMATORSr   r   r   r4   r0   r.   <module>r      s    
			  				               & & & & & &  & & & & & & - - - - - - 1 1 1 1 1 1        4 3 3 3 3 3 8 8 8 8 8 8 8 8            ) ( ( ( ( (                                               " 8 8 8	 	 	 	        		#	#	#%89	~&	w	'	'8		c	"	"	"$?@"'	  6	
 
			34# ,5 5- ,5 D				7R     ,    	 
** * * # # #L	6 	6 	6; ; ;* 	E	))A...	/	/0''))    ,2J   V V V0 & "< < < !!-00    .4L   
 
 
) )%%'') ) ) %
 6<T   A A A
 ((**++1I   , , , 	E=))M..**LLNN;;M...,???	
 	 	  +1I   P P P +1I    ),)0	 	@ 	@  	@ ##%%+C   4 4 4 4 4r0   