
    /ii(;                    !   d 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Zddlm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  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- ddl.m/Z/m0Z0m1Z1m2Z2 ddl3m4Z4m5Z5 ddl6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z? ddl@mAZA ddlBmCZCmDZDmEZEmFZFmGZG ddlHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZb d Zcd Zdeje        f                    dejg        g                    d           ejg        ddd          g          d              Zhd! Zid" Zjd# Zkeje        f                    d$ejl        d%fejm        d&fejm        d%fg          eje        f                    d'ejn        ejo        g          d(                         Zpeje        f                    d)ejl        d*d+d,fejl        dd+d-fejl        d.d+d/fejl        dd&d-fejm        d*d+d0fejm        dd+d1fejm        d2d+d3fejm        d*d4d5fejm        d*d6d0fg	          eje        f                    d'ejn        ejo        g          d7                         Zqeje        f                    d8g d9          eje        f                    d'ejn        ejo        g          d:                         Zrd; Zseje        f                    d< ejt        d6ejm        gg          d=f ejt        d6ejm        gg          d=f ejt        d6ejl        gg          d>f ejt        d6ejm        ggeu?          d@fg          eje        f                    dAd+d%g          dB                         ZvdC Zweje        x                    dD          dE             Zyeje        f                    ddFdGgdHdIgg ejt        dFdGgdHdIggdJ?           ejt        dFdGgdHdIggdK?          dLdMgdNdOgg ejt        dLdMgdNdOggdP?          g          dQ             Zzeje        f                    dRg dS          eje        f                    dTej{        ej|        gej{        fej|        ej|        fdUej|        fg          dV                         Z}dW Z~dX ZdY ZdZ Zd[ Zd\ Zd] Z ej        g d^_          d`             Zda Zdb Zdc Zdd Zde Zdf Zdg Zdh Zdi Zdj Zeje        f                    dk ed          eegg dlm          dn             Zdo Zeje        f                    dp e2            e0m          dq             Zdr Zds Zdt Zeje        f                    duej|        ej{        fej|        ddUf          eje        f                    dvdw          dx                         Zdy Zdz Z G d{ d|          Z G d} d~          Zd Zeje        f                    dd+d%g          d             Zeje        f                    dd edddd+i          dd+dfd edddd+i          dd+dfd edddd+i          gdgd+dfd edddd+i          dgd+dfd edddd+i          ddefd edddd+i          ddefgg dm          d             Zeje        f                    d'ejn        ejo        ej        ej        ej        ej        ej        ej        g          d             Zd Zd Zeje        f                    dg d          d             Zeje        f                    dd6deddd ed          fddej        ddd ed          fddej        ddd ed          fd6deefddd ed          fd6deddd ed          fddeddd ed          fddeddd ed          fddeddd ed          fddeddd ed          fddeddd ed          fddeddd ed          fg          d             Zd ejt        d6dg          dd*f ejt        d6dg           ejt        d6dg          dd*fd ejt        ddg          edfd ejt        ddg          ed*f ejt        d6dgej{        ?           ejt        d6dgej{        ?          edf ejt        d6dgej|        ?           ejt        d6dgej|        ?          edfd ejt        ddg          edfdZeje        f                    d ee                                           ee                                          m          eje        f                    dd+d%g          d                         Zdedfdedfdedf ejt        ddgej{        ?          edf ejt        ddgej|        ?          edfdǜZeje        f                    d ee                                           ee                                          m          dɄ             Zdʄ Zd˄ Zeje        f                    d e2                      d̈́             Zeje        f                    ddgdd6gdd6gg dТg dѢg          d҄             Zeje        f                    d e2            e0m          eje        f                    ddgdd6gdd6gg dТg dѢg          dӄ                         Zeje        f                    dg dԢdgddgg          dք             Zeje        f                    d e2            e0m          eje        f                    dg dԢdgddgg          dׄ                         Zeje        f                    dejt        ejo        ej        g          dل             Zeje        f                    dejt        ejo        ej        g          dڄ             Zeje        f                    dejo        ej        g          dۄ             Zd܄ Zd݄ Zdބ Zeje        f                    ddd6dgg          d             Zeje        f                    dg d          d             Zeje        f                    dg d          d             Zeje        f                    dddej        fddej        fddej        fddej        fddej        fddej        fddej        fddej        fddej        fddej        fddej        fddej        fddej        fd dej        fddej        fg          d             Zeje        f                    dg d          d             Zeje        f                    dg dg d	g d
g ddd6iddiddiggg dm          eje        f                    dg d          d                         Zeje        f                    dg dg dm          d             Zeje        f                    d e ed                     ed          dddgddgggg dm          d             ZӐd Zeje        f                    dg d          d             ZՐd Zeje        f                    ddd6gdfd ddggd!fgd"d#gm          d$             Z G d% d&e          Zؐd' Zِd( Zڐd) Zeje        f                    d*g d+          d,             Zܐd- Zݐd. Zeje        f                    d/dd6dd6dejm        gg d0g          d1             Ze?d2             Zeje        f                    d3g d4          eje        f                    d5d+d%g          d6                         Zd7 Zeje        f                    d8eEeDz   eCz   eFz             eje        f                    d9g d:          d;                         Zeje        f                    d< ejt        d6           ejt        d          gd6dgddggg          d=             Zd> Zd? Zd@ ZdA Ze?dB             Zeje        f                    g dC ejt        d6dgddggd6dgddggg           e            dDf ejt        d6dgddggd6dgddggg          ddEfg          dF             ZdS (G  z$Tests for input validation functions    N)product)
itemgetter)NamedTemporaryFile)importorskip)config_context)BaseEstimator)
make_blobs)RandomForestRegressor)NotFittedErrorPositiveSpectrumWarning)ARDRegression)EstimatorWithFit)KNeighborsClassifier)_sparse_random_matrix)SVR)_safe_indexingas_float_arraycheck_arraycheck_symmetric	check_X_y
deprecated)_convert_to_numpy_get_namespace_device_dtype_ids_is_numpy_namespace)yield_namespace_device_dtype_combinations)MockDataFrame_MockEstimatorOnOffPrediction)	SkipTest
TempMemmap_array_api_for_tests_convert_containerassert_allcloseassert_allclose_dense_sparseassert_array_equalcreate_memmap_backed_data'skip_if_array_api_compat_not_configured)_NotAnArray)COO_CONTAINERSCSC_CONTAINERSCSR_CONTAINERSDIA_CONTAINERSDOK_CONTAINERS)FLOAT_DTYPES_allclose_dense_sparse_check_feature_names_in_check_method_params_check_pos_label_consistency_check_psd_eigenvalues_check_response_method_check_sample_weight_check_y_deprecate_positional_args_estimator_has_get_feature_names
_is_fitted_num_features_num_samples_to_object_arrayassert_all_finitecheck_consistent_lengthcheck_is_fittedcheck_memorycheck_non_negativecheck_random_statecheck_scalarcolumn_or_1dhas_fit_parametervalidate_datac                     t          d           t          j        j        j        u sJ t          t          j                  t          j        j        j        u sJ t          j                            d          } t          d                              d          |                     d          k    sJ t          j                            d          } t          |           | u sJ t          j                            d          } t          d                              d          |                     d          k    sJ t          j        t                    5  t          d           d d d            d S # 1 swxY w Y   d S )N*   d   +   zsome invalid seed)
rB   nprandommtrand_randRandomStaterandintpytestraises
ValueError)rng_42s    i/var/www/html/bet.cuttalo.com/ml/venv/lib/python3.11/site-packages/sklearn/utils/tests/test_validation.pytest_make_rngrV   _   s   d##ry'7'=====bi((BI,<,BBBBBY""2&&Fb!!))#..&..2E2EEEEEY""2&&Ff%%////Y""2&&Fb!!))#..&..2E2EEEEE	z	"	" 0 0.///0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0s   E55E9<E9c                  Z   t          j        dt           j                  } | t          j        dt           j                  z   } t	          | d          }|j        t           j        k    sJ |                     t           j                  } t	          | d          }t	          | d          | usJ |j        t           j	        k    sJ t          t           j        t           j        t           j        t           j        t           j        t           j        g}|D ]=}|                     |          } t	          |           }|j        t           j        k    sJ >|                     t                     } t	          | d          }|j        t           j	        k    sJ t          j        dt           j                  } t	          | d          | u sJ t          j        |           } t          j        t	          | d                    sJ t'          j        t          j        d                                                    t-          ddd	
                                          g}|D ]J}t	          |d          }t           j        |d<   t          j        |                                          rJ Kd S )N)   
   dtyperY   FcopyT)rX         皙?)densityr   r   )rK   onesint32aranger   r[   float32astypeint64float64boolint8int16uint8uint16uint32objectasfortranarray	isfortransp
csc_matrixtoarrayr   nanisnanany)XX2tested_dtypesr[   matricesMNs          rU   test_as_float_arrayr   q   sY   
rx(((A	BIb))))A		&	&	&B8rz!!!!	A		%	%	%B!%(((11118rz!!!!27BHbh")RYWM & &HHUOOAx2:%%%%% 	
A		%	%	%B8rz!!!! 	bj)))A!%(((A----
!A<qt44455555 	bill##++--b"d333;;==H  % %14(((&$8A;;??$$$$$$% %    ry   rY   r^   rY   r^   csrformatc                     |                                  } t          j        | d<   t          j        | d<   t          | d          }t	          ||            d S )N)r_   r   )      	allow-nanensure_all_finite)r]   rK   rv   r   r#   )ry   X_converteds     rU   test_as_float_array_nanr      sO     	
AfAdGfAdG kBBBK a00000r   c                     t          j        d                              dd          } t          t	          |           t           j                  rJ t          t	          t          j        |                     t           j                  rJ d S )N   rX      )rK   re   reshape
isinstancer   matrixrs   rt   ry   s    rU   test_np_matrixr      so    
	"a##A.++RY77777.q)9)9::BIFFFFFFFr   c                  x   d } t          d          5 }t          j        |dt          j                  }d|d d <   t          t          j        | fD ]O} ||          }d|d d <   t          |                                |                                           d|d d <   P	 d d d            d S # 1 swxY w Y   d S )Nc                 $    t          | d          S )NFr\   )r   )xs    rU   <lambda>ztest_memmap.<locals>.<lambda>   s    nQU333 r   zsklearn-test)prefixrY   rY   )shaper[   r   r   )r   rK   memmaprf   r   asarrayr$   ravel)asflttmpr}   fry   s        rU   test_memmapr      s	    43E	>	2	2	2 cIc<<<!!!rz51 	 	A!AAaaaDqwwyy!''))444AaaaDD			                 s   BB//B36B3c                  ^   t          j        d          } | | j        fD ]Q}dD ]L}t          |d|          }|j        d         sJ t          |d|          }|j        d         sJ |r||usJ MRt          j        |           } | j        d d d         | _        | j        j        d         rJ d S )	N)rY   r_   )TFC)orderr]   C_CONTIGUOUSFF_CONTIGUOUS)rK   rc   Tr   flagsrs   
csr_matrixdata)ry   Ar]   Bs       rU   test_orderingr      s     	AV " "! 	" 	"DASt444A7>****ASt444A7>**** "zzzz	" 	aAVDDbD\AFv|N++++++r   zvalue, ensure_all_finiteFr   retypec                      |t          j        d                              dd                              t                              }| |d<   t          ||d          }t          ||           d S )Nr   r^   rb   T)r   accept_sparse)rK   re   r   rg   floatr   r#   )valuer   r   ry   	X_checkeds        rU   (test_check_array_ensure_all_finite_validr      sn     	ry||##Aq))007788AAdGA1BRVWWWI I.....r   z/value, input_name, ensure_all_finite, match_msg TzInput contains infinityzInput X contains infinitysample_weightz%Input sample_weight contains infinityInput contains NaNzInput X contains NaNyzInput y contains NaNz	allow-infz1ensure_all_finite should be a bool or 'allow-nan'r   c                 :    |t          j        d                              dd                              t           j                            }| |d<   t          j        t          |          5  t          |||d           d d d            d S # 1 swxY w Y   d S )Nr   r^   rb   matchT)
input_namer   r   )	rK   re   r   rg   ri   rQ   rR   rS   r   )r   r   r   	match_msgr   ry   s         rU   *test_check_array_ensure_all_finite_invalidr      s    . 	ry||##Aq))00<<==AAdG	z	3	3	3 
 
!/		
 	
 	
 	

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s   /BBBr   )ry   r   r   c                     |t          j        d                              dd                              t           j                            }t           j        |d<   t                      }d|j        j         d}t          j
        t          d|  d          5 }t          ||| d	
           d d d            n# 1 swxY w Y   | dk    r||j        j        d         v sJ n||j        j        d         vsJ | dk    rt          j
        t          d|  d          5 }t                                          |t          j        |j        d                              d d d            n# 1 swxY w Y   ||j        j        d         v sJ d S d S )Nr   r^   rb   
aX   does not accept missing values encoded as NaN natively. For supervised learning, you might want to consider sklearn.ensemble.HistGradientBoostingClassifier and Regressor which accept missing values encoded as NaNs natively. Alternatively, it is possible to preprocess the data, for instance by using an imputer transformer in a pipeline or drop samples with missing values. See https://scikit-learn.org/stable/modules/impute.html You can find a list of all estimators that handle NaN values at the following page: https://scikit-learn.org/stable/modules/impute.html#estimators-that-handle-nan-valueszInput z contains NaNr   T)	estimatorr   r   ry   r   )rK   re   r   rg   ri   rv   r   	__class____name__rQ   rR   rS   r   r   argsfitrc   r   )r   r   r   r   extended_msgctxs         rU   0test_check_array_links_to_imputer_doc_only_for_Xr      s     6")A,,&&q!,,33BJ??@@DDJI	-Y ) 	- 	- 	-  
z)K*)K)K)K	L	L	L 
PS!		
 	
 	
 	

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 Ssy~a00000039>!#44444S ]:-Oj-O-O-OPPP 	4TWEEIIdBGDJqM22333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4sy~a00000 
 10s%   B;;B?B?A E**E.1E.c                  N   t          j        ddt           j        ggt                    j        } t          | d d          }| |u sJ t          | d d          }| |u sJ t          j        t          d          5  t          | d d	           d d d            d S # 1 swxY w Y   d S )
NabrZ   r   r[   r   Fr   r   T)	rK   arrayrv   rp   r   r   rQ   rR   rS   )ry   r   s     rU   )test_check_array_ensure_all_finite_objectr   )  s    
3RV$%V4446AAT[IIII	>>>>ATUCCCI	>>>>	z)=	>	>	> ; ;ATT::::; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;s   :BB!Bz
X, err_msgInput contains NaN.z5Input contains infinity or a value too large for.*intrZ   z#cannot convert float NaN to integerr   c                     t          j        t          |          5  t          | t          |           d d d            d S # 1 swxY w Y   d S )Nr   r   )rQ   rR   rS   r   int)ry   err_msgr   s      rU   8test_check_array_ensure_all_finite_object_unsafe_castingr   6  s    0 
z	1	1	1 G GAS4EFFFFG G G G G G G G G G G G G G G G G Gs   AAAc                     t          j        d          } |                     g d          }dt          |           d}t          j        t
          |          5  t          |d           ddd           dS # 1 swxY w Y   dS )	z
    Check that we raise a proper error message when passing a Series and we expect a
    2-dimensional container.

    Non-regression test for:
    https://github.com/scikit-learn/scikit-learn/issues/27498
    pandasr   r^   rX   z+Expected a 2-dimensional container but got z	 instead.r   T	ensure_2dN)rQ   r   SeriestyperR   rS   r   )pdsermsgs      rU   test_check_array_series_err_msgr   R  s     
	X	&	&B
))III

C
LS		
L
L
LC	z	-	-	- ) )C4(((() ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) )s   A99A= A=z3ignore:Can't check dok sparse matrix for nan or infc                     ddgddgg} t          j        |           }t          j        t                    5  t          |           d d d            n# 1 swxY w Y   t          g dd          }|j        dk    sJ t          j        t          d	          5  t          g dd
           d d d            n# 1 swxY w Y   t          j        t          d	          5  t          dd
           d d d            n# 1 swxY w Y   t          t           d          r~t          t          t          j        |                               }|j        dk    rEt          j        t          d	          5  t          |d
d
           d d d            n# 1 swxY w Y   t          j        d                              ddd          }t          j        t                    5  t          |           d d d            n# 1 swxY w Y   t          |d
           t          j        d                              dd                              d                              d          }                    t"                    }                    t$                    }|||g}t          j        t"          t$          t          j        d t*          t,          g}	g d}
d
dg}t/          ||	|
|          D ]\  } }}}t          | |||          }||j        |k    sJ n|j        | j        k    sJ |dk    r|j        d         sJ |j        d         rJ n$|dk    r|j        d         sJ |j        d         rJ |r| |usJ | j        |j        k    r>|j        d         | j        d         k    r"|j        d         | j        d         k    r| |u sJ g }|                    fdt6          t8          z   t:          z   t<          z   D                        |                    |d                             t          j                  |d                             t          j                   g           ddgddgg}d |	D             }t/          ||||          D ]\  } }}}t          | |||          }||j        |k    sJ n|j        | j        k    sJ | j!        |v r| j!        |j!        k    sJ n|j!        |d         k    sJ |r| |usJ t| j        |j        k    r| j!        |j!        k    r| |u sJ t          ddgddgg          }tE          |t          j#                  sJ t          j        t                    5  t          |$                                           d d d            n# 1 swxY w Y   t          |$                                d
           tK          |          }t          |          }tE          |t          j#                  sJ t          ddgddgg          }d }t          j        t          |	          5  t          |d
d!tM                      "           d d d            d S # 1 swxY w Y   d S )#Nr   r^   rX   r   )r   r   r^   Fr   z'Expected 2D array, got 1D array insteadr   Tz+Expected 2D array, got scalar array insteadrY   	csr_arrayzExpected 2D input, got)r   r      allow_ndr   r   )r   r   N)r[   r   r]   r   r   c                 &    g | ]} |          S  r   ).0sparse_containerX_Cs     rU   
<listcomp>z$test_check_array.<locals>.<listcomp>  s4     	
 	
 	
  S!!	
 	
 	
r   r   r   coodokc                 $    g | ]}|t           u|S r   )rp   )r   dts     rU   r   z$test_check_array.<locals>.<listcomp>  s"    AAA&0@0@0@0@0@r   r[   r   r]   z<Negative values in data passed to X in RandomForestRegressorry   )ensure_non_negativer   r   )'rs   r   rQ   rR   	TypeErrorr   ndimrS   hasattrnextiterr   rK   re   r   r]   rg   r   r   rd   rf   rj   rp   r   r[   r   extendr*   r)   r(   r,   rh   ri   r   r   ndarraytolistr'   r
   )ry   X_csrX_array
sparse_rowX_ndimX_FX_intX_floatXsdtypesorderscopysr[   r   r]   r   accept_sparsesnon_object_dtypesr   X_dense
X_no_arrayresultX_negr   r   s                           @rU   test_check_arrayr  a  s    Q!QAM!E	y	!	!  E               )))u555G<1	z)R	S	S	S / /III..../ / / / / / / / / / / / / / / 
z)V	W	W	W ( (B$''''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( r; L$r|A//00
?az1IJJJ L LJddKKKKL L L L L L L L L L L L L L L Yq\\!!!Q**F	z	"	"  F              &&&& )A,,

q!
$
$
)
)#
.
.C
((3--CJJsOOEjjG
sE7	#BhUBJdFCFF5ME!(VVU!C!C & &5%e$GGG	?e+++++?ag----C<<?>2222 ~66666c\\?>2222 ~6666 		&I%%%%% 9?**ON3qw~7NNNON3qw~7NNNI~~~~
 
BII	
 	
 	
 	
$2%% %	
 	
 	
   IIr!u||BH%%r!u||BJ'?'?@AAAenuen5N BAfAAA)0
~u* * & &%5-  mRVWWW	?e+++++?ag----8}$$8y////// #}Q'77777 	&I%%%%% w)/))ah):J.J.JI~~~~ Aq6Aq6*++Ggrz*****	z	"	" % %FMMOO$$$% % % % % % % % % % % % % % %$//// W%%J$$Ffbj))))) !Q"a)**ELG	z	1	1	1 
 
 $+--		
 	
 	
 	

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s}   AAAB99B= B=C==DD1FFFG99G= G=/"VV!$V!7 Y$$Y(+Y(1234US   1   2   3   4V1c                     d}t          j        t          |          5  t          | d           ddd           dS # 1 swxY w Y   dS )zmTest that check_array errors when it receives an array of bytes/string
    while a numeric dtype is required.z>dtype='numeric' is not compatible with arrays of bytes/stringsr   numericrZ   NrQ   rR   rS   r   )ry   expected_msgs     rU   test_check_array_numeric_errorr    s     UL	z	6	6	6 ( (AY''''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (s   =AApd_dtype)Int8Int16UInt8UInt16Float32Float64zdtype, expected_dtyper  c                    t          j        d          }| dv rt          j        dd          }t          j        dddt          j        t          j        gt          j        t          j        dd	d
gg dg          j        }|                    || g d          }|d                             d          |d<   t          |d|          }t          ||           |j
        |k    sJ t          |d|          }t          ||           |j
        |k    sJ d}t          j        t          |          5  t          |d           d d d            d S # 1 swxY w Y   d S )Nr   >   r#  r$  z1.2)
minversionr   r^   rX   r   r   r   )r   r^   rX   r   r_   r   r   c)r[   columnsr(  r   r   )r   r[   Fr   r   Tr   )rQ   r   rK   r   rv   r   	DataFramerg   r   r"   r[   rR   rS   )r  r[   expected_dtyper   X_npry   r   r   s           rU   "test_check_array_pandas_na_supportr-    s    
	X	&	&B))) e<<<8
Q2626	"RVRVQ1$=O  	
 	T???CCAsV]]7##AcFAEJJJIIt$$$?n,,,,AeDDDIIt$$$?n,,,,
C	z	-	-	- / /A..../ / / / / / / / / / / / / / / / / /s   2EEEc                  (   t          j        d          } |                     dd| j        gd          }d}t          j        t
          |          5  t          |dd	
           ddd           n# 1 swxY w Y   t          |d	d	
          }t          |ddt          j	        g           |j
        t          j        k    sJ t          |d	d	t          j                  }t          |ddt          j	        g           |j
        t          j        k    sJ dS )z4Check check_array is correct with pd.NA in a series.r   r   r^   Int64rZ   r   r   TF)r   r   N)r   r   r[   )rQ   r   r   NArR   rS   r   r"   rK   rv   r[   ri   rf   )r   X_int64r   X_outs       rU   *test_check_array_panadas_na_support_seriesr3     s[   		X	&	&BiiAruWi55G
C	z	-	-	- F FGtuEEEEF F F F F F F F F F F F F F F 5EJJJEEAq"&>***;"*$$$$5E  E EAq"&>***;"*$$$$$$s   A00A47A4c                  &   t          j        d          } t          j        g dg dg dgt          j                  }|                     |          }t          |          j        t          j        k    sJ t          |t                    j        t          j        k    sJ |	                    dt          j
        i          }t          |j        t          j
        t          j        t          j        f           t          |          j        t          j        k    sJ t          |t                    j        t          j        k    sJ |	                    dt          j        i          }t          |          j        t          j        k    sJ t          |t                    j        t          j        k    sJ |	                    dt          j
        i          }t          |          j        t          j        k    sJ t          |t                    j        t          j        k    sJ |	                    t          j                  }t          |          j        t          j        k    sJ t          |t                    j        t          j        k    sJ |                     d|                     g d          i          }t          |          j        t          j        k    sJ t          |t                    j        t          j        k    sJ d S )	Nr   r   r   r_   r      r   	   rZ   r   r^   cat_col)rQ   r   rK   r   rf   r*  r   r[   r-   rg   float16r$   r  rl   ri   Categoricalrh   )r   ry   X_dfcat_dfs       rU   %test_check_array_pandas_dtype_castingr>  5  sw   		X	&	&B
)))YYY			2"*EEEA<<??Dt"bj0000t<0006"*DDDD;;2:''Dt{RZRZ$HIIIt"bj0000t<0006"*DDDD;;28}%%Dt"bj0000t<0006"*DDDD;;2:''Dt"bj0000t<0006"*DDDD;;rx  Dt"bh.... t<0006"*DDDD
 \\9bnnYYY&?&?@AAFv$0000v\2228BJFFFFFFr   c                  .   t          j        ddgddgddgddgg          } t          |           }t          |          }|j        | j        k    sJ t          |t           j                  }|j        t          j        t           j                  k    sJ d S )Ng?gffffff?g333333?g      ?g?r`   rZ   )rK   r   r   r   r[   rf   )arrmock_dfchecked_arrs      rU   "test_check_array_on_mock_dataframerC  Z  s    
(S#Jc
S#Jc
C
D
DCC  Gg&&K	))))gRZ888K 4 4444444r   c                      g dg dg dg} t          |           j        j        dk    sJ t          | d          j        j        dk    sJ d S )Nr   r5  r6  iFr   )r   r[   kindr   s    rU    test_check_array_dtype_stabilityrG  c  sa    	IIIyyy)Aq>>$++++qE***05<<<<<<r   c                     g dg dg dg} t          j        | t           j                  }t          j        | t           j                  }t	          j        |          }t	          j        |          }t	          j        |t           j                  }||g}|||g}t          j	                    5  t          j
        d           |D ]5}t          |t           j        d          }	|	j        t           j        k    sJ 6|D ]}t          |t           j        t           j        gd          }	|	j        t           j        k    sJ |	|u sJ t          |t           j        t           j        gdd	gd
          }	|	j        t           j        k    sJ |	|usJ t          |t           j        t           j        gdd	gd
          }	|	j        t           j        k    sJ |	|usJ |	j        dk    sJ 	 d d d            d S # 1 swxY w Y   d S )Nr   r5  r6  rZ   errorT)r[   r   r   r   r   F)rK   r   rf   rh   rs   r   rt   rd   warningscatch_warningssimplefilterr   ri   r[   r   )

X_int_list	X_float32r1  X_csr_float32X_csc_float32X_csc_int32integer_datafloat32_datary   r   s
             rU   test_check_array_dtype_warningrT  j  sl   ))YYY			2J
:RZ888Ij28444GM),,MM),,M-rx888K[)L}m<L		 	"	" ) )g&&& 	1 	1A#ARZtLLLI?bj00000 	& 	&A#"*bj1  I ?bj0000>>>>#z2:.$en	  I ?bj0000A%%%%%:rz* %.	
 
 
	 "*,,,,----5(((((?) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) )s   0D4G22G69G6c                     ddgddgg} t          j        |           }t                      }d}t          j        t
          |          5  t          |d           d d d            n# 1 swxY w Y   d	}t          j        t          |          5  t          ||           d d d            n# 1 swxY w Y   d
}t          j        t          |          5  t          |g            d d d            n# 1 swxY w Y   t          j        t          |          5  t          |d           d d d            n# 1 swxY w Y   t          j        t
          d          5  t          ||g           d d d            d S # 1 swxY w Y   d S )Nr   r^   rX   r   ziSparse data was passed, but dense data is required. Use '.toarray\(\)' to convert to a dense numpy array.r   Fr   zjParameter 'accept_sparse' should be a string, boolean or list of strings. You provided 'accept_sparse=.*'.z]When providing 'accept_sparse' as a tuple or list, it must contain at least one string value.r   r   )rs   r   r   rQ   rR   r   r   rS   )ry   r   invalid_typer   s       rU   -test_check_array_accept_sparse_type_exceptionrX    s   
Q!QAM!E55L	A  
y	,	,	, 0 0E////0 0 0 0 0 0 0 0 0 0 0 0 0 0 0	G  
z	-	-	- 7 7E66667 7 7 7 7 7 7 7 7 7 7 7 7 7 7	5  
z	-	-	- - -E,,,,- - - - - - - - - - - - - - -	z	-	-	- - -E,,,,- - - - - - - - - - - - - - -	y	.	.	. 9 9E,88889 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9sZ   A&&A*-A*B,,B03B0C22C69C6D66D:=D:E<<F F c                      ddgddgg} t          j        |           }t          |d           t          |d           t          |dg           t          |d           d S )	Nr   r^   rX   r   TrV  r   )r   )rs   r   r   )ry   r   s     rU   +test_check_array_accept_sparse_no_exceptionrZ    sw    
Q!QAM!ET****U++++eW----X......r   )r   cscr   bsr)paramsc              #     K   t          j        dd| j                  }| j        dk    rst          |d          r$t	          d |j        D                       |_        n}|j                            d          |_        |j                            d          |_        n>|j	                            d          |_	        |j
                            d          |_
        |V  d S )N   rY   r   r   coordsc              3   @   K   | ]}|                     d           V  dS )rh   N)rg   )r   vs     rU   	<genexpr>zX_64bit.<locals>.<genexpr>  s.      AA1QXXg..AAAAAAr   rh   )rs   rL   paramr   tupler`  rowrg   colindicesindptr)requestry   s     rU   X_64bitrk    s      
	"b///A}1h 
	* AAAAAAAAHH ELL))AEELL))AEEI$$W--	8??7++
GGGGGr   c                 *    t          | dd           d S )NT)accept_large_sparser   )r   )rk  s    rU   1test_check_array_accept_large_sparse_no_exceptionrn    s    TFFFFFFr   c                     d}t          j        t          |          5  t          | dd           d d d            d S # 1 swxY w Y   d S )NzbOnly sparse matrices with 32-bit integer indices are accepted. Got int64 indices. Please do reportr   TF)r   rm  r  )rk  r   s     rU   4test_check_array_accept_large_sparse_raise_exceptionrp    s    	<  
z	-	-	- L LG4UKKKKL L L L L L L L L L L L L L L L L Ls   >AAc                  \   d} t          j        t          |           5  t          g g           d d d            n# 1 swxY w Y   d} t          j        t          |           5  t          g d           d d d            n# 1 swxY w Y   t	          j        d          } t          j        t          |           5  t          dd           d d d            n# 1 swxY w Y   t          j        d          }t          j        d	          }d
} t          j        t          |           5  t          ||d           d d d            n# 1 swxY w Y   t          j        t          |           5  t          ||dd           d d d            n# 1 swxY w Y   t          j        d          }t          j        d          }d} t          j        t          |           5  t          ||d           d d d            n# 1 swxY w Y   t          j        t          |           5  t          ||dd           d d d            n# 1 swxY w Y   t          j
        d                              dd          }t          j        d          }d} t          j        t          |           5  t          ||           d d d            n# 1 swxY w Y   t          j        d          }t          j        d          }t          ||d          \  }}t          ||           t          ||           d S )NzC0 feature\(s\) \(shape=\(1, 0\)\) while a minimum of 1 is required.r   z@0 sample\(s\) \(shape=\(0,\)\) while a minimum of 1 is required.Fr   zgInput should have at least 1 dimension i.e. satisfy `len(x.shape) > 0`, got scalar `array(42)` instead.rH   )r   rY   r   zC1 sample\(s\) \(shape=\(1, 10\)\) while a minimum of 2 is required.r^   )ensure_min_samples)rr  r   r   zD2 feature\(s\) \(shape=\(10, 2\)\) while a minimum of 3 is required.rX   )ensure_min_featuresT)rs  r   r   rY   zD0 feature\(s\) \(shape=\(10, 0\)\) while a minimum of 1 is required.)rY   r      rt  r   )rQ   rR   rS   r   reescaper   rK   rc   r   emptyr   r$   )r   ry   r   r   	y_checkeds        rU   2test_check_array_min_samples_and_features_messagesry    s   
PC	z	-	-	-  RD              
 NC	z	-	-	- ) )B%(((() ) ) ) ) ) ) ) ) ) ) ) ) ) ) )B C 
y	,	,	, ) )B%(((() ) ) ) ) ) ) ) ) ) ) ) ) ) ) 	A


A
PC	z	-	-	- . .!Q1----. . . . . . . . . . . . . . .
 
z	-	-	- ? ?!Q1>>>>? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
 	A


A
QC	z	-	-	- / /!QA..../ / / / / / / / / / / / / / /
 
z	-	-	- > >!QA====> > > > > > > > > > > > > > >
 	B""A
A
QC	z	-	-	-  !Q               	  A
A$QD999Iyq)$$$q)$$$$$s   ;??#BBB;CC C)EEE.FFFG==HH#II
I'KKKc                     t          j        g dg dg          } t          j        t          d          5  t          |            d d d            n# 1 swxY w Y   g dg dg} t          j        t          d          5  t          |            d d d            n# 1 swxY w Y   d} t          j        t          d          5  t          |            d d d            n# 1 swxY w Y   t          j        g d          t          j        g d          g} t          j        t          d          5  t          |            d d d            n# 1 swxY w Y   t          j        g d          t          j        g d          f} t          j        t          d          5  t          |            d d d            n# 1 swxY w Y   t          t          j        g dg dg                    } t          j        t          d          5  t          |            d d d            n# 1 swxY w Y   t          j        ddgddgg          } t          j        t          d          5  t          |            d d d            n# 1 swxY w Y   t          j        g d          }t          j        t          d          5  t          |           d d d            d S # 1 swxY w Y   d S )	N      ?       @      @      @      @      @       @      @      @      @      @      @zComplex data not supportedr   )r{  r  r   r|  )r|  r}  r~  r  r  r  )
rK   r   rQ   rR   rS   r   r   rs   
coo_matrixr5   )ry   r   s     rU   #test_check_array_complex_data_errorr  #  s   
***,D,D,DEFFA	z)E	F	F	F  A               
"	!	!#;#;#;<A	z)E	F	F	F  A               	=A	z)E	F	F	F  A               
***	+	+RX6N6N6N-O-OPA	z)E	F	F	F  A               
***	+	+RX6N6N6N-O-OPA	z)E	F	F	F  A               	bh 8 8 8:R:R:RSTTUUA	z)E	F	F	F  A               	6{QF+,,A	z)E	F	F	F  A              
 	AAABBA	z)E	F	F	F                   s   AAA BB #B C  C$'C$2EEE F<<G G 	H%%H),H)%JJJ=KK!Kc                     t          t          d          rJ t          t          d          sJ t          t          d          sJ t          t                      d          sJ  G d d          } t          | d          s
J d            d S )Nr   c                   8    e Zd Z ed          dd            ZdS )@test_has_fit_parameter.<locals>.TestClassWithDeprecatedFitMethodz7Deprecated for the purpose of testing has_fit_parameterNc                     d S Nr   )selfry   r   r   s       rU   r   zDtest_has_fit_parameter.<locals>.TestClassWithDeprecatedFitMethod.fitT      Dr   r  )r   
__module____qualname__r   r   r   r   rU    TestClassWithDeprecatedFitMethodr  S  s?        	M	N	N	 	 	 
O	N	 	 	r   r  z=has_fit_parameter fails for class with deprecated fit method.)rE   r   r
   r   )r  s    rU   test_has_fit_parameterr  M  s     !5GGGGG2ODDDDDS/22222SUUO44444       
 =OO  G    r   c            	         t          j        ddgddgg          } t          j        d          }t          j        ddgddgg          }|t          j        |          t          j        |          t          j        |          t          j        |          t          j        |          t          j	        |          d}t          j        t                    5  t          |           d d d            n# 1 swxY w Y   |                                D ]\  }}t          j        t                     5  t          |           d d d            n# 1 swxY w Y   t          j        t                    5  t          |d           d d d            n# 1 swxY w Y   t          |d          }t          j        |          r0|j        |k    sJ t'          |                                |            t'          ||            d S )	Nr   r   r^   )denser   r   r[  r   lilr\  T)raise_exceptionF)raise_warning)rK   r   rc   rs   
dok_matrixr   rt   r  
lil_matrix
bsr_matrixrQ   rR   rS   r   itemswarnsUserWarningissparser   r$   ru   )arr_symarr_badarr_asymtest_arrays
arr_formatr@  outputs          rU   test_check_symmetricr  ]  s   hAA'((GgajjGx!Q!Q())H }X&&}X&&}X&&}X&&}X&&}X&& K 
z	"	" ! !   ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ',,.. 0 0
C\+&& 	! 	!C   	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!]:&& 	7 	7C6666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 !E:::;v 	0=J....v~~//9999vw////0 0s6   C44C8;C81EE	E	1FF	F	c                      G d dt                     } t          j        t                    5  t	           |                        d d d            n# 1 swxY w Y   t	           |                                                        d S )Nc                       e Zd Zd Zd ZdS )6test_check_is_fitted_with_is_fitted.<locals>.Estimatorc                     d| _         | S )NT)r9   r  kwargss     rU   r   z:test_check_is_fitted_with_is_fitted.<locals>.Estimator.fit  s    "DOKr   c                 0    t          | d          o| j        S )Nr9   )r   r9   r  s    rU   __sklearn_is_fitted__zLtest_check_is_fitted_with_is_fitted.<locals>.Estimator.__sklearn_is_fitted__  s    4..B4?Br   N)r   r  r  r   r  r   r   rU   	Estimatorr    s7        	 	 		C 	C 	C 	C 	Cr   r  )r   rQ   rR   r   r?   r   )r  s    rU   #test_check_is_fitted_with_is_fittedr    s    C C C C CM C C C 
~	&	& % %		$$$% % % % % % % % % % % % % % %IIKKOO%%&&&&&s   AAAc                  Z     G d dt                     } t           |                        dS )z;Check that check_is_fitted passes for stateless estimators.c                   $     e Zd Zd Z fdZ xZS ):test_check_is_fitted_stateless.<locals>.StatelessEstimatorc                     | S r  r   r  s     rU   r   z>test_check_is_fitted_stateless.<locals>.StatelessEstimator.fit      Kr   c                 V    t                                                      }d|_        |S )NF)super__sklearn_tags__requires_fit)r  tagsr   s     rU   r  zKtest_check_is_fitted_stateless.<locals>.StatelessEstimator.__sklearn_tags__  s%    77++--D %DKr   )r   r  r  r   r  __classcell__)r   s   @rU   StatelessEstimatorr    sG        	 	 		 	 	 	 	 	 	 	 	r   r  N)r   r?   )r  s    rU   test_check_is_fitted_statelessr    sL        ]    &&(()))))r   c                  8   t          j        t                    5  t          t                     d d d            n# 1 swxY w Y   t          j        t                    5  t          d           d d d            n# 1 swxY w Y   t	                      } t                      }	 t          j        t                    5  t          |            d d d            n# 1 swxY w Y   t          j        t                    5  t          |           d d d            n# 1 swxY w Y   n# t          $ r J d            w xY wd}d}t          j        t          |          5  t          | |           d d d            n# 1 swxY w Y   d}d	}t          j        t          |          5  t          ||           d d d            n# 1 swxY w Y    | j	        t                         |j	        t                        t          |           J t          |          J d S )
Nr   Fz&check_is_fitted failed with ValueErrorz!Random message %(name)s, %(name)sz+Random message ARDRegression, ARDRegressionr   )r   z"Another message %(name)s, %(name)szAnother message SVR, SVR)rQ   rR   r   r?   r   r   r   rS   AttributeErrorr   r	   )ardsvrr   r   s       rU   test_check_is_fittedr    sz   	y	!	! ' '&&&' ' ' ' ' ' ' ' ' ' ' ' ' ' '	y	!	!                 //C
%%C?]>** 	! 	!C   	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!]>** 	! 	!C   	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! ? ? ?>>>>>? .C9E	z	/	/	/ & &%%%%& & & & & & & & & & & & & & & /C&E	~U	3	3	3 & &%%%%& & & & & & & & & & & & & & & CGZ\\CGZ\\3'''3'''''s   ;??A;;A?A?#D$ <CD$ CD$ C D$ <DD$ DD$ D D$ $D9E99E= E=#GGGc                      G d dt                     } d} |             }t          |ddg          rJ t          j        t          |          5  t          |ddg           d d d            n# 1 swxY w Y   t          |ddgt                    rJ t          j        t          |          5  t          |ddgt                     d d d            n# 1 swxY w Y   t          |ddgt                    rJ t          j        t          |          5  t          |ddgt                     d d d            n# 1 swxY w Y   d	|_        t          |ddg          rJ t          j        t          |          5  t          |ddg           d d d            n# 1 swxY w Y   t          |ddgt                    rJ t          j        t          |          5  t          |ddgt                     d d d            n# 1 swxY w Y   t          |ddgt                    sJ t          |ddgt                     d
|_	        t          |ddg          sJ t          |ddg           t          |ddgt                    sJ t          |ddgt                     t          |ddgt                    sJ t          |ddgt                     d S )Nc                       e Zd Zd ZdS )4test_check_is_fitted_attributes.<locals>.MyEstimatorc                     | S r  r   r  ry   r   s      rU   r   z8test_check_is_fitted_attributes.<locals>.MyEstimator.fit  r  r   N)r   r  r  r   r   r   rU   MyEstimatorr    s#        	 	 	 	 	r   r  z
not fitteda_b_)
attributesr   )r  
all_or_anyr   r   )
r   r9   rQ   rR   r   r?   allrx   r  r  )r  r   ests      rU   test_check_is_fitted_attributesr    s       m    C
+--C#4,777777	~S	1	1	1 6 6t55556 6 6 6 6 6 6 6 6 6 6 6 6 6 6#4,3GGGGGG	~S	1	1	1 F FtEEEEF F F F F F F F F F F F F F F#4,3GGGGGG	~S	1	1	1 F FtEEEEF F F F F F F F F F F F F F F CF#4,777777	~S	1	1	1 6 6t55556 6 6 6 6 6 6 6 6 6 6 6 6 6 6#4,3GGGGGG	~S	1	1	1 F FtEEEEF F F F F F F F F F F F F F FctTlsCCCCCCCT4LSAAAACFctTl333333CT4L1111ctTlsCCCCCCCT4LSAAAActTlsCCCCCCCT4LSAAAAAAsZ   A00A47A41CCCD>>EE F  F$'F$!HHHwrap)singlelistre  )idsc                    t                      }t          j        t          d          5  t	          | | dg                     d d d            n# 1 swxY w Y    |j        t                        t	          | | dg                     t          j        t          d          5  t	          | | dg                     d d d            d S # 1 swxY w Y   d S )Nzis not fitted yetr   coef_	coef_bad_)r   rQ   rR   r   r?   r   r	   )r  r  s     rU   $test_check_is_fitted_with_attributesr    s[    //C	~-@	A	A	A . .TT7)__---. . . . . . . . . . . . . . . CGZ\\ Cwi))) 
~-@	A	A	A 2 2TT;-001112 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2s#   AAA'CCCc                     t          dgdgdgdgdg           t          ddgddgggddgddg           t          dgdt          j        dg          t          j        d	                     t          j        t          d
          5  t          ddgdg           ddd           n# 1 swxY w Y   t          j        t          d          5  t          ddgd           ddd           n# 1 swxY w Y   t          j        t          d          5  t          ddgt                                 ddd           n# 1 swxY w Y   t          j        t                    5  t          ddgt          j        d                     ddd           n# 1 swxY w Y   t          j        t          d          5  t          ddgt                                 ddd           dS # 1 swxY w Y   dS )zpTest that `check_consistent_length` raises on inconsistent lengths and wrong
    input types trigger TypeErrors.r   r^   rX   r   r_   r   r   )r^   r   r^   inconsistent numbers of samplesr   Nzgot <\w+ 'int'>zgot <\w+ 'object'>Expected sequence or array-like)r>   rK   r   rs   r   rQ   rR   rS   r   rp   r
   r   r   rU   test_check_consistent_lengthr    s&    QC!qcA3444aVq!fX.Ac
CCCQCrx}}bmF6K6KLLL	z)J	K	K	K - -A,,,- - - - - - - - - - - - - - -	y(:	;	;	; + +A***+ + + + + + + + + + + + + + +	y(=	>	>	> 2 2A1112 2 2 2 2 2 2 2 2 2 2 2 2 2 2	y	!	! 5 5A4445 5 5 5 5 5 5 5 5 5 5 5 5 5 5 
y(I	J	J	J A AA(=(?(?@@@A A A A A A A A A A A A A A A A A AsZ   B((B,/B,C--C14C1D>>EE"%FFF9G%%G),G)zarray_namespace, device, _c                 Z   t          | |          }t          d          5  t          |                    g d|          |                    ddgddgddgg|          g dg dt	          j        dt
          	          t          j        d
dgdd
gd
d
gg                     t          j	        t          d          5  t          |                    ddg|          |                    dg|                     ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )zCTest that check_consistent_length works with different array types.Tarray_api_dispatchr   devicer   r^   rX   r'  rZ   r   r  r   N)r    r   r>   r   rK   rp   rs   r   rQ   rR   rS   )array_namespacer  _xps       rU   &test_check_consistent_length_array_apir    s    
ov	6	6B	4	0	0	0  JJyyyJ00JJAAA/J??IIOOJf555L1a&1a&1a&122	
 	
 	
 ]:-NOOO 	 	#

Aq6&
112::qc&:3Q3Q  	 	 	 	 	 	 	 	 	 	 	 	 	 	 	                 s6   BD >>D<D D	D D	D  D$'D$c                      	 dd l } t          j        g dg dg dg          }|                     |g d          }t	          |           d S # t
          $ r t          d          w xY w)Nr   r   r5  r6  )r   r   r   r)  zPandas not found)r   rK   r   r*  r>   ImportErrorr   )r   ry   r<  s      rU   "test_check_dataframe_fit_attributer  %  s    +HiiiIII677||A'8'8'8|99%%%%% + + +)***+s   A	A A'c                     t          j        dt           j        g          } t          j        t
                    5  t          |            d d d            n# 1 swxY w Y   t          j        d           t          |            t          j        d           t          j        t
                    5  t          |            d d d            d S # 1 swxY w Y   d S )Nr   T)assume_finiteF)	rK   r   infrQ   rR   rS   r=   sklearn
set_configr   s    rU   test_suppress_validationr  2  sB   
!RVA	z	"	"  !              T****aU++++	z	"	"  !                 s#   AAA3CCCc                     t          d          } t          |                     g d          d          }t          |t	          j        g d                     |                     g d                              d          }t          |d d          }t          |t	          j        g dt                               d S )	Nr   r   Fr   r'  category)r[   r   rZ   )r   r   r   r$   rK   r   rg   rp   )r   resss      rU   test_check_array_seriesr  =  s    	h		B
bii			**e
<
<
<CsBHYYY//000 			///""))*55A
atu
5
5
5CsBH___FCCCDDDDDr   r[   
bool_dtype)rj   booleanc                 L   t          d          }|                    g dg d|                    g d|          dg d          }t          ||           }|j        t
          j        k    sJ t          j        g dg d	g d
gt                    }t          ||           d S )Nr   r   )r   r`    @TFTrZ   )r   r   rj   r  )      ?        r  )       @r`   r  )      @r  r  )
r   r*  r   r   r[   rK   ri   r   r   r#   )r[   r  r   dfr   expected_arrays         rU   'test_check_dataframe_mixed_float_dtypesr  I  s     
h		B	99"]]II111IDD	
 	

 )(( 
 
 
B %(((E;"*$$$$X	///???;5  N !77777r   c                     t          d          } |                     dg di          }t          |d          }|j        t          j        k    sJ t          |dgdgdgg           |                     g dg dd	dd
g          }t          |d          }|j        t          j        k    sJ t          |ddgddgddgg           dS )z7Check that dataframe with bool return a boolean arrays.r   rj   r  NrZ   TFr   )rj   r   r   r  r  r   r   r^   rX   )r   r*  r   r[   rK   bool_r$   rh   r   r  r   s      rU   #test_check_dataframe_with_only_boolr  g  s    	h		B	v2223	4	4B$'''E;"(""""uvw7888 
$$$YYY77 
 
 
B ),,,E;"(""""u1v1v1v677777r   c                      t          d          } |                     d|                     g dd          i          }t          |d          }|j        t
          j        k    sJ t          |dgdgdgg           dS )	zFCheck that dataframe with boolean return a float array with dtype=Noner   rj   r  r  rZ   NTF)r   r*  r   r   r[   rK   ri   r$   r   s      rU   &test_check_dataframe_with_only_booleanr  z  s    	h		B	vryy)<)<)<IyNNO	P	PB$'''E;"*$$$$uvw788888r   c                       e Zd Zd ZdS )DummyMemoryc                     |S r  r   )r  funcs     rU   cachezDummyMemory.cache  s    r   N)r   r  r  r  r   r   rU   r  r    s#            r   r  c                       e Zd ZdS )WrongDummyMemoryNr   r  r  r   r   rU   r
  r
    s        Dr   r
  c                 ,   t          | dz            }t          |          }|j        |k    sJ t          d           }|j        J t                      }t          |          }||u sJ d}t	          j        t          |          5  t          d           d d d            n# 1 swxY w Y   t                      }d                    |          }t	          j        t          |          5  t          |           d d d            d S # 1 swxY w Y   d S )Ncache_directoryzf'memory' should be None, a string or have the same interface as joblib.Memory. Got memory='1' instead.r   r   zg'memory' should be None, a string or have the same interface as joblib.Memory. Got memory='{}' instead.)	strr@   locationr  rQ   rR   rS   r
  r   )tmp_pathr  memorydummyr   s        rU   test_check_memoryr    s   (%6677O/**F?o----$F?"""MME%  FU????	2  
z	-	-	-  Q              E	3396%==  
z	-	-	-  U                 s$   B##B'*B',D		DDr]   c                    t          j        d          }t          |d          5 }t          ||           }t          j        ||          |  k    sJ |j        d         | k    sJ 	 d d d            d S # 1 swxY w Y   d S )N)r   r   r	mmap_moder\   	WRITEABLE)rK   rc   r   r   may_share_memoryr   )r]   ry   X_memmapr   s       rU   test_check_array_memmapr    s    
A	A	%	%	% 4t444	"8Y77HEEEE{+t333334 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4s   AA55A9<A9zOestimator_name, estimator_value, delegates, expected_result, expected_exception
estimator_SubEstimatorr   attribute_presentr   estimators_custom_estimatorno_estimatorattribute_absent)'fitted_estimator_with_default_delegates estimator_with_default_delegates#list_of_estimators_with_estimators_&custom_estimator_with_custom_delegates#no_estimator_with_default_delegates5estimator_with_default_delegates_but_absent_attributec                 6   |t          d          }nt          d|          } G d d          } |            }t          || |           |r:t          j        |          5   ||           ddd           dS # 1 swxY w Y   dS  ||          |k    sJ dS )z
    Tests the _estimator_has function by verifying:
    - Functionality with default and custom delegates.
    - Raises ValueError if delegates are missing.
    - Raises AttributeError if the specified attribute is missing.
    Nr  )	delegatesc                       e Zd ZdS ))test_estimator_has.<locals>.MockEstimatorNr  r   r   rU   MockEstimatorr,    s        r   r-  )r7   setattrrQ   rR   )estimator_nameestimator_valuer*  expected_resultexpected_exceptioncheckr-  r   s           rU   test_estimator_hasr4    s    J 2332iHHH        	AA~/// +]-.. 	 	E!HHH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 uQxx?******s   "A;;A?A?c                 f   t          j        g dg dg dg dg          } | |          }t          |d            | ddgddgg          }t          |d           d|d<    | |          }t          j        t
          d          5  t          |d           d d d            d S # 1 swxY w Y   d S )	N)r   r   r   r   )r   r   r   r   r   r   r   rb   z	Negative r   )rK   r   rA   rQ   rR   rS   )r   r   ry   s      rU   test_check_non_negativer6    s    	,,,lllLLLIJJAq		Aq"AA  Aq"AdGq		A	z	5	5	5 " "1b!!!" " " " " " " " " " " " " " " " " "s   B&&B*-B*c                  d   t          j        d          } d }d}t          j        t          |          5  t          | |           d d d            n# 1 swxY w Y   d}t          j        t          |          5  t          | |t                                 d d d            d S # 1 swxY w Y   d S )Nr^   r^   z;estimator requires y to be passed, but the target y is Noner   zGRandomForestRegressor requires y to be passed, but the target y is Noner   )rK   rc   rQ   rR   rS   r   r
   )ry   r   r   s      rU    test_check_X_y_informative_errorr:  "  s-   
AA
GC	z	-	-	-  !Q               TC	z	-	-	- ; ;!Q"7"9"9::::; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;s#   AAA9B%%B),B)c                  (    G d d          }  |             }t          |          t          |          k    sJ  G d d          }t          j        t          d          5  t           |                       d d d            d S # 1 swxY w Y   d S )Nc                       e Zd Zd Zd ZdS )Jtest_retrieve_samples_from_non_standard_shape.<locals>.TestNonNumericShapec                     d| _         d S N)znot numericr   r  s    rU   __init__zStest_retrieve_samples_from_non_standard_shape.<locals>.TestNonNumericShape.__init__0      )DJJJr   c                 $    t          g d          S )Nr   )lenr  s    rU   __len__zRtest_retrieve_samples_from_non_standard_shape.<locals>.TestNonNumericShape.__len__3  s    yyy>>!r   N)r   r  r  rA  rE  r   r   rU   TestNonNumericShaper=  /  s2        	* 	* 	*	" 	" 	" 	" 	"r   rF  c                       e Zd Zd ZdS )Jtest_retrieve_samples_from_non_standard_shape.<locals>.TestNoLenWeirdShapec                     d| _         d S r?  r@  r  s    rU   rA  zStest_retrieve_samples_from_non_standard_shape.<locals>.TestNoLenWeirdShape.__init__;  rB  r   N)r   r  r  rA  r   r   rU   TestNoLenWeirdShaperH  :  s#        	* 	* 	* 	* 	*r   rJ  r  r   )r;   rD  rQ   rR   r   )rF  ry   rJ  s      rU   -test_retrieve_samples_from_non_standard_shaperK  .  s   " " " " " " " " 	A??c!ff$$$$* * * * * * * * 
y(I	J	J	J , ,((**+++, , , , , , , , , , , , , , , , , ,s   "BBBr   )r^   rX   g      @r_   c           	          t          j                    5  t          j        d           t          | dt          j        ddd          }ddd           n# 1 swxY w Y   || k    sJ dS )zPTest that check_scalar returns no error/warning if valid inputs are
    providedrI  	test_namer^   r_   bothtarget_typemin_valmax_valinclude_boundariesN)rJ  rK  rL  rC   numbersReal)r   scalars     rU   test_check_scalar_validrW  B  s     
	 	"	" 	
 	
g&&&%
 
 
	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 Q;;;;;;s   4AAAzJx, target_name, target_type, min_val, max_val, include_boundaries, err_msg
test_name1r   neitherz1test_name1 must be an instance of float, not int.z6test_name1 must be an instance of float, not NoneType.z4test_name1 must be an instance of int, not NoneType.z9test_name1 must be an instance of {float, bool}, not int.
test_name2ztest_name2 == 1, must be > 2.r_   
test_name3ztest_name3 == 5, must be < 4.
test_name4rightztest_name4 == 2, must be > 2.
test_name5leftztest_name5 == 4, must be < 4.
test_name6zbad parameter valuezyUnknown value for `include_boundaries`: 'bad parameter value'. Possible values are: ('left', 'right', 'both', 'neither').
test_name7zT`include_boundaries`='left' without specifying explicitly `min_val` is inconsistent.
test_name8zU`include_boundaries`='right' without specifying explicitly `max_val` is inconsistent.c           	      (   t          j        t                    5 }t          | |||||           ddd           n# 1 swxY w Y   t	          |j                  t	          |          k    sJ t          |j        t          |                    sJ dS )zLTest that check_scalar returns the right error if a wrong input is
    givenrO  N)rQ   rR   	ExceptionrC   r  r   r   r   )r   target_namerP  rQ  rR  rS  r   raised_errors           rU   test_check_scalar_invalidrg  S  s    l 
y	!	! 
\#1	
 	
 	
 	

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 |!""c'll2222l($w--8888888s   <A A r  )r_   y        -C6
?zJThere are imaginary parts in eigenvalues \(1e\-05 of the maximum real part)r_   g-C6
gưz?There are negative eigenvalues \(1e\-06 of the maximum positiveg|۽z?There are negative eigenvalues \(1e\-10 of the maximum positive)r_   g-=z=the largest eigenvalue is more than 1e\+12 times the smallest)nominalnominal_np_arrayinsignificant_imagzinsignificant negzinsignificant neg float32zinsignificant neg float64zinsignificant posz(lambdas, expected_lambdas, w_type, w_msgenable_warningsc                 ^   |sd }|Wt          j                    5  t          j        dt                     t	          | |          }d d d            n# 1 swxY w Y   n?t          j        ||          5  t	          | |          }d d d            n# 1 swxY w Y   t          ||           d S )NrI  )rk  r   )rJ  rK  rL  r   r2   rQ   r  r"   )lambdasexpected_lambdasw_typew_msgrk  lambdas_fixeds         rU    test_check_psd_eigenvalues_validrr    sF     ~$&& 	 	!'+BCCC2  M	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 \&... 	 	2  M	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
 $m44444s#   ,AAA4BBB)r_   y              @z/There are significant imaginary parts in eigenv)r   z,All eigenvalues are negative \(maximum is -1)r_   r   z*There are significant negative eigenvaluesga2U0*3?ggh㈵>g|)significant_imagzall negativezsignificant negzsignificant neg float32zsignificant neg float64zlambdas, err_type, err_msgc                     t          j        ||          5  t          |            d d d            d S # 1 swxY w Y   d S )Nr   )rQ   rR   r2   )rm  err_typer   s      rU   "test_check_psd_eigenvalues_invalidrw  0  s     
xw	/	/	/ ( (w'''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (s   488c                    t          d |                     d                    }t          t          ||           t	          j        d                     t          d|                     d                    }t          t          ||           dt	          j        d          z             t          j        t          d          5  t          |                     d          |                     d	                     d d d            n# 1 swxY w Y   t          j	        d
|                     d          j
         d          }t          j        t          |          5  t          |                     d          |                     d	                     d d d            n# 1 swxY w Y   |                     d          }|                     d| j                  }t          ||          }|j        | j        k    sJ |                     d          }|                     t          |                    }d|d<   d}t          j        t          |          5  t          ||d           d d d            d S # 1 swxY w Y   d S )Nr_   r^   r   r_   r  r^   z)Sample weights must be 1D array or scalarr   )r^   r   r8  zsample_weight.shape == r   z, expected (2,)!rZ   r   z1Negative values in data passed to `sample_weight`T)r   )r4   rc   r"   r   rK   rQ   rR   rS   ru  rv  r   rf   r[   r;   )r  r   r   ry   r   s        rU   _check_sample_weight_commonr{  =  s    )AAAM%mR88"'!**EEE )@@@M%mR88!bgajj.III 
z)U	V	V	V A ARWWV__@@@@A A A A A A A A A A A A A A A )Pbggajj.>PPP
Q
QC	z	-	-	- < <RWWQZZ2776??;;;;< < < < < < < < < < < < < < < 	AGGARZG00M(::M"*,,,, 	AGGLOO,,MM"AG	z	1	1	1 I I]A4HHHHI I I I I I I I I I I I I I I I I Is6   8DDD!8F%%F),F)I<<J J c                  |   t          j        d          d d d         } | j        d         rJ t          | t          j        d                    } | j        d         sJ t	          t                      t          j        dt
                    }t          d ||j                  } | j        t           j        k    sJ d S )NrY   r^   r   r_   r   r   ry  rZ   )rK   rc   r   r4   r{  r   r[   ri   )r   ry   s     rU   test_check_sample_weightr~  `  s    GBKK!$M">2222("'&//JJJM~....### 	c"""A(q@@@M"*,,,,,,r   zarray_namespace,device,dtypec                    t          | |          }t          d          5  |                    d          d d d         }t          |          r|j        d         rJ t          ||                    d                    }t          |          r|j        d         sJ t          |           d d d            d S # 1 swxY w Y   d S )NTr  rY   r^   r   r}  r   )r    r   rc   r   r   r4   r{  )r  r  r[   r  r   s        rU   "test_check_sample_weight_array_apir  o  s    
ov	6	6B	4	0	0	0 	( 	(CCaC(r"" 	;$*>::::,]bggfooNNNr"" 	7 &~6666#B'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(s   BB<<C C y_truer   )r   r   r   )r   r   r   c                 2    t          d |           dk    sJ d S )Nr   )r1   r  s    rU    test_check_pos_label_consistencyr    s#    'f55::::::r   c                     t          | |          }t          d          5  |                    ||          }t          d |          dk    sJ 	 d d d            d S # 1 swxY w Y   d S )NTr  r  r   )r    r   r   r1   r  r  r[   r  r  r@  s         rU   *test_check_pos_label_consistency_array_apir    s     
ov	6	6B	4	0	0	0 < <jjj//+D#66!;;;;;< < < < < < < < < < < < < < < < < <s   .AA!$A!)r^   rX   r   rz  c                     t          j        t          d          5  t          d |            d d d            n# 1 swxY w Y   t          d|           dk    sJ d S )Ny_true takes value inr   r   )rQ   rR   rS   r1   r  s    rU   (test_check_pos_label_consistency_invalidr    s    	z)@	A	A	A 3 3$T62223 3 3 3 3 3 3 3 3 3 3 3 3 3 3 (V44;;;;;;s   9= =c                 Z   t          | |          }t          d          5  |                    ||          }t          j        t
          d          5  t          d |           d d d            n# 1 swxY w Y   t          d|          dk    sJ 	 d d d            d S # 1 swxY w Y   d S )NTr  r  r  r   r   )r    r   r   rQ   rR   rS   r1   r  s         rU   2test_check_pos_label_consistency_invalid_array_apir    s8    
ov	6	6B	4	0	0	0 = =jjj//]:-DEEE 	4 	4(s333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 ,C55<<<<<= = = = = = = = = = = = = = = = = =s5   3B A1%B 1A5	5B 8A5	9B  B$'B$ru   c                     t          j        d                              dd          } | |           | |          }}t          ||          sJ d S )Nr8  rX   rK   re   r   r.   ru   baser   r   s       rU   !test_allclose_dense_sparse_equalsr    sT    9Q<<1%%D74==''$--qA!!Q'''''''r   c                     t          j        d                              dd          } | |           | |dz             }}t          ||          rJ d S )Nr8  rX   r   r  r  s       rU   %test_allclose_dense_sparse_not_equalsr    sZ    9Q<<1%%D74==''$(++qA%a+++++++r   c                     t          j        d                              dd          } | |dz             }d}t          j        t
          |          5  t          ||           d d d            d S # 1 swxY w Y   d S )Nr8  rX   r   zFCan only compare two sparse matrices, not a sparse matrix and an arrayr   )rK   re   r   rQ   rR   rS   r.   )ru   r   r   r   s       rU    test_allclose_dense_sparse_raiser    s    
	!Q""AAA
RC	z	-	-	- % %q!$$$% % % % % % % % % % % % % % % % % %s   A22A69A6c                     t           dddd            } t          j        t          d          5   | ddd           d d d            n# 1 swxY w Y   t          j        t          d          5   | dddd	           d d d            n# 1 swxY w Y   t           ddddd
d            }t          j        t          d          5   |dd           d d d            n# 1 swxY w Y   t           dddd            }t          j        t          d          5   |dd           d d d            d S # 1 swxY w Y   d S )Nr   r(  dc                    d S r  r   r   r   r(  r  s       rU   f1z=test_deprecate_positional_args_warns_for_function.<locals>.f1      r   Pass c=3 as keyword argsr   r^   rX   Pass c=3, d=4 as keyword argsr   )r   r(  r  c                    d S r  r   r  s       rU   f2z=test_deprecate_positional_args_warns_for_function.<locals>.f2  r  r   zPass b=2 as keyword argsc                    d S r  r   r  s       rU   f3z=test_deprecate_positional_args_warns_for_function.<locals>.f3  r  r   )r   r6   rQ   r  FutureWarning)r  r  r  s      rU   1test_deprecate_positional_args_warns_for_functionr    s   1       
m+F	G	G	G  
1a               
m+K	L	L	L  
1aA                Q!q       
m+F	G	G	G  
1a                1       
m+F	G	G	G  
1a                 sG   A

AA0BBBC  C$'C$D44D8;D8c                      t          d          d             } t          j        t          d          5   | dd           d d d            d S # 1 swxY w Y   d S )Nz1.1)versionc                    d S r  r   r   r   s     rU   r  zEtest_deprecate_positional_args_warns_for_function_version.<locals>.f1  r  r   z,From version 1.1 passing these as positionalr   r   r^   r  )r  s    rU   9test_deprecate_positional_args_warns_for_function_versionr    s    ...  /. 
L
 
 
   	1a                 s   AAAc                  @    G d d          } t          j        t          d          5   | ddd           d d d            n# 1 swxY w Y   t          j        t          d          5   | dddd	           d d d            n# 1 swxY w Y    G d
 d          }t          j        t          d          5   |ddd           d d d            n# 1 swxY w Y   t          j        t          d          5   |dddd	           d d d            d S # 1 swxY w Y   d S )Nc                   ,    e Zd Zedddd            ZdS ):test_deprecate_positional_args_warns_for_class.<locals>.A1r   r  c                    d S r  r   r  r   r   r(  r  s        rU   rA  zCtest_deprecate_positional_args_warns_for_class.<locals>.A1.__init__  r  r   Nr   r  r  r6   rA  r   r   rU   A1r    s=        	#&'1 	 	 	 	 
$	#	 	 	r   r  r  r   r   r^   rX   r  r   c                   .    e Zd Zeddddd            ZdS ):test_deprecate_positional_args_warns_for_class.<locals>.A2r   r  c                    d S r  r   r  s        rU   rA  zCtest_deprecate_positional_args_warns_for_class.<locals>.A2.__init__  r  r   N)r   r   r  r   r   rU   A2r    sA        	#	!q 	 	 	 	 
$	#	 	 	r   r  )rQ   r  r  )r  r  s     rU   .test_deprecate_positional_args_warns_for_classr    s]          
 
m+F	G	G	G  
1a               
m+K	L	L	L  
1aA                     
 
m+F	G	G	G  
1a               
m+K	L	L	L  
1aA                 sG   AA
A)BBB7CCC7DDDrh  rX   c                 t   t           j                            dd          }g dt          j        g d          t	          j        g d          j        t	          j        g d          ddd d}t          |||           }| | n&t          t          |j
        d                             }d	D ]}||         ||         u sJ |d
         t          |d
         |          k    sJ t          |d         t          |d         |                     t          |d         t          |d         |                     d S )Nr   r^   )r   r^   rX   r   r   xxx)r  r   
sparse-col
sparse-row
scalar-int
scalar-strNone)r]  rh  r   )r  r  r  r  r  r   r  )rK   rL   randnr   rs   rt   r   r0   r  ranger   r   r$   r#   )rh  ry   _paramsr  indices_keys         rU   test_check_method_paramsr    sI   
	1A,,,''mLLL113mLLL11 G "!GWEEEF!-ww4agaj8I8I3J3JHA + +c{gcl*****&>^GFOXFFFFFFvgww7G(R(RSSS |nW\-BHMM    r   	sp_format)Tr   r[  r   r\  c                     t          j        d          }t          dd          }|j        j                            |          }t          ||           }| du rd} t          j        |          sJ |j	        | k    sJ t          ||           d S )Nr   rY   rX   rV  Tr   )rQ   r   r   r*  sparsefrom_spmatrixr   rs   r  r   r#   )r  r   sp_matsdfr  s        rU   "test_check_sparse_pandas_sp_formatr    s     
	X	&	&B"2q))F
,

+
+F
3
3CI666FD	;v=I%%%% 00000r   zntype1, ntype2)	)
longdoubler:  )r:  rf   )rf   double)rl   rd   )rd   long)bytern   )ushortro   )ro   uint64)rm   rk   c                     t          j        d          }|                    |j                            g d| d          |j                            g d|d          d          }t          |ddg	           d
S )zXCheck that pandas dataframes having sparse extension arrays with mixed dtypes
    works.r   r   r   r   r   r[   
fill_valuer   r   r   col1col2r   r[  rV  N)rQ   r   r*  arraysSparseArrayr   )ntype1ntype2r   r  s       rU   %test_check_pandas_sparse_mixed_dtypesr  .  s    " 
	X	&	&B	I)))))6a)PPI)))))6a)PP	
 	

 
B 5%.111111r   z ntype1, ntype2, expected_subtyper  r  r  rf   ri   rk   r  shortrl   intcrd   intpr  r   rh   longlongint_ubyterm   rn   r  uintcro   uintr  uintp	ulonglongc                 0   t          j        d          }|                    |j                            g d| d          |j                            g d|d          d          }t          |ddg	          }t          j        |j        |          sJ d S )
Nr   r  r   r  r  r  r   r[  rV  )	rQ   r   r*  r  r  r   rK   
issubdtyper[   )r  r  expected_subtyper   r  r@  s         rU   test_check_pandas_sparse_validr  I  s    . 
	X	&	&B	I)))))6a)PPI)))))6a)PP	
 	

 
B b
7
7
7C=$45555555r   constructor_name)r  re  r   	dataframe
sparse_csr
sparse_cscc                 `    g dg dg}t          ||           }t          |          dk    sJ dS )z$Check _num_features for array-likes.r   r5  rX   N)r!   r:   )r  ry   s     rU   test_num_featuresr  k  sE     
IIIA1.//Aq      r   r   r'  )FTF)r  g333333@g      @r   r   r(  )r   r  rj   r   dict)r  re  r   seriesc                    t          | |          } |dk    rd}n|dk    rd}n|}d| }t          | d          r|t          j        d          z  }nAt	          | d         t
                    r|d	z  }n t	          | d         t                    r|d
z  }t          j        t          |          5  t          |            d d d            d S # 1 swxY w Y   d S )Nr   znumpy.ndarrayr  zpandas.*Series5Unable to find the number of features from X of type r   z with shape (3,)r   z" where the samples are of type strz# where the samples are of type dictr   )r!   r   ru  rv  r   r  r  rQ   rR   r   r:   )ry   r  expected_type_namemessages       rU   &test_num_features_errors_1d_containersr  v  sI    	1.//A7"",	X	%	%--T@RTT  q' 929/000	AaD#		 977	AaD$		 988	y	0	0	0  a                 s   .CCC)r   r   Fr  )r   r  rj   r   c                     dt          |           j         }t          j        t          |          5  t          |            d d d            d S # 1 swxY w Y   d S )Nr  r   )r   r  rQ   rR   r   r:   )ry   r   s     rU    test_num_features_errors_scalarsr    s    
X$q''BV
X
XC	y	,	,	,  a                 s   AAAnamesr  )zlist-intr  default
MultiIndexc                    t          j        d          }|                    ddgddgddgg|           }t          j                    5  t          j        dt                     t          |          } d	d	d	           n# 1 swxY w Y   | J d	S )
zGet feature names with pandas dataframes without warning.

    Column names with consistent dtypes will not warn, such as int or MultiIndex.
    r   r   r^   r   r_   r   r  rI  N)rQ   r   r*  rJ  rK  rL  r  r8   )r  r   ry   s      rU   2test_get_feature_names_pandas_with_ints_no_warningr    s     
	X	&	&B
q!fq!fq!f-u==A		 	"	" & &g}555"1%%& & & & & & & & & & & & & & & =====s   *A>>BBc                      t          j        d          } d t          d          D             }|                     g dg dg|          }t	          |          }t          ||           dS )z)Get feature names with pandas dataframes.r   c                     g | ]}d | S )col_r   )r   rE  s     rU   r   z1test_get_feature_names_pandas.<locals>.<listcomp>  s    ,,,azazz,,,r   rX   r   r5  r  N)rQ   r   r  r*  r8   r$   )r   r)  ry   feature_namess       rU   test_get_feature_names_pandasr    sp    		X	&	&B,,588,,,G
iii+W==A&q))M}g.....r   zconstructor_name, minversion))pyarrowz12.0.0)r  z1.5.0)polarsz0.18.2c                     g dg dg}g d}t          || ||          }t          |          }t          ||           dS )z:Uses the dataframe exchange protocol to get feature names.)r   r   r^   )rX   rX   r   )col_0col_1col_2)columns_namer&  N)r!   r8   r$   )r  r&  r   r)  r  r  s         rU   )test_get_feature_names_dataframe_protocolr    sd     IIyyy!D)))G	W
 
 
B 'r**M}g.....r   c                  `    t          j        g dg dg          } t          |           }|J dS )z/Get feature names return None for numpy arrays.r   r5  N)rK   r   r8   )ry   r  s     rU   test_get_feature_names_numpyr    s8    
)))YYY'((Aq!!E=====r   znames, dtypesz['int', 'str']pizzaz['list', 'str']zint-strzlist-strc                 $   t          j        d          }|                    ddgddgddgg|           }t          j        d| d	          }t          j        t          |
          5  t          |          } ddd           dS # 1 swxY w Y   dS )zAGet feature names errors when the feature names have mixed dtypesr   r   r^   r   r_   r   r  z]Feature names are only supported if all input features have string names, but your input has a.   as feature name / column name types. If you want feature names to be stored and validated, you must convert them all to strings, by using X.columns = X.columns.astype(str) for example. Otherwise you can remove feature / column names from your input data, or convert them all to a non-string data type.r   N)rQ   r   r*  ru  rv  rR   r   r8   )r  r  r   ry   r   s        rU   %test_get_feature_names_invalid_dtypesr    s     
	X	&	&B
q!fq!fq!f-u==A
)	?$	? 	? 	? C 
y	,	,	, & &"1%%& & & & & & & & & & & & & & & & & &s   (BB	B	c                   $    e Zd ZddZd ZddZdS )PassthroughTransformerNc                 *    t          | |d           | S )NT)reset)rF   r  s      rU   r   zPassthroughTransformer.fit  s    dAT****r   c                     |S r  r   )r  ry   s     rU   	transformz PassthroughTransformer.transform  s    r   c                 "    t          | |          S r  )r/   )r  input_featuress     rU   get_feature_names_outz,PassthroughTransformer.get_feature_names_out  s    &t^<<<r   r  )r   r  r  r   r  r  r   r   rU   r  r    sK             = = = = = =r   r  c                     t          j        g dg          } t                                          |           }|                                }t          |g d           ddg}t          j        t          d          5  |                    |           ddd           n# 1 swxY w Y   |`	t          j        t          d          5  |                                 ddd           dS # 1 swxY w Y   dS )	z4Check behavior of check_feature_names_in for arrays.r  r  r  )x0x1x2x10r  z*input_features should have length equal tor   Nz Unable to generate feature names)
rK   r   r  r   r  r$   rQ   rR   rS   n_features_in_)ry   r  r  incorrect_len_namess       rU   test_check_feature_names_inr#    sw   
///"##A
 
"
"
&
&q
)
)C%%''Eu000111 $-	z)U	V	V	V 7 7!!"56667 7 7 7 7 7 7 7 7 7 7 7 7 7 7 		z)K	L	L	L $ $!!###$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $s$   >B  B$'B$C**C.1C.c                     t          j        d          } g d}|                     g dg|          }t                                          |          }|                                }t          |g d           t          j        t          d          5  |                    g d           ddd           dS # 1 swxY w Y   dS )	z?Check behavior of check_feature_names_in for pandas dataframes.r   r'  r  r  zinput_features is not equal tor   )r  r  x3N)	rQ   r   r*  r  r   r  r$   rR   rS   )r   r  r  r  s       rU   "test_check_feature_names_in_pandasr&  	  s
   		X	&	&BOOE	'	7	7B
 
"
"
&
&r
*
*C%%''Euooo...	z)I	J	J	J 6 6!!"4"4"45556 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6s   B::B>B>c                      d} t          j        t          |           5  t          t	                      d           ddd           dS # 1 swxY w Y   dS )z@Check the error message when passing an unknown response method.zKRandomForestRegressor has none of the following attributes: unknown_method.r   unknown_methodN)rQ   rR   r  r3   r
   )r   s    rU   )test_check_response_method_unknown_methodr)    s     	V  
~W	5	5	5 J J4668HIIIJ J J J J J J J J J J J J J J J J Js   AAAresponse_method)decision_functionpredict_probapredictc                     d|  d}t          j        t          |          5  t          t	                      |            ddd           dS # 1 swxY w Y   dS )zUCheck the error message when a response method is not supported by the
    estimator.z7EstimatorWithFit has none of the following attributes: .r   N)rQ   rR   r  r3   r   )r*  r   s     rU   8test_check_response_method_not_supported_response_methodr0     s     	U/TTT  
~W	5	5	5 D D/11?CCCD D D D D D D D D D D D D D D D D Ds   AAAc                     dg} t          |           }d}ddg}dd                    |           d}t          j        t          |          5   t          ||          |           d	d	d	           n# 1 swxY w Y   ddg} t          ||          |          }|dk    sJ ddg} t          |           }g d
} t          ||          |          }|dk    sJ d	S )z0Check that we can pass a list of ordered method.r,  mocking_datar+  r-  zD_MockEstimatorOnOffPrediction has none of the following attributes: z, r/  r   N)r+  r-  r,  )r   joinrQ   rR   r  r3   )method_implementedmy_estimatorry   r*  r   method_name_predictings         rU   #test_check_response_method_list_strr7  -  s|   )*01CDDLA +I6O	)99_%%	) 	) 	)  
~W	5	5	5 A A=|_==a@@@A A A A A A A A A A A A A A A +O<OR3L/RRSTUU!_4444 *9501CDDLGGGOR3L/RRSTUU!Y......s   A33A7:A7c                      t          d          } t          |                     ddg          d          }t          j        ddg          }|j        |j        k    sJ t          ||           dS )zRegression test for gh-25145r   TFr   N)r   r   r   rK   r   r[   r$   )r   r  expecteds      rU   #test_boolean_series_remains_booleanr:  J  so    	h		B
biiu..%
@
@
@Cxu&&H9&&&&sH%%%%%r   input_values)r   r   r   r   r   r   c                     t          d          }|                    | d          }t          |dddd          }t          j        |j        j        t          j                  sJ t          ||            dS )zpCheck pandas array with extensions dtypes returns a numeric ndarray.

    Non-regression test for gh-25637.
    r   Int32rZ   NF)r[   r   r   r   )	r   r   r   rK   r  r[   rF  floatingr"   )r;  r   input_seriesr  s       rU   !test_pandas_array_returns_ndarrayr@  T  s     
h		B88L888L  F =*BK88888FL)))))r   c                     t          j        d          } |                     | j        ddgd| j        dgg| j                  }t          d          5  t          j        t          d	          5  t          |           d
d
d
           n# 1 swxY w Y   d
d
d
           n# 1 swxY w Y   |                     | j	        ddgd| j	        dgg| j                  }t          d          5  t          j        t          d	          5  t          |           d
d
d
           n# 1 swxY w Y   d
d
d
           d
S # 1 swxY w Y   d
S )z9Checks that Array API arrays checks non-finite correctly.array_api_strictr   r   rX   rZ   Tr  r   r   Nzinfinity or a value too large)
rQ   r   r   rv   rf   r   rR   rS   r   r  )r  X_nanX_infs      rU   )test_check_array_array_api_has_non_finiterE  g  s<    
	/	0	0BJJABFA7rzJJJE	4	0	0	0  ]:-BCCC 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	               JJABFA7rzJJJE	4	0	0	0  ]:-LMMM 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	                 sl   B"/B?B"B	B"B	B""B&)B&+D;D#D;#D'	'D;*D'	+D;;D?D?zextension_dtype, regular_dtype))r  rj   )r/  rh   )r$  ri   )r  rp   include_objectc                    t          j        d          }|                    |                    g d|          |                    g dd          d          }|r|                    g dd          |d	<   |                    |d
                             |                     }t          |d          }t          |d          }t          ||           dS )zKCheck pandas extension arrays give the same result as non-extension arrays.r   )r   r   r   r   rZ   )r8  r   r7  r   rh   )r   r(  r  rp   r   r   )r   N)rQ   r   r*  r   assignrg   r   r$   )extension_dtyperegular_dtyperF  r   	X_regularX_extensionX_regular_checkedX_extension_checkeds           rU   $test_check_array_multiple_extensionsrO  w  s     
	X	&	&B<<<}==<<<w77	
 	
 I  I#7#7#7xHH	#""Ys^%:%:?%K%K"LLK#IT:::%k>>>(*=>>>>>r   c                      t          j        d          } |                     g dg dd          }t          |          dk    sJ dS )zDUse the DataFrame interchange protocol to get n_samples from polars.r  r   r5  r  rX   N)rQ   r   r*  r;   )plr  s     rU   #test_num_samples_dataframe_protocolrR    sR    		X	&	&B	IIIIII66	7	7Bq      r   r   output_format)r   r[  r   c                 >    | ddgddggt           j                  }t          |d          r*|j                            t           j                  |_        nt          |d          r:t          |d          r*|j                            t           j                  |_        nrt          |d          rbt          |d          rR|j                            t           j                  |_        |j                            t           j                  |_        t          ||	          }|d
k    r:|j        j
        t           j        k    sJ |j        j
        t           j        k    sJ dS |j        j
        t           j        k    sJ |j        j
        t           j        k    sJ dS )zGCheck the consistency of the indices dtype with sparse matrices/arrays.r   r   rZ   offsetsrf  rg  rh  ri  rV  r   N)rK   ri   r   rU  rg   rd   rf  rh  ri  r   r[   rg  )r   rS  ry   r   s       rU   1test_check_array_dia_to_int32_indexed_csr_csc_coorV    sq    	1a&1a&)<<<A q) -I$$RX..			E		 -wq%00 -RX&&	I		 -71h#7#7 -I$$RX..	8??28,,A];;;I}"bh....}"bh...... &"(2222%111111r   sequencec                     t          |           }t          |t          j                  sJ |j        j        dk    sJ |j        dk    sJ d S )NOr   )r<   r   rK   r   r[   rF  r   )rW  outs     rU   test_to_object_arrayr[    sO    
8
$
$Cc2:&&&&&9>S    8q======r   c                     dg dfdg dfdt          j        d          dz  fdg dfdg d	fdd
gdgdggfdg dg dgfdg dgfdd
d
gddgdd
ggfddd
gddgdd
ggfdg dgfdt          j        d                              d          fg} | D ]y\  }}|dv r0t          t	          |          t          j        |                     9t          j        t                    5  t	          |           d d d            n# 1 swxY w Y   zd S )Nbinary)spameggr^  )r   r   r   r   
continuousrY   g      4@
multiclassr   )r   r   r^   r^   r   r   r^   rX   zmultilabel-indicatorr  )r   r   r   zmulticlass-multioutputr_   r   zcontinuous-multioutput   )r   rX   )r]  ra  r`  )	rK   re   r   r$   rD   r   rQ   rR   rS   )EXAMPLESy_typer   s      rU   test_column_or_1dre    s   	***+	<<< 	ry}}t+,	yyy!	'	aS1#'	)))YYY!78	!III;/	!QFQFQF#;<	!QFQFQF#;<	!III;/	!29R==#8#8#A#ABH     	;;;|A<<<<z**    Q                             	   s   !C==D	D	c                  :   t           j                            d          } t          | dd          }t          j        ||           sJ |j        j        sJ d| j        _        t          | dd          }t          j        ||           rJ |j        j        sJ dS )zyCheck the behavior of check_array when a writeable array is requested
    without copy if possible, on numpy arrays.
    r   sizeFTr]   force_writeableN)rK   rL   uniformr   r  r   	writeable)ry   rZ  s     rU   test_check_array_writeable_nprm    s     		x((A
aeT
:
:
:CsA&&&&&9AG
aeT
:
:
:C"3*****9r   c                  f   t           j                            d          } t          | d          }t	          |dd          }t          j        ||          sJ |j        j        sJ t          | d          }t	          |dd          }t          j        ||          rJ |j        j        sJ d	S )
a  Check the behavior of check_array when a writeable array is requested
    without copy if possible, on a memory-map.

    A common situation is when a meta-estimators run in parallel using multiprocessing
    with joblib, which creates read-only memory-maps of large arrays.
    r   rg  zw+r  FTri  r  N)rK   rL   rk  r%   r   r  r   rl  )ry   mmaprZ  s      rU   test_check_array_writeable_mmaprp    s     		x((A$Q$777D
d
=
=
=CsD)))))9$Q#666D
d
=
=
=C"3-----9r   c                     t          j        d          } t          j                            d          }|                     |d          }t          |dd          }t          j        ||          sJ |j        j	        sJ d|j        _	        |                     |d          }t          |dd          }t          j        ||          rJ |j        j	        sJ dS )	zxCheck the behavior of check_array when a writeable array is requested
    without copy if possible, on a dataframe.
    r   r   rg  Fr\   Tri  N)
rQ   r   rK   rL   rk  r*  r   r  r   rl  )r   ry   r  rZ  s       rU   test_check_array_writeable_dfrr  	  s     
	X	&	&B
	x((A	ae	$	$B
bud
;
;
;CsB'''''9AG	ae	$	$B
bud
;
;
;C"3+++++9r   c                  V   t          j        g dg dg          } t          d          5  t          j        t	          | d                    sJ t          j        t                    5  t	          |            d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr  r  Tr  rV  )rs   r   r   r  r   rQ   rR   r   )X_sps    rU   8test_check_array_on_sparse_inputs_with_array_api_enabledru  	  s)   <III.//D	4	0	0	0  {;t4@@@AAAAA]9%% 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	                 s5   ?B*B:BB
	
BB
	BB"%B"ry   r   expected_error_messagezLFound array with dim 3, while dim <= 2 is required by RandomForestRegressor.z3Found array with dim 3, while dim <= 2 is required.c                     t          j        t          |          5  t          | |           d d d            d S # 1 swxY w Y   d S )Nr   r9  r  rv  s      rU    test_check_array_allow_nd_errorsry  #	  s    " 
z)?	@	@	@ , ,A++++, , , , , , , , , , , , , , , , , ,s   ;??)__doc__rT  ru  rJ  	itertoolsr   operatorr   tempfiler   numpyrK   rQ   scipy.sparser  rs   r   r  sklearn._configr   sklearn.baser   sklearn.datasetsr	   sklearn.ensembler
   sklearn.exceptionsr   r   sklearn.linear_modelr   (sklearn.metrics.tests.test_score_objectsr   sklearn.neighborsr   sklearn.random_projectionr   sklearn.svmr   sklearn.utilsr   r   r   r   r   r   sklearn.utils._array_apir   r   r   r   sklearn.utils._mockingr   r   sklearn.utils._testingr   r   r    r!   r"   r#   r$   r%   r&   sklearn.utils.estimator_checksr'   sklearn.utils.fixesr(   r)   r*   r+   r,   sklearn.utils.validationr-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rV   r   markparametrizerL   r   r   r   r   r  rv   r   r   r   r   r   r   r   rp   r   r   filterwarningsr  r  rf   ri   r-  r3  r>  rC  rG  rT  rX  rZ  fixturerk  rn  rp  ry  r  r  r  r  r  r  r  r  re  r  r  r  r  r  r  r  r  r  r  r
  r  r  r   rS   r  r4  rt   r  r  r  r  
dia_matrixr6  r:  rK  rW  r   r   rU  Integralrj   r   rg  _psd_cases_validvalueskeysrr  _psd_cases_invalidrw  r{  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r>  integerunsignedintegerr  r  r  r  r  r  r  r  r  r  r  r#  r&  r)  r0  r7  r:  r@  rE  rO  rR  rV  r[  re  rm  rp  rr  ru  ry  r   r   rU   <module>r     s   * *  				              ' ' ' ' ' '                   * * * * * * & & & & & & ' ' ' ' ' ' 2 2 2 2 2 2 F F F F F F F F . . . . . . F E E E E E 2 2 2 2 2 2 ; ; ; ; ; ;                                       
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 7 6 6 6 6 6                                                                    <0 0 0$'% '% '%T ")

7
#
#YRYr1U%C%C%C	D 1 1 1G G G   , , ,& fe_rv{+bfe_=  BJ#>??/ / @?	 
/ 5	T45	d78	$(OP	k#>?	T/0	d23	d23F?		
 
Q,- & BJ#>??
 
 @?' (
 'B'B'BCCBJ#>??%1 %1 @? DC%1P
; 
; 
;  BHq"&k]##!	

 BHq"&k]##!	

 BHq"&k]##C	
 
Arv;-v	.	.	.0UV $ ,tUm<<G G =<% &G) ) ) QRRA
 A
 SRA
H 
sc3Z 3*sCj)5553*sCj)555
d|$4,t-T:::	 	( (	 	( JJJ  
*bj	!2:.	RZ 	BJ / /  /:% % %*"G "G "GJ5 5 5= = =() () ()V9 9 9>/ / / 333444  54,G G G
L L L<% <% <%~' ' 'T    0  0  0F' ' '* * *!( !( !(H"B "B "BJ 
ZZ]]D%(.I.I.I   2 2 2A A A(  --//'   
  
(
+ 
+ 
+  	E 	E 	E rz2:&
D)D  ':;;8 8 <; 848 8 8&9 9 9       
	 	 	 	 	 	 	 	  6 $//4 4 0/4 U D&94%@AA	
 D&94%@AA	
 ^R*=t)DEE O	
 D&94%@AA 	
 D&94%@AA	
 D&8$%?@@	
M-\	 	 	a  8 8r+ +s8 8r+< 








	 
" 
" 
"	; 	; 	;, , ,( nnn--  .-  P IIJJ	
 LINOO	
 ILMM	
 DMIQRR	
 J677	
 J677	
 J677	
 J677	
 !JM 	
 J# 	
 J# 	
Cmp pb9 9cp pb9& !Q(($3!1a&))828QF+;+;T2F!QV	 %hbh1v&6&68OQST!U2:...!Qrz***K	" 	!VBJ///!Qrz***K	" 	!QH	-  > .D		 	 	"	"##""$$%%   
 *T5M::5 5 ;: 54 	9 	7 	4 	$bj1114  	$rz2224 +  :  D		"	"	$	$%%$$&&''   
( ( 
( I  I  IF- - - "$M$M$O$O ( ( ( QC!Q"a)))\\\#RSS; ; TS; "--//'   
 QC!Q"a)))\\\#RSS< < TS < IIIuq"g#>??< < @?< "--//'   
 IIIuq"g#>??	= 	= @? 	= RXr}bm$LMM( ( NM( RXr}bm$LMM, , NM, R]BM$BCC% % DC%  6    0 TAq6N33  430 &H&H&HII1 1 JI1$ 
 
 
 
2 
2 
2 &	<-	9bk*	9bk*	$	'2:&	"*%	$	
#	*bj)	$	'2-.	8R/0	(B./	2-.	+r12 (6 6) (6 GGG ! !	 ! 		
qC8c1X& 	0//  
 
 +-Q-Q-QRR  SR
 
* 2228W8W8WXX  YX 	T%%((^^UU1XXtsCj3*%=>666   
  
/ / / "III 	/ 	/	 	/   
q#$
C:	 12 
J   & & &"	= 	= 	= 	= 	=] 	= 	= 	=$ $ $$6 6 6J J J HHH D D D/ / /:& & & 1aAq"&*ACUCUCU)VWW* * XW*$ )  )( $    )D%=99? ? :9 ?*! ! ! ^#n4~E  *?*?*?@@2 2 A@	 
2, xrx{{HBHQKK&@Aq6Aq6BR%STT  UT     0  &  ,  . )  )( 000 BH1v1v&!Q!Q(89::!!##%	
 BH1v1v&!Q!Q(89::A	
  , ,!  , , ,r   