
    P3jF                     
   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	m
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mZ d d
lmZmZmZmZmZmZ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)Z)dZ*	 d dl,m-Z-  e'ej^                         e'e      k  r e+dej^                   de d      d Z0eeeeeeeee e!d
Z1e0e1d<   ejd                  jg                   ejh                  dd      dk7  d      Z5 ejl                   ejn                  ejp                  e5      ejr                  g      d        Z:d Z; e;e      Z< e;e      Z= e;e      Z> e;e      Z? e;e      Z@ e;e      ZA e;e      ZB e;e      ZC e;e       ZD e;e!      ZE ejl                  e0      ZFd ZG ejl                  d !      d"        ZHd# ZId$ ZJd% ZKd& ZLd' ZMejl                  d(        ZNe-de-_O        yy# e+$ r dZ*Y yw xY w# e.$ r dZ-Y w xY w))    N)suppress)wraps)environ)SkipTest)DoctestItem)face)threadpool_limits)PYTEST_MIN_VERSION)
fetch_20newsgroupsfetch_20newsgroups_vectorizedfetch_california_housingfetch_covtypefetch_kddcup99fetch_lfw_pairsfetch_lfw_peoplefetch_olivetti_faces
fetch_rcv1fetch_species_distributions)get_pytest_filterwarning_lines)	_IS_32BITnp_base_versionparse_version
sp_versionTF)	dt_configz/Your version of pytest is too old. Got version z, you should have pytest >= z installed.c                      t        j                  dd      dk(  } | st        d      	 dd l}t        d      S # t        $ r t        d      w xY w)	NSKLEARN_SKIP_NETWORK_TESTS101test is enabled when SKLEARN_SKIP_NETWORK_TESTS=0r   z#test requires pooch to be installedT)gray)r   getr   poochImportErrorr   )run_network_testsr"   s     =/DATA/.local/lib/python3.12/site-packages/sklearn/conftest.pyraccoon_face_or_skipr&   <   sY    $@#F#MJKK> T?  ><==>s	   8 A)
fetch_20newsgroups_fxt!fetch_20newsgroups_vectorized_fxtfetch_california_housing_fxtfetch_covtype_fxtfetch_kddcup99_fxtfetch_lfw_pairs_fxtfetch_lfw_people_fxtfetch_olivetti_faces_fxtfetch_rcv1_fxtfetch_species_distributions_fxtraccoon_face_fxtSKLEARN_RUN_FLOAT32_TESTSr   r   z:Set SKLEARN_RUN_FLOAT32_TESTS=1 to run float32 dtype testsreason)marks)paramsc              #   (   K   | j                    y wN)param)requests    r%   global_dtyper;   _   s     
--s   c                      t        j                  dd      dk(  t                fd       t        j                  fd      S )zAFetch dataset (download if missing and requested by environment).r   r   r   c                      |d<   	  | i |S # t         $ r.}t        |      dk7  r t        j                  d       Y d }~y d }~ww xY w)Ndownload_if_missingz1Data not found and `download_if_missing` is Falser   )OSErrorstrpytestskip)argskwargser>   fs      r%   wrappedz_fetch_fixture.<locals>.wrappedh   sV    (;$%	Md%f%% 	M1vLLKKKLL	Ms    	A$AAc                       S r8    )rG   s   r%   <lambda>z _fetch_fixture.<locals>.<lambda>r   s    '    )r   r!   r   rA   fixture)rF   r>   rG   s   `@@r%   _fetch_fixturerM   d   sC    !++&BCHCO
1XM M >>/**rK   c                    t        j                  dd      dk(  }t        j                  j	                  d      }t        t              }t               }|D ]  }t        |t              rAd|j                  v r3|j                  j                  d      d   }| d	}t        |g      |z  }	n't        |d
      sat        |j                        }
|
|z  }	|	s~|r||	z  }|j                  |        t        j                  dd      }|dk(  r.|r,|D ]'  }t        t              5  t        |           ddd       ) |D ]g  }|j                  j!                  d      st#        j$                         dk(  s7t        j                  j'                  d      }|j                  |       i d}	 ddl}t,        rd}d}n#t.        j"                  j1                  d      rd}d}t2        t5        d      k  rd}d}t6        t5        d      k  rd}d}|D ]$  }t        |t              si |j8                  _        & |rYt        j                  j	                        }|D ]4  }t        |t              s|j                  dk7  s$|j                  |       6 	 ddl}d}|sHt        j                  j	                  d      }|D ]"  }|j                  dv s|j                  |       $ yy# 1 sw Y   xY w# t*        $ r d}d}Y Mw xY w# t*        $ r d}Y yw xY w)zCalled after collect is completed.

    Parameters
    ----------
    config : pytest config
    items : list of collected items
    r   r   r   r   r3   fetch_._fxtfixturenamesPYTEST_XDIST_WORKERgw0NGradientBoostingClassifieraarch64zKknow failure. See https://github.com/scikit-learn/scikit-learn/issues/17797Fr   Tz*matplotlib is required to run the doctestsz;doctest are only run when the default numpy int is 64 bits.win32z\doctests are not run for Windows because numpy arrays repr is inconsistent across platforms.2z6Due to NEP 51 numpy scalar repr has changed in numpy 2z1.14z2Scipy sparse matrix repr has changed in scipy 1.14zsklearn._config.config_contextzpillow (or PIL) not installed!)z/sklearn.feature_extraction.image.PatchExtractorz3sklearn.feature_extraction.image.extract_patches_2d)r   r!   rA   markrB   setdataset_fetchers
isinstancer   namesplithasattrrS   
add_markerr   r   endswithplatformmachinexfail
matplotlibr#   r   sys
startswithr   r   r   dtestglobsPIL)configitemsr$   skip_networkdataset_features_setdatasets_to_downloaditemfetcher_function_namedataset_fetchers_keydataset_to_fetchitem_fixtures	worker_idr^   markerskip_doctestsrf   r4   skip_markerrk   pillow_installeds                       r%   pytest_collection_modifyitemsr{      s     $@#F#M;;##B $ L /05dK(X-B$(IIOOC$8$<!&;%<D#A "$8#9:=QQ~. 1 12M,/CC $44  OOL)% . 159IE/(D(# &( $# )  II;<  "i/[[&&P ' F OOF#  M>
 N		 	 	)5 	 s++ JM&))E
 dK(!DJJ  kk&&f&5D$,
 99 @@OOK0 ! kk&&.N&ODyy   ,  M $#(  >=>^  ! !s0   K&K' 	K; K$	'K87K8;L	L	function)scopec               #      K   t        j                  d      } | j                  d       |  | j                  d       yw)a/  Setup and teardown fixture for matplotlib.

    This fixture checks if we can import matplotlib. If not, the tests will be
    skipped. Otherwise, we close the figures before and after running the
    functions.

    Returns
    -------
    pyplot : module
        The ``matplotlib.pyplot`` module.
    zmatplotlib.pyplotallN)rA   importorskipclose)pyplots    r%   r   r      s6        !45F
LL
L
LLs   =?c                  ~  	 dd l 	d } | 	j                  j                  _        | 	j                  j                  _        | 	j                  j                  _         G 	fdd      } G d d|	j                  j
                        } G d d|	j                  j                        } G d	 d
|	j                  j                        } G d d|	j                  j                        } G d d|	j                  j                        } G d d|	j                  j                        } G d d|	j                  j                        }|x	j                  _        	j                  j                  _        |x	j                  _        	j                  j                  _        |x	j                  _        	j                  j                  _        |x	j                  _        	j                  j                  _        |x	j                  _	        	j                  j                   _	        |x	j                  _
        	j                  j"                  _
        |x	j                  _        	j                  j$                  _        |	j                  j                  _        |	j                  j                  _        |	j                  j                  _        |	j                  j                  _        |	j                  j                  _        |	j                  j&                  _        |	j                  j&                  _        |	j                  j&                  _        |	j                  j&                  _        |	j                  j&                  _        |	j                  j&                  _	        |	j                  j&                  _
        y )Nr   c                      t        d      )Nz7Old spmatrix function called. Use e.g. block or random.
ValueError)rC   kwdss     r%   flag_this_callz;munge_scipy_to_check_spmatrix_usage.<locals>.flag_this_call  s    RSSrK   c                        e Zd Z fdZ fdZ fdZd Zed        Zed        Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Z xZS )>munge_scipy_to_check_spmatrix_usage.<locals>._strict_mul_mixinc                     j                   j                  j                  |      st        d      t        |   |      S Nz"Operator * used here! Change to @?)sparse_sputilsisscalarliker   super__mul__selfother	__class__scipys     r%   r   zFmunge_scipy_to_check_spmatrix_usage.<locals>._strict_mul_mixin.__mul__  s6    <<((55e< !EFF7?5))rK   c                     j                   j                  j                  |      st        d      t        |   |      S r   )r   r   r   r   r   __rmul__r   s     r%   r   zGmunge_scipy_to_check_spmatrix_usage.<locals>._strict_mul_mixin.__rmul__"  7    <<((55e< !EFF7#E**rK   c                     j                   j                  j                  |      st        d      t        |   |      S r   )r   r   r   r   r   __imul__r   s     r%   r   zGmunge_scipy_to_check_spmatrix_usage.<locals>._strict_mul_mixin.__imul__'  r   rK   c                     t        d      )Nz6spmatrix ** used here! Use sparse.linalg.matrix_power?r   )r   rC   rD   s      r%   __pow__zFmunge_scipy_to_check_spmatrix_usage.<locals>._strict_mul_mixin.__pow__,  s    UVVrK   c                     t        d      )Nz2spmatrix A property is not allowed! Use .toarray()	TypeErrorr   s    r%   Az@munge_scipy_to_check_spmatrix_usage.<locals>._strict_mul_mixin.A/  s    PQQrK   c                     t        d      )Nz6spmatrix H property is not allowed! Use .conjugate().Tr   r   s    r%   Hz@munge_scipy_to_check_spmatrix_usage.<locals>._strict_mul_mixin.H3  s    TUUrK   c                     t        d      )Nz0spmatrix asfptype is not allowed! rewrite neededr   r   s    r%   asfptypezGmunge_scipy_to_check_spmatrix_usage.<locals>._strict_mul_mixin.asfptype7  s    NOOrK   c                     t        d      )Nz-spmatrix get_shape is not allowed! Use .shaper   r   s    r%   	get_shapezHmunge_scipy_to_check_spmatrix_usage.<locals>._strict_mul_mixin.get_shape:      KLLrK   c                     t        d      )Nz-spmatrix getformat is not allowed! Use .shaper   r   s    r%   	getformatzHmunge_scipy_to_check_spmatrix_usage.<locals>._strict_mul_mixin.getformat=  r   rK   c                     t        d      )Nz/spmatrix getmaxprint is not allowed! Use .shaper   r   s    r%   getmaxprintzJmunge_scipy_to_check_spmatrix_usage.<locals>._strict_mul_mixin.getmaxprint@  s    MNNrK   c                     t        d      )Nz*spmatrix getnnz is not allowed! Use .shaper   r   s    r%   getnnzzEmunge_scipy_to_check_spmatrix_usage.<locals>._strict_mul_mixin.getnnzC      HIIrK   c                     t        d      )Nz(spmatrix getH is not allowed! Use .shaper   r   s    r%   getHzCmunge_scipy_to_check_spmatrix_usage.<locals>._strict_mul_mixin.getHF  s    FGGrK   c                     t        d      )Nz*spmatrix getrow is not allowed! Use .shaper   r   s    r%   getrowzEmunge_scipy_to_check_spmatrix_usage.<locals>._strict_mul_mixin.getrowI  r   rK   c                     t        d      )Nz*spmatrix getcol is not allowed! Use .shaper   r   s    r%   getcolzEmunge_scipy_to_check_spmatrix_usage.<locals>._strict_mul_mixin.getcolL  r   rK   )__name__
__module____qualname__r   r   r   r   propertyr   r   r   r   r   r   r   r   r   r   __classcell__)r   r   s   @r%   _strict_mul_mixinr     st    	*
	+
	+
	W 
	R 
	R 
	V 
	V	P	M	M	O	J	H	J	JrK   r   c                       e Zd Zy)?munge_scipy_to_check_spmatrix_usage.<locals>._strict_coo_matrixNr   r   r   rI   rK   r%   _strict_coo_matrixr   O      rK   r   c                       e Zd Zy)?munge_scipy_to_check_spmatrix_usage.<locals>._strict_bsr_matrixNr   rI   rK   r%   _strict_bsr_matrixr   R  r   rK   r   c                       e Zd Zy)?munge_scipy_to_check_spmatrix_usage.<locals>._strict_csr_matrixNr   rI   rK   r%   _strict_csr_matrixr   U  r   rK   r   c                       e Zd Zy)?munge_scipy_to_check_spmatrix_usage.<locals>._strict_csc_matrixNr   rI   rK   r%   _strict_csc_matrixr   X  r   rK   r   c                       e Zd Zy)?munge_scipy_to_check_spmatrix_usage.<locals>._strict_dok_matrixNr   rI   rK   r%   _strict_dok_matrixr   [  r   rK   r   c                       e Zd Zy)?munge_scipy_to_check_spmatrix_usage.<locals>._strict_lil_matrixNr   rI   rK   r%   _strict_lil_matrixr   ^  r   rK   r   c                       e Zd Zy)?munge_scipy_to_check_spmatrix_usage.<locals>._strict_dia_matrixNr   rI   rK   r%   _strict_dia_matrixr   a  r   rK   r   )r   r   
_constructbmatrand
coo_matrix
bsr_matrix
csr_matrix
csc_matrix
dok_matrix
lil_matrix
dia_matrix_coo_bsr_csr_csc_dok_lil_dia_matrix)
r   r   r   r   r   r   r   r   r   r   s
            @r%   #munge_scipy_to_check_spmatrix_usager     s   T $2ELL #1ELL #1ELL 1J 1Jf.0G0G .0G0G .0G0G .0G0G .0G0G .0G0G .0G0G  >POELLell//:=OOELLell//:=OOELLell//:=OOELLell//:=OOELLell//:=OOELLell//:=OOELLell//:);ELL&);ELL&);ELL&);ELL&);ELL&&8ELL#&8ELL#&8ELL#&8ELL#&8ELL#&8ELL#&8ELL#rK   c                    t        t        d            }t        j                  d      }dg}||}n|dk(  r|}nyd|v r?|j	                  d      \  }}t        t        t        |      t        |      dz               }nt        |      g}t        |      dk  st        |      d	kD  rt        d
|       d| j                  v r| j                  d|       yy)a  Parametrization of global_random_seed fixture

    based on the SKLEARN_TESTS_GLOBAL_RANDOM_SEED environment variable.

    The goal of this fixture is to prevent tests that use it to be sensitive
    to a specific seed value while still being deterministic by default.

    See the documentation for the SKLEARN_TESTS_GLOBAL_RANDOM_SEED
    variable for instructions on how to use this fixture.

    https://scikit-learn.org/dev/computing/parallelism.html#sklearn-tests-global-random-seed

    d    SKLEARN_TESTS_GLOBAL_RANDOM_SEED*   Nr   -   r   c   zxThe value(s) of the environment variable SKLEARN_TESTS_GLOBAL_RANDOM_SEED must be in the range [0, 99] (or 'all'), got: global_random_seed)listranger   r!   r_   intminmaxr   rS   parametrize)metafuncRANDOM_SEED_RANGErandom_seed_vardefault_random_seedsrandom_seedsstartstops          r%   pytest_generate_testsr   {  s    $ U3Z(kk"DEO4+	E	!(/!)//4KE4c%j#d)a- @AL01L|q C$5$:$$3#46  x4441<@ 5rK   c                 ^    t         s| j                  dd       | j                  dddd       y )Nthread_unsafe_fixtureszlist of stuffz--check_spmatrix
store_trueFz,raise for spmatrix usage that breaks sparray)actiondefaulthelp)PARALLEL_RUN_AVAILABLEaddini	addoption)parserpluginmanagers     r%   pytest_addoptionr    s3    !.@
;	  rK   c                     d| j                   v r7| j                  j                  j                  rt	        j
                  d       y y y )Nno_check_spmatrixz9skip due to check_spmatrix scipy patch breaking this test)keywordsrl   optioncheck_spmatrixrA   rB   )rq   s    r%   pytest_runtest_setupr    s6    dmm+0B0B0Q0QOP 1R+rK   c                 B   	 dd l }|j                  d       t        j                  d      }t        j                  d      }|t        |t        |      z  d      }t        |       t        j                  dd      dk7  r!t               D ]  }| j                  d	|        | j                  j                  r
t                t        sI| j                  d
d       | j                  d
d       | j                  d
d       | j                  d
d       y y # t        $ r Y w xY w)Nr   aggT)only_physical_coresPYTEST_XDIST_WORKER_COUNTr   SKLEARN_WARNINGS_AS_ERRORSr   filterwarningsmarkerszOparallel_threads(n): run the given test function in parallel using `n` threads.z8thread_unsafe: mark the test function as single-threadedzCiterations(n): run the given test function `n` times in each thread)rf   user#   joblib	cpu_countr   r!   r   r   r	   r   addinivalue_liner  r  r   r  )rl   rf   allowed_parallelismxdist_worker_countlines        r%   pytest_configurer    s#   u !**tD %@A% ""5=O9P"PRST)*{{/5< 34D##$4d; 5 }}## 	,-!!	

 	F	
 	Q	
 	Q	
 "5  s   D 	DDc                 ^    t         j                  fd}| j                  t         d|       y)z!Pretend pandas was not installed.c                 :    | dk(  r
t                | g|i |S )Npandas)r#   )r^   rC   rD   import_origs      r%   mocked_importz,hide_available_pandas.<locals>.mocked_import  s(    8-41$1&11rK   
__import__N)builtinsr#  setattr)monkeypatchr"  r!  s     @r%   hide_available_pandasr'    s)     %%K2
 ,>rK   )Pr$  rc   rg   
contextlibr   	functoolsr   osr   unittestr   r  numpynprA   _pytest.doctestr   scipy.datasetsr   threadpoolctlr	   sklearn._min_dependenciesr
   sklearn.datasetsr   r   r   r   r   r   r   r   r   r   sklearn.utils._testingr   sklearn.utils.fixesr   r   r   r   pytest_run_parallelr  r#   scipy_doctest.conftestr   ModuleNotFoundError__version__r&   r\   rZ   skipifr!   _SKIP32_MARKrL   r9   float32float64r;   rM   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r{   r   r   r   r  r  r  r'  strict_checkrI   rK   r%   <module>r>     s     
        '  + 8   B #!
0 ##$}5G'HH

9&:L:L9M N""4!5[	B 
 1)F$<&(*, 4 'B  (< # ${{!!GKK+S1S8G "  RZZ|DbjjQR S+$ ((:; $23P$Q !-.FG "=1 #N3 $_5 %&67 )*>? 
+"01L"M !6>>"67 y-x j! "$f9R*AZQ
1
h 	? 	? !I [  #"#  Is$   4G) ;G7 )G43G47HH