
    >[g                        d dl Z d dlZd dlmZ d dlZd dlZd dlmZmZmZ d dl	m
Z
 d dlmZmZ d Zd Zd Zd	 Zej$                  j'                  d
g d      d        Zej$                  j+                  e
d      d        Zd Zd Zy)    N)ThreadPoolExecutor)config_context
get_config
set_config)_IS_WASM)Paralleldelayedc                  \   t               ddddddddddd
k(  sJ t        d       t               d	   du sJ t        d      5  t               ddddddddddd
k(  sJ 	 d d d        t               d	   du sJ t        d      5  t        d       5  t               d	   du sJ 	 d d d        t               d	   du sJ t        d      5  t               d	   du sJ t        d       5  t               d	   du sJ t        d       t               d	   du sJ 	 d d d        t               d	   du sJ 	 d d d        t               d	   du sJ 	 d d d        t               ddddddddddd
k(  sJ t        j                  t
              5  t        d       d d d        t        j                  t
              5  t        d
      j                          d d d        y # 1 sw Y   zxY w# 1 sw Y   BxY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)NFi   Tdiagram   default)
assume_finiteworking_memoryprint_changed_onlydisplayarray_api_dispatchpairwise_dist_chunk_sizeenable_cython_pairwise_disttransform_outputenable_metadata_routingskip_parameter_validationr   r   do_something_else)r   r   r   pytestraises	TypeError	__enter__     T/var/www/html/bid-api/venv/lib/python3.12/site-packages/sklearn/tests/test_config.pytest_config_contextr"      sF   <"#$''+%#(%*    &<(E111	d	+|!""& "'(++/ )',). 
 
 	
 
 
, <(E111	d	+$/<0D888 0 |O,444%0<0E999d3!|O4=== .!|O4<<< 4 <0E999 1 |O,444' 
,* <"#$''+%#(%*    
y	!t 
" 
y	!.88: 
"	!m 
,	+  0/ 43 10 
,	+F 
"	! 
"	!sx   GH
G%%%H

G>(/G2G>2H
H4H"G"%G/	*H
2G;7G>>H	H

HH"H+c                      t               d   du sJ 	 t        d      5  t               d   du sJ t               # 1 sw Y   nxY wn# t        $ r Y nw xY wt               d   du sJ y )Nr   FTr   )r   r   
ValueErrorr   r    r!   test_config_context_exceptionr%   Y   sv    <(E111$/<0D888, 0//  <(E111s    A ;A A 	AAc                     t               d   du sJ t        d        t               d   du sJ t        d       t               d   du sJ t        d        t               d   du sJ t        d       t               d   du sJ t        j                  t              5  t        d       d d d        y # 1 sw Y   y xY w)Nr   Fr   Tr   )r   r   r   r   r   r   r    r!   test_set_configr'   d   s    <(E111T"<(E111T"<(D000T"<(D000U#<(E111 
y	!T* 
"	!	!s   B55B>c                     t        |       5  t        j                  |       t               d   cddd       S # 1 sw Y   yxY w)zAReturn the value of assume_finite after waiting `sleep_duration`.r   r   N)r   timesleepr   )r   sleep_durations     r!   set_assume_finiter,   t   s,    	m	4

>"|O, 
5	4	4s	   "9Abackend)lokymultiprocessing	threadingc                 n    g d}g d} t        | d      d t        ||      D              }|g dk(  sJ y)ao  Test that the global config is threadsafe with all joblib backends.
    Two jobs are spawned and sets assume_finite to two different values.
    When the job with a duration 0.1s completes, the assume_finite value
    should be the same as the value passed to the function. In other words,
    it is not influenced by the other job setting assume_finite to True.
    FTFT皙?皙?r4   r5      )r-   n_jobsc              3   N   K   | ]  \  }} t        t              ||        y w)N)r	   r,   ).0r   	sleep_durs      r!   	<genexpr>z0test_config_threadsafe_joblib.<locals>.<genexpr>   s,      0(L$M9 	#!"=)<(Ls   #%N)r   zip)r-   assume_finitessleep_durationsitemss       r!   test_config_threadsafe_joblibr@   {   sF     0N*O/HWQ/ 0(+NO(L0 E
 ....r    zcannot start threads)reasonc                      g d} g d}t        d      5 }|j                  t        | |      D cg c]  }| }}ddd       g dk(  sJ yc c}w # 1 sw Y   xY w)zUses threads directly to test that the global config does not change
    between threads. Same test as `test_config_threadsafe_joblib` but with
    `ThreadPoolExecutor`.r2   r3   r6   )max_workersN)r   mapr,   )r=   r>   eoutputr?   s        r!   test_config_threadsaferG      sl     0N*O		*a %% 1>?S
S S 	 
 
+ ....
 
+	*s   A	AAAAc                 z   t         j                  fd}| j                  t         d|       t        j                  t
        d      5  t        d      5  	 ddd       ddd       t        j                  t
        d      5  t        d       ddd       y# 1 sw Y   BxY w# 1 sw Y   FxY w# 1 sw Y   yxY w)z=Check error is raised when array_api_compat is not installed.c                 2    | dk(  rt          | g|i |S Narray_api_compat)ImportErrornameargskwargsorig_imports      r!   mocked_importz;test_config_array_api_dispatch_error.<locals>.mocked_import   s'    %%41$1&11r    
__import__zarray_api_compat is requiredmatchTr   N)builtinsrS   setattrr   r   rL   r   r   monkeypatchrR   rQ   s     @r!   $test_config_array_api_dispatch_errorr[      s     %%K2
 ,>	{*H	It4 5 
J 
{*H	Id+ 
J	I 54 
J	I 
J	Is0   	B%BB%B1B"	B%%B.1B:c                    t         j                  fd}| j                  t         d|       | j                  t        j                  j
                  j                  dd       t        j                  t        d      5  t        d      5  	 d	d	d	       d	d	d	       t        j                  t        d      5  t        d       d	d	d	       y	# 1 sw Y   BxY w# 1 sw Y   FxY w# 1 sw Y   y	xY w)
z!Check error when NumPy is too oldc                 :    | dk(  r
t               S  | g|i |S rJ   )objectrM   s      r!   rR   zAtest_config_array_api_dispatch_error_numpy.<locals>.mocked_import   s(    %%8O41$1&11r    rS   __version__z1.20zNumPy must be 1.21 or newerrT   TrV   N)rW   rS   rX   sklearnutils
_array_apinumpyr   r   rL   r   r   rY   s     @r!   *test_config_array_api_dispatch_error_numpyrd      s     %%K2
 ,>0066vN	{*G	Ht4 5 
I 
{*G	Hd+ 
I	H 54 
I	H 
I	Hs0   >CCC8C&C	CC#&C/)rW   r)   concurrent.futuresr   r   r`   r   r   r   sklearn.utils.fixesr   sklearn.utils.parallelr   r	   r"   r%   r'   r,   markparametrizer@   xfailrG   r[   rd   r   r    r!   <module>rk      s      1   : : ( 4I;X2+ - $LM/ N/$ 8$:;/ </",*,r    