
    ה9i-3                        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	jp                  jr                  d        Z:dAdZ; G d de      Z<e	jp                  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$        Z> e7 e? e%             e$%      d&        Z@e	jp                  j                  d'      e	jp                  jr                  d(               ZBd) ZCe	jp                  jr                  d*        ZDd+ ZEd, ZF e? e e%        e ed            g eF                   ZGe	jp                  j{                  d-eGe#.      d/        ZHd0d1gZId2 ZJ e%d3      D  cg c]  }  eJ|       r|  c} ZKe	jp                  j{                  d3eKe#.      d4        ZL e%       D  cg c]  }  eM| d5      s|  c} ZNe	jp                  j{                  d6eNe#.      d7        ZOe	jp                  j{                  d6 e? e%             e#.      d8        ZP e? e e%d3       e e        e              ed9:       ed;<      g            ZQe	jp                  j{                  d-eQe#.      d=        ZRe	jp                  j{                  d-eQe#.      e	jp                  j{                  d>e3e.e4e/g      d?               ZSe	jp                  j{                  d6 e%       e#.      d@        ZTyc c} w c c} w )Bz.
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 ]<  \  } }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      c/var/www/html/backtest/airagagent/rag_env/lib/python3.12/site-packages/sklearn/tests/test_common.py test_all_estimator_no_base_classr/   @   sL     *+ 8iR
&, 	 ::<**627C72	8       c                      y N )xys     r.   _sample_funcr7   J   s    r0   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 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                 $    t        |       |k(  sJ y r3   )r   )valexpecteds     r.   test_get_check_estimator_idsrK   X   s    . $C(H444r0   )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      r.   test_estimatorsrV   r   s8    
 
!3[-P
  	i  s   	3<zZignore:Since version 1.0, it is not needed to import enable_hist_gradient_boosting anymorec                  ~   t         j                  j                  t        j                        g} t        j                  | dd       }|D cg c]  \  }}}|
 }}}|dgz   D ]R  }d|v sd|v rd|v rt        |d	      }t        |d
d      D ]%  }t        ||      rJ dj                  ||              T y c c}}w )Nsklearn.c                      y r3   r4   _s    r.   <lambda>z-test_import_all_consistency.<locals>.<lambda>       r0   )pathprefixonerrorsklearnz.tests.zsklearn.externalszsklearn._build_utilsdummy)fromlist__all__r4   z#Module '{0}' has no attribute '{1}')osr^   dirnamera   __file__pkgutilwalk_packages
__import__getattrhasattrr(   )sklearn_pathpkgsr[   modnamesubmodspackager+   s          r.   test_import_all_consistencyrr   }   s     GGOOG$4$456L   *nD -11=1gqw1G1i[( 
#6'#A!W,Ww7GY3 	D7D) +P+W+W, )	
 2s   B9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 r3   r4   rZ   s    r.   r\   z3test_root_import_all_completeness.<locals>.<lambda>   r]   r0   )r^   r`   .r[   )	re   r^   rf   ra   rg   rh   ri   r*   rd   )rm   
EXCEPTIONSr[   ro   s       r.   !test_root_import_all_completenessrz      sy    GGOOG$4$456L7J ..> *7A '>W//4:8M'//)))*r0   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 )NzK(?x)
        \.externals(\.|$)|
        \.tests(\.|$)|
        \._
        >   sklearn.datasets.datasklearn.datasets.descrsklearn.datasets.imagesrX   )r_   z.testszn{0} do not have `tests` subpackages. Perhaps they require __init__.py or a meson.build in the parent directory)recompilere   r^   rf   ra   rg   rh   ri   itemssearchr(   )HAS_TESTS_EXCEPTIONSresource_modulesrm   r[   r+   ispkglookupmissing_testss           r.   test_all_tests_are_importabler      s    
 ::	
 GGOOG$4$456L &33LT AtU 	eF  "<<>D%(($++D18O6) 	M  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 anymore)match)pytestraises	TypeErrorr   r   r%   r-   s    r.   test_class_support_removedr      sl     EC	y	, ,*+, 
y	, 6!3 456 6, ,6 6s   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_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
*$&&&FF+&&dQ&OC}}%%)JJllv{{005Q0R  	:-&&&::;s   B1C4C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        D ]  }dt        |j                        vrJ  	 d d d        } y # 1 sw Y   5xY w# 1 sw Y   xY w)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:;15P6  	Q	
 00. 	V	 }6 	V((5 8''00) " V9W__AUUUUV	V 	V	V 	V 	Vs*   +C#!C#$C#C#C C##C,	ensemblekernel_approximationc                 h    t        | d      ry| j                  j                  d      d   }|t        vS )Nget_feature_names_outTrx   r1   )rl   r>   split"GET_FEATURES_OUT_MODULES_TO_IGNORE)transformermodules     r.   '_include_in_get_feature_names_out_checkr     s7    {34##))#.q1F;;;r0   r   c                     t        t              5  t        | j                  j                  |        t        | j                  j                  |        d d d        y # 1 sw Y   y xY wrN   )r   rQ   r#   r   r=   r$   )r   s    r.   'test_transformers_get_feature_names_outr   !  sU     
=	2 
/!!**K	
 	7!!**K	
	
 
 
s   AAA$r   rS   c                 H    | j                   j                  }t        ||        y r3   )r   r=   r   )rS   estimator_names     r.   +test_estimators_get_feature_names_out_errorr   3  s     ((11N%ni@r0   c                     t        | t              rt        j                  d       | j                  j
                  }t        ||        y )NzFeatureUnion is not tested here)r   r   r   r   r   r=   r   rS   r+   s     r.   test_check_param_validationr   ;  s6     )\*5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 ];  }t        t              5  t        |j                   j                  |       d d d        = y # 1 sw Y   HxY w)N
set_outputz(Skipping check_set_output_transform for z!: Does not support set_output APIrO   )	r   r=   rl   r   r   r   r    r   rQ   )r   r+   rS   s      r.   test_set_output_transformr   Q  s     ##,,D><06tf = 	
 0"N P	 }6 	P&y':':'C'CYO	P 	PP	P 	Ps   !BB	
check_funcc                 :   | j                   j                  }t        | d      s&t        j                  d|j                   d| d       t        ||       D ]8  }t        t              5   ||j                   j                  |       d d d        : y # 1 sw Y   ExY w)Nr   z	Skipping z for z%: Does not support set_output API yetrO   )r   r=   rl   r   r   r   r   rQ   )r   r   r+   rS   s       r.   $test_set_output_transform_configuredr   b  s     ##,,D><0
++,E$ 8" "	
 0
NK @	}6 	@y**33Y?	@ 	@@	@ 	@s   (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=   rl   r   r   r   r   s     r.   #test_check_inplace_ensure_writeabler   z  s     ''Dy&!%(	H	%E*$@ABB yMWEu}/{M2"43r0   )r1   )Ur@   re   rh   r   r   	functoolsr   	itertoolsr   r   scipy.linalgr   ra   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   filterwarningsrr   rz   r   r   r   column_name_estimatorsr   r   r   GET_FEATURES_OUT_ESTIMATORSr   rl   %ESTIMATORS_WITH_GET_FEATURE_NAMES_OUTr   r   SET_OUTPUT_ESTIMATORSr   r   r   )r   s   0r.   <module>r      s3   
  	     &  & - 1 4 8  )    " 8 8	  		#%89	~&	w	'8	c	"$?@"'	6	
 
	34#,5-,5 		7R ,  	
** # #L	6;* 		)A.	/0')  ,2J  VV0 & "< "-0.s3   .4L  

 &')738O+PC) %
 6<T  AA
 (*+1I  ,, 	=).*LN;.,?	
	  +1I  PP +1I   ),)0		@	@ #%+C  44G()s   4M*5M/M/