o
    tBh                     @   s  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
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 ddlmZ ddlmZ ddlmZ ddlmZ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& ddl'm(Z( ddl)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0 ddlm1Z1 ddl2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZD ddlEmFZF ddlGZGddlHmIZImJZJ ddlmKZK e
jLMde
jLMd d!d" ZNe
jLOd#ejPPd$eQd%d&R gd'd( ZSe
jLMde
jLMd d)d* ZTd+d, ZUd-d. ZVe
jLOd/ejWd0fejXd1fejXd0fge
jLOd2ejYejZgd3d4 Z[e
jLOd5ejWd6d7d8fejWd#d7d9fejWd:d7d;fejWd#d1d9fejXd6d7d<fejXd#d7d=fejXd>d7d?fejXd6d@dAfejXd6dBd<fg	e
jLOd2ejYejZgdCdD Z\e
jLOdEg dFe
jLOd2ejYejZgdGdH Z]dIdJ Z^e
jLOdKe_dBejXggdLfe_dBejXggdLfe_dBejWggdMfej_dBejXgge`dNdOfge
jLOdPd7d0gdQdR ZaedSdT Zbe
jLOd#dUdVgdWdXggej_dUdVgdWdXggdYdNej_dUdVgdWdXggdZdNd[d\gd]d^ggej_d[d\gd]d^ggd_dNgd`da Zce
jLOdbg dce
jLOddejdejegejdfejeejefdeejefgdfdg Zfdhdi Zgdjdk Zhdldm Zidndo Zjdpdq Zkdrds Zle
jmg dtdudvdw Zndxdy Zodzd{ Zpd|d} Zqd~d Zrdd Zsdd Ztdd Zudd Zvdd Zwe
jLjOde	dexeygg dddd Zzdd Z{dd Z|dd Z}dd Z~e
jLOdejeejdfejeddefe
jLOdddd Zdd Zdd ZG dd dZG dd dZdd Ze
jLOdd7d0gdd Ze
jLOd2ejYejZejejejejejejgdd Zdd Zdd Ze
jLOdg ddd Ze
jLOddBded&ddedfddejd&ddedfddejd&ddedfdBdeefd&ddedfdBded&ddedfdded&ddedfd&ded&ddedfdded&ddedŃfdded&ddedȃfddedddedʃfdded&dded̃fgdd΄ Zde_dBd&gdd6fe_dBd&ge_dBd&gdd6fde_ddgeJdfde_ddgeJd6fej_dBdgejddNej_dBdgejddNeJdfej_dBdgejedNej_dBdgejedNeJdfde_ddgeJdfdٜZe
jLjOdexe exe de
jLOdd7d0gdd݄ Zdedfdedfdedfej_ddgejddNedfej_ddgejedNedfdZe
jLjOdexe exe ddd Zdd Ze
jLOdej_ejZejgdd Ze
jLOdej_ejZejgdd Ze
jLOdejZejgdd Zdd Zdd Zdd Ze
jLOdddBdggdd Ze
jLOdg d dd Ze
jLOdg ddd Ze
jLOddd	ejfd
dejfddejfddejfddejfddejfddejfddejfddejfddejfddejfddejfdd ejfd!d"ejfd#d$ejfd%d&ejfgd'd( Ze
jLOd)g d*d+d, Ze
jLjOd#g d-g d.g d/g d0d1dBid2d&id3diggg d4de
jLOd)g d5d6d7 Ze
jLjOd#g d8g d9dd:d; Ze
jLMd d<d= Ze
jLjOd>exed&ed&dd1d2gd3d?gggg d@ddAdB ZdCdD ZdEdF Ze
jLjOdGd1dBgdHfdId1d2ggdJfgdKdLgddMdN ZG dOdP dPeFZdQdR ZdSdT ZdS (U  z$Tests for input validation functions    N)NamedTemporaryFile)product)
itemgetter)importorskip)assert_no_warnings)ignore_warnings)SkipTest)assert_array_equal)assert_allclose_dense_sparse)assert_allclose)_convert_container)as_float_arraycheck_arraycheck_symmetric)	check_X_y)
deprecated)MockDataFrame)parse_version)_NotAnArray)_sparse_random_matrix)ARDRegression)KNeighborsClassifier)RandomForestRegressor)SVR)
make_blobs)_safe_indexing)has_fit_parametercheck_is_fittedcheck_consistent_lengthassert_all_finitecheck_memorycheck_non_negative_num_samplescheck_scalar_check_psd_eigenvalues_check_y_deprecate_positional_args_check_sample_weight_allclose_dense_sparse_num_featuresFLOAT_DTYPES_get_feature_names_check_feature_names_in_check_fit_params)BaseEstimator)NotFittedErrorPositiveSpectrumWarning)
TempMemmapz9ignore:np.matrix usage is deprecated in 1.0:FutureWarningz4ignore:the matrix subclass:PendingDeprecationWarningc                  C   s  t jdt jd} | t jdt jd } t| dd}|jt jks J | t j} t| dd}t| dd| us6J |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sbJ qO| t} t| dd}|jt j	ksvJ t jdt jd} t| dd| u sJ t | } t t| ddsJ t t dtt d tddd	d
 g}|D ]}t|dd}t j|d< t | rJ qd S )N)   
   dtyper3   FcopyT)r2         皙?)densityr   r   )nponesint32aranger   r5   float32astypeint64float64boolint8int16uint8uint16uint32objectasfortranarray	isfortranmatrixsp
csc_matrixtoarrayr   nanisnanany)XX2tested_dtypesr5   matricesMN r[   z/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/sklearn/utils/tests/test_validation.pytest_as_float_arrayA   s:   



r]   rU   r3   r8   r3   r8   c                 C   s.   t j| d< t j| d< t| dd}t||  d S )N)r9   r   )      	allow-nanforce_all_finite)r=   rR   r   r
   )rU   X_convertedr[   r[   r\   test_as_float_array_nann   s   

re   c                  C   s^   t ddd} tt| t jrJ ttt | t jr J ttt| t jr-J d S )N   r2      )r=   r@   reshape
isinstancer   rN   rO   rP   rU   r[   r[   r\   test_np_matrixw   s   rk   c                  C   s   dd } t dd:}tj|dtjd}d|d d < ttj| fD ]}||}d|d d < t| |  d|d d < qW d    d S 1 sFw   Y  d S )	Nc                 S   s   t | ddS )NFr6   )r   )xr[   r[   r\   <lambda>   s    ztest_memmap.<locals>.<lambda>zsklearn-test)prefix)r3   r3   )shaper5   r   r`   )r   r=   memmaprA   r   asarrayr	   ravel)asflttmprY   frU   r[   r[   r\   test_memmap   s   "rv   c                  C   s   t d} | | jfD ]+}dD ]&}t|d|d}|jd sJ t|d|d}|jd s,J |r4||us4J qq
t| } | jd d d | _| jjd rLJ d S )	N)r3   r9   )TFC)orderr7   C_CONTIGUOUSFF_CONTIGUOUS)r=   r>   Tr   flagsrO   
csr_matrixdata)rU   Ar7   Br[   r[   r\   test_ordering   s   

r   zvalue, force_all_finiteFra   retypec                 C   s@   |t dddt}| |d< t||dd}t|| d S )Nrg   r8   r<   T)rc   accept_sparse)r=   r@   rh   rB   floatr   r
   )valuerc   r   rU   	X_checkedr[   r[   r\   'test_check_array_force_all_finite_valid   s   r   z.value, input_name, force_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-infz0force_all_finite should be a bool or "allow-nan"r`   c                 C   sj   |t dddt j}| |d< tjt|d t|||dd W d    d S 1 s.w   Y  d S )Nrg   r8   r<   matchT)
input_namerc   r   )	r=   r@   rh   rB   rD   pytestraises
ValueErrorr   )r   r   rc   	match_msgr   rU   r[   r[   r\   (test_check_array_force_all_finiteinvalid   s   "r   r   )rU   r   r   c                 C   s*  |t dddt j}t j|d< t }d|jj d}t	j
td|  dd}t||| d	d
 W d    n1 s=w   Y  | dkrQ||jjd v sPJ n
||jjd vs[J | dkrt	j
td|  dd}t |t |jd  W d    n1 sw   Y  ||jjd v sJ d S d S )Nrg   r8   r<   
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   rU   r   )r=   r@   rh   rB   rD   rR   r   	__class____name__r   r   r   r   r   argsfitr>   ro   )r   r   r   r   extended_msgctxr[   r[   r\   0test_check_array_links_to_imputer_doc_only_for_X   s.   
r   c                  C   s   t jddt jggtdj} t| d dd}| |u sJ t| d dd}| |u s'J tjtdd t| d d	d W d    d S 1 sAw   Y  d S )
Nabr4   ra   r5   rc   Fr   r   T)	r=   arrayrR   rK   r}   r   r   r   r   )rU   r   r[   r[   r\   (test_check_array_force_all_finite_object   s   "r   z
X, err_msgzInput contains NaN.z5Input contains infinity or a value too large for.*intr4   z#cannot convert float NaN to integerrc   c                 C   sB   t jt|d t| t|d W d    d S 1 sw   Y  d S )Nr   r   )r   r   r   r   int)rU   err_msgrc   r[   r[   r\   7test_check_array_force_all_finite_object_unsafe_casting	  s   "r   c               	   C   s  ddgddgg} t | }tt t| W d    n1 s!w   Y  tg ddd}|jdks5J tjtdd	 tg dd
d W d    n1 sOw   Y  tjtdd	 tdd
d W d    n1 slw   Y  t	d
ddd}tt t| W d    n1 sw   Y  t|d
d t	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| |||d}|d ur|j|ksJ n|j| jksJ |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 q| j|jkrQ|jd | jd krQ|jd | jd krQ| |u sQJ qt |}| }| }|t}|t}|||||g}ddgddgg}t||	||D ]\} }}}tjd
d}t| |||d}W d    n	1 sw   Y  |tu st | rt|rt|d j}ddg}||v sJ n	t|dksJ |d ur|j|ksJ n	|j| jksJ | j|v r| j|jksJ n
|j|d ksJ |r| |usJ q| j|jkr"| j|jkr"| |u s"J qtddgddgg}t |tj!s7J tt t|"  W d    n	1 sNw   Y  t|" d
d t#|}t|}t |tj!slJ d S )Nr`   r8   r2   rg   )r   r`   r8   F	ensure_2dz'Expected 2D array, got 1D array insteadr   Tz+Expected 2D array, got scalar array insteadr3      allow_ndrw   rz   )rw   rz   N)r5   rx   r7   ry   r{   csrcoodok)recordr5   r   r7   r   z0object dtype is not supported by sparse matricesz-Can't check dok sparse matrix for nan or inf.)$rO   r   r   r   	TypeErrorr   ndimr   r=   r@   rh   r7   rB   r   r   r?   rA   rE   rK   r   r5   r~   rP   tocootodokwarningscatch_warningsisspmatrix_doklenstrmessageformatri   ndarraytolistr   )rU   X_csrX_arrayX_ndimX_CX_FX_intX_floatXsdtypesorderscopysr5   rx   r7   r   X_cscX_cooX_dokaccept_sparsesr   wr   messagesX_dense
X_no_arrayresultr[   r[   r\   test_check_array%  s   










 
r   1234US   1   2   3   4V1c                 C   sD   d}t jt|d t| dd W d   dS 1 s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   numericr4   Nr   r   r   r   )rU   expected_msgr[   r[   r\   test_check_array_numeric_error  s   "r   pd_dtype)Int8Int16UInt8UInt16Float32Float64zdtype, expected_dtyper   c                 C   s  t d}| dv rt jddd}tdddtjtjgtjtjdd	d
gg dgj}|j|| g dd}|d d|d< t|d|d}t	|| |j
|ksOJ t|d|d}t	|| |j
|ksbJ d}t jt|d t|dd W d    d S 1 s}w   Y  d S )Npandas>   r   r   z1.2
minversionr`   r8   r2   r   rg   r_   )r`   r8   r2   rg   r9   r   r   c)r5   columnsr   r   ra   )rc   r5   Fr   r   Trb   )r   r   r=   r   rR   r}   	DataFramerB   r   r   r5   r   r   )r   r5   expected_dtypepdX_nprU   r   msgr[   r[   r\   "test_check_array_pandas_na_support  s(   
(

"r   c                  C   s  t d} tjg dg dg dgtjd}| |}t|jtjks%J t|tdjtjks1J |j	d d df 
tj|j	d d df< t|jtjtjtjf t|jtjks[J t|tdjtjksgJ |j	d d df 
tj|j	d d df< t|jtjksJ t|tdjtjksJ |j	d d df 
tj|j	d d df< t|jtjksJ t|tdjtjksJ |
tj}t|jtjksJ t|tdjtjksJ | d	| g di}t|jtjksJ t|tdjtjksJ d S )
Nr   r`   r8   r2   rg   r9   r_      r   	   r4   r   r`   r8   cat_col)r   r   r=   r   rA   r   r   r5   r*   ilocrB   float16r	   r   rG   rD   CategoricalrC   )r   rU   X_dfcat_dfr[   r[   r\   %test_check_array_pandas_dtype_casting  s*   
"
(((r   c                  C   sj   t ddgddgddgddgg} t| }t|}|j| jks!J t|t jd}|jt t jks3J d S )Ng?gffffff?g333333?g      ?g?r:   r4   )r=   r   r   r   r5   rA   )arrmock_dfchecked_arrr[   r[   r\   "test_check_array_on_mock_dataframe  s   "r  c                  C   sF   g dg dg dg} t | jjdksJ t | ddjjdks!J d S )Nr   r   r   iFr   )r   r5   kindrj   r[   r[   r\    test_check_array_dtype_stability   s   r  c            
      C   s\  g dg dg dg} t j| t jd}t j| t jd}t|}t|}tj|t jd}||g}|||g}|D ]}tt	|t j
dd}	|	jt j
ksKJ q8|D ]9}tt	|t j
t jgdd}	|	jt jksdJ |	|u sjJ tt	|t j
t jgddgdd	}	|	jt jksJ |	|usJ qNtt	|t j
t jgddgd
d	}	|	jt jksJ |	|usJ |	jdksJ d S )Nr   r   r   r4   T)r5   r   r   r   r   F)r=   rq   rA   rC   rO   r   rP   r?   r   r   rD   r5   r   )

X_int_list	X_float32X_int64X_csr_float32X_csc_float32X_csc_int32integer_datafloat32_datarU   r   r[   r[   r\   test_check_array_dtype_warning  sL   





r  c                  C   sV  ddgddgg} t | }t }d}tjt|d t|dd W d    n1 s*w   Y  d	}tjt|d t||d W d    n1 sIw   Y  d
}tjt|d t|g d W d    n1 shw   Y  tjt|d t|dd W d    n1 sw   Y  tjtdd t||gd W d    d S 1 sw   Y  d S )Nr`   r8   r2   rg   zlA sparse matrix was passed, but dense data is required. Use X.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   )rO   r   r   r   r   r   r   r   )rU   r   invalid_typer   r[   r[   r\   -test_check_array_accept_sparse_type_exception3  s0   
"r  c                  C   sP   ddgddgg} t | }t|dd t|dd t|dgd t|dd d S )	Nr`   r8   r2   rg   Tr  r   )r   )rO   r   r   )rU   r   r[   r[   r\   +test_check_array_accept_sparse_no_exceptionR  s   
r  )r   cscr   bsr)paramsc                 c   sJ    t jdd| jd}dD ]}t||rt||t||d q|V  d S )N   r3   )r   )indicesindptrrowcolrC   )rO   randparamhasattrsetattrgetattrrB   )requestrU   attrr[   r[   r\   X_64bit\  s   

r$  c                 C   s   t | ddd d S )NT)accept_large_sparser   )r   )r$  r[   r[   r\   1test_check_array_accept_large_sparse_no_exceptione  s   r&  c                 C   sF   d}t jt|d t| ddd W d    d S 1 sw   Y  d S )NzQOnly sparse matrices with 32-bit integer indices are accepted. Got int64 indices.r   TF)r   r%  r   )r$  r   r[   r[   r\   4test_check_array_accept_large_sparse_raise_exceptionj  s
   "r'  c                  C   st  d} t jt| d tg g W d    n1 sw   Y  d} t jt| d tg dd W d    n1 s8w   Y  d} t jt| d tddd W d    n1 sWw   Y  td}td	}d
} t jt| d t||dd W d    n1 sw   Y  t jt| d t||ddd W d    n1 sw   Y  td}td}d} t jt| d t||dd W d    n1 sw   Y  t jt| d t||ddd W d    n1 sw   Y  td	dd}td}d} t jt| d t|| W d    n	1 sw   Y  td}td}t||d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   zDSingleton array array\(42\) cannot be considered a valid collection.*   )r`   r3   r`   zC1 sample\(s\) \(shape=\(1, 10\)\) while a minimum of 2 is required.r8   )ensure_min_samples)r)  r   r^   zD2 feature\(s\) \(shape=\(10, 2\)\) while a minimum of 3 is required.r2   )ensure_min_featuresT)r*  r   r   r3   zD0 feature\(s\) \(shape=\(10, 0\)\) while a minimum of 1 is required.)r3   r      r+  r   )r   r   r   r   r   r=   r>   r   emptyrh   r	   )r   rU   r   r   	y_checkedr[   r[   r\   2test_check_array_min_samples_and_features_messagest  sR   







r.  c                  C   sZ  t g dg dg} tjtdd t|  W d    n1 s!w   Y  g dg dg} tjtdd t|  W d    n1 sDw   Y  d} tjtdd t|  W d    n1 saw   Y  t g dt g dg} tjtdd t|  W d    n1 sw   Y  t g dt g df} tjtdd t|  W d    n1 sw   Y  tt g dg dg} tjtdd t|  W d    n1 sw   Y  tddgddgg} tjtdd t|  W d    n	1 sw   Y  t g d}tjtdd t	| W d    d S 1 s&w   Y  d S )	N      ?       @      @      @      @      @       @      @      @      @      @      @zComplex data not supportedr   )r/  r3  r   r0  )r0  r1  r2  r4  r5  r6  )
r=   r   r   r   r   r   r   rO   
coo_matrixr%   )rU   r   r[   r[   r\   #test_check_array_complex_data_error  s@   







$r8  c                  C   s^   t tdrJ t tdsJ t tdsJ t t dsJ G dd d} t | ds-J dd S )Nr   c                   @   s   e Zd ZeddddZdS )z@test_has_fit_parameter.<locals>.TestClassWithDeprecatedFitMethodz7Deprecated for the purpose of testing has_fit_parameterNc                 S      d S Nr[   )selfrU   r   r   r[   r[   r\   r        zDtest_has_fit_parameter.<locals>.TestClassWithDeprecatedFitMethod.fitr:  )r   
__module____qualname__r   r   r[   r[   r[   r\    TestClassWithDeprecatedFitMethod  s    r?  z=has_fit_parameter fails for class with deprecated fit method.)r   r   r   r   )r?  r[   r[   r\   test_has_fit_parameter  s   r@  c               	   C   s\  t ddgddgg} t d}t ddgddgg}|t|t|t|t|t|t	|d}t
t t| W d    n1 sKw   Y  | D ]W\}}t
t t| W d    n1 slw   Y  t
t t|dd W d    n1 sw   Y  t|dd}t|r|j|ksJ t| |  qTt||  qTd S )	Nr   r`   r8   )denser   r   r  r   lilr  T)raise_exceptionF)raise_warning)r=   r   r>   rO   
dok_matrixr   rP   r7  
lil_matrix
bsr_matrixr   r   r   r   itemswarnsUserWarningissparser   r	   rQ   )arr_symarr_badarr_asymtest_arrays
arr_formatr  outputr[   r[   r\   test_check_symmetric  s6   



rR  c                  C   sV   G dd dt } tt t|   W d    n1 sw   Y  t|    d S )Nc                   @      e Zd Zdd Zdd ZdS )z6test_check_is_fitted_with_is_fitted.<locals>.Estimatorc                 [   s
   d| _ | S )NT)
_is_fitted)r;  kwargsr[   r[   r\   r     s   z:test_check_is_fitted_with_is_fitted.<locals>.Estimator.fitc                 S   s   t | do| jS )NrT  )r  rT  r;  r[   r[   r\   __sklearn_is_fitted__  s   zLtest_check_is_fitted_with_is_fitted.<locals>.Estimator.__sklearn_is_fitted__N)r   r=  r>  r   rW  r[   r[   r[   r\   	Estimator  s    rX  )r.   r   r   r/   r   r   )rX  r[   r[   r\   #test_check_is_fitted_with_is_fitted  s
   rY  c               
   C   s  t t tt W d    n1 sw   Y  t t td W d    n1 s-w   Y  t } t }z4t t t|  W d    n1 sMw   Y  t t t| W d    n1 sfw   Y  W n tyw   J dw zt| dd W n ty } zt|dksJ W Y d }~nd }~ww zt|dd W n t	y } zt|dksJ W Y d }~nd }~ww | j
t   |j
t   t| d u sJ t|d u sJ d S )	Nr   Fz&check_is_fitted failed with ValueErrorz!Random message %(name)s, %(name)s)r   z+Random message ARDRegression, ARDRegressionz"Another message %(name)s, %(name)szAnother message SVR, SVR)r   r   r   r   r   r   r/   r   r   AttributeErrorr   r   )ardsvrer[   r[   r\   test_check_is_fitted  sF   



r^  c                  C   s  G dd d} d}|  }t jt|d t|ddgd W d    n1 s&w   Y  t jt|d t|ddgtd W d    n1 sFw   Y  t jt|d t|ddgtd W d    n1 sfw   Y  d	|_t jt|d t|ddgd W d    n1 sw   Y  t jt|d t|ddgtd W d    n1 sw   Y  t|ddgtd d
|_t|ddgd t|ddgtd t|ddgtd d S )Nc                   @      e Zd Zdd ZdS )z4test_check_is_fitted_attributes.<locals>.MyEstimatorc                 S   s   | S r:  r[   r;  rU   r   r[   r[   r\   r   ?     z8test_check_is_fitted_attributes.<locals>.MyEstimator.fitN)r   r=  r>  r   r[   r[   r[   r\   MyEstimator>      rb  z
not fittedr   a_b_)
attributes)rf  
all_or_anyr   r   )r   r   r/   r   allrT   rd  re  )rb  r   estr[   r[   r\   test_check_is_fitted_attributes=  s0   rj  wrap)singlelisttuple)idsc                 C   s   t  }tjtdd t|| dg W d    n1 sw   Y  |jt   t|| dg tjtdd t|| dg W d    d S 1 sKw   Y  d S )Nzis not fitted yetr   coef_	coef_bad_)r   r   r   r/   r   r   r   )rk  r[  r[   r[   r\   $test_check_is_fitted_with_attributesY  s   "rr  c                   C   s  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dgtd	 tjtd
d t ddgdg W d    n1 sGw   Y  tjtdd t ddgd W d    n1 sew   Y  tjtdd t ddgt	  W d    n1 sw   Y  tt t ddgtd W d    n1 sw   Y  tjtdd t ddgt
  W d    d S 1 sw   Y  d S )Nr`   r8   r2   rg   r9   r   r   )r8   r`   r8   zinconsistent numbers of samplesr   zgot <\w+ 'int'>zgot <\w+ 'object'>Expected sequence or array-like)r   r=   r   rO   r   r   r   r   r   rK   r   r[   r[   r[   r\   test_check_consistent_lengthk  s$   ""ru  c                  C   s\   z"dd l } tg dg dg dg}| j|g dd}t| W d S  ty-   tdw )Nr   r   r   r   )r   r   r   r   zPandas not found)r   r=   r   r   r   ImportErrorr   )r   rU   r   r[   r[   r\   "test_check_dataframe_fit_attribute  s   rx  c                  C   s   t dt jg} tt t|  W d    n1 sw   Y  tjdd t|  tjdd tt t|  W d    d S 1 sFw   Y  d S )Nr   T)assume_finiteF)	r=   r   infr   r   r   r   sklearn
set_configrj   r[   r[   r\   test_suppress_validation  s   

"r}  c                  C   sp   t d} t| g ddd}t|tg d | g dd}t|d dd}t|tjg dtd d S )	Nr   r   Fr   r   category)r5   r   r4   )r   r   Seriesr	   r=   r   rB   rK   )r   ressr[   r[   r\   test_check_array_series  s   r  r5   
bool_dtype)rE   booleanc                 C   s   |dkrt ddd}nt d}|jg dg d|jg d|dd	g d	d
}t|| d}|jtjks5J tjg dg dg dgtd}t	|| d S )Nr  r   1.0r   r   )r   r:    @TFTr4   )r   r   rE   rv  )      ?        r  )       @r:   r  )      @r  r  )
r   r   r  r   r5   r=   rD   r   r   r
   )r5   r  r   dfr   expected_arrayr[   r[   r\   'test_check_dataframe_mixed_float_dtypes  s    	r  c                  C   s   t d} | dg di}t|dd}|jtjksJ t|dgdgdgg | jg dg dd	dd
gd}t|dd}|jtjksDJ t|ddgddgddgg dS )z7Check that dataframe with bool return a boolean arrays.r   rE   r  Nr4   TFr   )rE   r   r   rv  r   r`   r   r8   r2   )r   r   r   r5   r=   bool_r	   rC   r   r  r   r[   r[   r\   #test_check_dataframe_with_only_bool  s    r  c                  C   s^   t ddd} | d| jg dddi}t|d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   r  r   rE   r  r  r4   NTF)r   r   r  r   r5   r=   rD   r	   r  r[   r[   r\   &test_check_dataframe_with_only_boolean  s
   r  c                   @   r_  )DummyMemoryc                 C      |S r:  r[   )r;  funcr[   r[   r\   cache  ra  zDummyMemory.cacheN)r   r=  r>  r  r[   r[   r[   r\   r    rc  r  c                   @   s   e Zd ZdS )WrongDummyMemoryN)r   r=  r>  r[   r[   r[   r\   r    s    r  c                  C   s   t d} | jdksJ t d } | jd u sJ t }t |} | |u s#J d}tjt|d t d W d    n1 s;w   Y  t }d|}tjt|d t | W d    d S 1 s_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.)r    locationr  r   r   r   r  r   )memorydummyr   r[   r[   r\   test_check_memory  s&   

"r  r7   c                 C   sp   t d}t|dd#}t|| d}t |||  ksJ |jd | ks&J W d    d S 1 s1w   Y  d S )N)rg   rg   r)	mmap_moder6   	WRITEABLE)r=   r>   r1   r   may_share_memoryr~   )r7   rU   X_memmapr   r[   r[   r\   test_check_array_memmap  s   
"r  c                 C   s   t 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d t|d W d    d S 1 sIw   Y  d S )	N)r`   r`   r   r   )r   r   r   r   r   r   r|   r<   z	Negative r   )r=   r   r!   r   r   r   )r   r   rU   r[   r[   r\   test_check_non_negative  s   "

"r  c                  C   s   t d} d }d}tjt|d t| | W d    n1 s w   Y  d}tjt|d t| |t d W d    d S 1 sBw   Y  d S )Nr8   r8   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   )r=   r>   r   r   r   r   r   )rU   r   r   r[   r[   r\    test_check_X_y_informative_error(  s   
"r  c                  C   st   G dd d} |  }t |t|ksJ G dd d}tjtdd t |  W d    d S 1 s3w   Y  d S )Nc                   @   rS  )zJtest_retrieve_samples_from_non_standard_shape.<locals>.TestNonNumericShapec                 S   
   d| _ d S N)znot numericro   rV  r[   r[   r\   __init__6     
zStest_retrieve_samples_from_non_standard_shape.<locals>.TestNonNumericShape.__init__c                 S   s   t g dS )Nr   )r   rV  r[   r[   r\   __len__9  s   zRtest_retrieve_samples_from_non_standard_shape.<locals>.TestNonNumericShape.__len__N)r   r=  r>  r  r  r[   r[   r[   r\   TestNonNumericShape5  s    r  c                   @   r_  )zJtest_retrieve_samples_from_non_standard_shape.<locals>.TestNoLenWeirdShapec                 S   r  r  r  rV  r[   r[   r\   r  A  r  zStest_retrieve_samples_from_non_standard_shape.<locals>.TestNoLenWeirdShape.__init__N)r   r=  r>  r  r[   r[   r[   r\   TestNoLenWeirdShape@  rc  r  rt  r   )r"   r   r   r   r   )r  rU   r  r[   r[   r\   -test_retrieve_samples_from_non_standard_shape4  s   "r  rl   )r8   r2   g      @r9   c              	   C   sX   t   t d t| dtjdddd}W d   n1 sw   Y  || ks*J dS )zPTest that check_scalar returns no error/warning if valid inputs are
    providederror	test_namer8   r9   bothtarget_typemin_valmax_valinclude_boundariesN)r   r   simplefilterr#   numbersReal)rl   scalarr[   r[   r\   test_check_scalar_validH  s   


r  zJx, target_name, target_type, min_val, max_val, include_boundaries, err_msg
test_name1rg   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.r9   
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              	   C   sn   t t}t| |||||d W d   n1 sw   Y  t|jt|ks*J t|jt|ks5J dS )zLTest that check_scalar returns the right error if a wrong input is
    givenr  N)r   r   	Exceptionr#   r   r   type)rl   target_namer  r  r  r  r   raised_errorr[   r[   r\   test_check_scalar_invalidY  s   v	r  rs  )r9   y        -C6
?zJThere are imaginary parts in eigenvalues \(1e\-05 of the maximum real part)r9   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)r9   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                 C   sd   |sd }d}t j||d}tt| |d| W d    n1 s!w   Y  |d u r.|r0J d S d S )Nr   r   )r  )r   rI  r	   r$   )lambdasexpected_lambdasw_typew_msgr  r   r[   r[   r\    test_check_psd_eigenvalues_valid  s   
r  )r9   y              @z/There are significant imaginary parts in eigenv)r|   z,All eigenvalues are negative \(maximum is -1)r9   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                 C   s<   t j||d t|  W d    d S 1 sw   Y  d S )Nr   )r   r   r$   )r  err_typer   r[   r[   r\   "test_check_psd_eigenvalues_invalid1  s   	
"r  c                  C   s  t dd d d } | jd rJ t| t dd} | jd s!J td t dd} t| t d tdt dd} t| dt d  tjtd	d
 tt dt dd W d    n1 scw   Y  d}tjt|d
 tt dt dd W d    n1 sw   Y  t d}t jdt jd} t| |} | j	t jksJ t jdt
d}td ||j	d} | j	t jksJ t d}t t|} d| d< d}tjt|d
 t| |dd W d    d S 1 sw   Y  d S )Nr3   r8   ry   )r9   r`   rj   )r9   r8   r9   r  z)Sample weights must be 1D array or scalarr   )r8   rg   r  z/sample_weight.shape == \(4,\), expected \(2,\)!rg   r4   ir|   z1Negative values in data passed to `sample_weight`T)only_non_negative)r=   r>   r~   r'   r   r   r   r   rA   r5   r   rD   r"   )r   r   rU   r   r[   r[   r\   test_check_sample_weight>  s:   


"r  rQ   c                 C   s6   t ddd}| || |}}t||sJ d S )Nr   r2   r=   r@   rh   r(   rQ   baserl   r   r[   r[   r\   !test_allclose_dense_sparse_equalsj  s   r  c                 C   s:   t ddd}| || |d }}t||rJ d S )Nr   r2   r`   r  r  r[   r[   r\   %test_allclose_dense_sparse_not_equalsq  s   r  c                 C   s`   t ddd}| |d }d}tjt|d t|| W d    d S 1 s)w   Y  d S )Nr   r2   r`   zFCan only compare two sparse matrices, not a sparse matrix and an arrayr   )r=   r@   rh   r   r   r   r(   )rQ   rl   r   r   r[   r[   r\    test_allclose_dense_sparse_raisex  s   "r  c                  C   s,  t ddddd} tjtdd | ddd W d    n1 s"w   Y  tjtd	d | dddd
 W d    n1 s@w   Y  t ddddddd}tjtdd |dd W d    n1 shw   Y  t ddddd}tjtdd |dd W d    d S 1 sw   Y  d S )Nr`   r   dc                S   r9  r:  r[   r   r   r   r  r[   r[   r\   f1  r<  z=test_deprecate_positional_args_warns_for_function.<locals>.f1Pass c=3 as keyword argsr   r8   r2   Pass c=3, d=4 as keyword argsrg   )r   r   r  c                S   r9  r:  r[   r  r[   r[   r\   f2  r<  z=test_deprecate_positional_args_warns_for_function.<locals>.f2zPass b=2 as keyword argsc                S   r9  r:  r[   r  r[   r[   r\   f3  r<  z=test_deprecate_positional_args_warns_for_function.<locals>.f3)r`   r&   r   rI  FutureWarning)r  r  r  r[   r[   r\   1test_deprecate_positional_args_warns_for_function  s$   "r  c                  C   sP   t dddd } tjtdd | dd W d    d S 1 s!w   Y  d S )	N1.1)versionc                S   r9  r:  r[   )r   r   r[   r[   r\   r    r<  zEtest_deprecate_positional_args_warns_for_function_version.<locals>.f1z,From version 1.1 passing these as positionalr   r`   r8   r  )r  r[   r[   r\   9test_deprecate_positional_args_warns_for_function_version  s   
"r  c                  C   s  G dd d} t jtdd | ddd W d    n1 sw   Y  t jtdd | dddd	 W d    n1 s=w   Y  G d
d d}t jtdd |ddd W d    n1 saw   Y  t jtdd |dddd	 W d    d S 1 sw   Y  d S )Nc                   @   s    e Zd ZedddddZdS )z:test_deprecate_positional_args_warns_for_class.<locals>.A1r`   r  c                S   r9  r:  r[   r;  r   r   r   r  r[   r[   r\   r    r<  zCtest_deprecate_positional_args_warns_for_class.<locals>.A1.__init__Nr   r=  r>  r&   r  r[   r[   r[   r\   A1  s    r  r  r   r`   r8   r2   r  rg   c                   @   s"   e Zd ZeddddddZdS )z:test_deprecate_positional_args_warns_for_class.<locals>.A2r`   r  c                S   r9  r:  r[   r  r[   r[   r\   r    r<  zCtest_deprecate_positional_args_warns_for_class.<locals>.A2.__init__N)r`   r`   r  r[   r[   r[   r\   A2  s    r  )r   rI  r  )r  r  r[   r[   r\   .test_deprecate_positional_args_warns_for_class  s   "r  r  r2   c                 C   s   t jdd}g dt g dtg djtg dddd d}t||| }| d ur/| ntt	|j
d }dD ]}|| || u sFJ q:|d	 t|d	 |ksTJ t|d
 t|d
 | t|d t|d | d S )Nrg   r8   )r`   r8   r2   rg   r`   xxx)rm  r   
sparse-col
sparse-row
scalar-int
scalar-strNoner   )r  r  r  r  rm  r   r  )r=   randomrandnr   rO   rP   r}   r-   rm  rangero   r   r	   r
   )r  rU   
fit_paramsr   indices_keyr[   r[   r\   test_check_fit_params  s$   	r   	sp_format)Tr   r  r   r  c                 C   sd   t d}tdd}|jj|}t|| d}| du rd} t|s$J |j	| ks+J t
|| d S )Nr   r3   r2   r  Tr   )r   r   r   r   sparsefrom_spmatrixr   rO   rK  r   r
   )r  r   sp_matsdfr   r[   r[   r\   "test_check_sparse_pandas_sp_format  s   

r  zntype1, ntype2)	)
longdoubler   )r   rA   )rA   double)rG   r?   )r?   long)byterI   )ushortrJ   )rJ   uint64)rH   rF   c                 C   s   t d}||jjg d| dd|jjg d|ddd}t|jtdk rLd}t jt|d	 t	|d
dgd W d   dS 1 sEw   Y  dS t	|d
dgd dS )zcheck that we raise an error with dataframe having
    sparse extension arrays with unsupported mixed dtype
    and pandas version below 1.1. pandas versions 1.1 and
    above fixed this issue so no error will be raised.r   r   r`   r   r   r5   
fill_valuer`   r   r`   col1col2r  z3Pandas DataFrame with mixed sparse extension arraysr   r   r  r  N)
r   r   r   arraysSparseArrayr   __version__r   r   r   )ntype1ntype2r   r  r   r[   r[   r\    test_check_pandas_sparse_invalid  s   
"r  z ntype1, ntype2, expected_subtype	longfloatr  r   halfrl  rA   r  rD   rF   r
  shortrG   intcr?   int0r	  r   rC   longlongint_intpubyterH   rI   r  uintcrJ   uintr  uintp	ulonglongc                 C   sd   t d}||jjg d| dd|jjg d|ddd}t|ddgd	}t|j|s0J d S )
Nr   r  r   r  r  r  r   r  r  )	r   r   r   r  r  r   r=   
issubdtyper5   )r  r  expected_subtyper   r  r  r[   r[   r\   test_check_pandas_sparse_valid  s   
r)  constructor_name)rm  rn  r   	dataframe
sparse_csr
sparse_cscc                 C   s.   g dg dg}t || }t|dksJ dS )z$Check _num_features for array-likes.r   r   r2   N)r   r)   )r*  rU   r[   r[   r\   test_num_features4  s   
r.  r   r   )FTF)r  g333333@g      @r   r   r   )r   r   rE   r   dict)rm  rn  r   seriesc                 C   s   t | |} |dkrd}n	|dkrd}n|}d| }t| dr$|d7 }nt| d tr0|d	7 }nt| d tr;|d
7 }tjtt	|d t
|  W d    d S 1 sUw   Y  d S )Nr   znumpy.ndarrayr0  zpandas.core.series.Series5Unable to find the number of features from X of type ro   z with shape (3,)r   z" where the samples are of type strz# where the samples are of type dictr   )r   r  ri   r   r/  r   r   r   reescaper)   )rU   r*  expected_type_namer   r[   r[   r\   &test_num_features_errors_1d_containers?  s"   




"r5  )r`   r   Fr  )r   r   rE   r   c                 C   sL   dt | j }tjt|d t|  W d    d S 1 sw   Y  d S )Nr1  r   )r  r>  r   r   r   r)   rU   r   r[   r[   r\    test_num_features_errors_scalars`  s   
"r7  c                  C   sP   t t d} d}tjt|d t|  W d   dS 1 s!w   Y  dS )z.Test that matrix support is deprecated in 1.0.r9   zxnp.matrix usage is deprecated in 1.0 and will raise a TypeError in 1.2. Please convert to a numpy array with np.asarray.r   N)r=   rN   r@   r   rI  r  r   r6  r[   r[   r\   "test_check_array_deprecated_matrixh  s   
"r8  namesr  )zlist-intr  default
MultiIndexc                 C   sv   t d}|jddgddgddgg| d}t  tdt t|} W d	   n1 s.w   Y  | d	u s9J 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`   r8   rg   r9   r_   rv  r  N)r   r   r   r   r   r  r  r+   )r9  r   rU   r[   r[   r\   2test_get_feature_names_pandas_with_ints_no_warningu  s   

 

r<  c                  C   sL   t d} dd tdD }| jg dg dg|d}t|}t|| dS )	z)Get feature names with pandas dataframes.r   c                 S   s   g | ]}d | qS )col_r[   ).0r  r[   r[   r\   
<listcomp>  s    z1test_get_feature_names_pandas.<locals>.<listcomp>r2   r   r   rv  N)r   r   r  r   r+   r	   )r   r   rU   feature_namesr[   r[   r\   test_get_feature_names_pandas  s
   
rA  c                  C   s.   t g dg dg} t| }|du sJ dS )z/Get feature names return None for numpy arrays.r   r   N)r=   r   r+   )rU   r9  r[   r[   r\   test_get_feature_names_numpy  s   rB  znames, dtypesz['int', 'str']pizzaz['list', 'str']zint-strzlist-strc                 C   s   t d}|jddgddgddgg| d}td| d	}t jt|d
 t|} W d   n1 s4w   Y  | du s?J dS )z@Get feature names warns when the feature names have mixed dtypesr   r`   r8   rg   r9   r_   rv  zVFeature names only support names that are all strings. Got feature names with dtypes: z. An error will be raisedr   N)r   r   r   r2  r3  rI  r  r+   )r9  r   r   rU   r   r[   r[   r\   +test_get_feature_names_invalid_dtypes_warns  s   

 
rD  c                   @   s(   e Zd ZdddZdd ZdddZdS )	PassthroughTransformerNc                 C   s   | j |dd | S )NT)reset)_validate_datar`  r[   r[   r\   r     s   zPassthroughTransformer.fitc                 C   r  r:  r[   )r;  rU   r[   r[   r\   	transform  ra  z PassthroughTransformer.transformc                 C   s
   t | |S r:  )r,   )r;  input_featuresr[   r[   r\   get_feature_names_out  r  z,PassthroughTransformer.get_feature_names_outr:  )r   r=  r>  r   rH  rJ  r[   r[   r[   r\   rE    s    
rE  c                  C   s   t g dg} t | }| }t|g d ddg}tjtdd || W d   n1 s4w   Y  |`	tjtdd |  W d   dS 1 sRw   Y  dS )	z4Check behavior of check_feature_names_in for arrays.r  r  r  )x0x1x2x10rM  z*input_features should have length equal tor   Nz Unable to generate feature names)
r=   r   rE  r   rJ  r	   r   r   r   n_features_in_)rU   ri  r9  incorrect_len_namesr[   r[   r\   test_check_feature_names_in  s   
"rR  c                  C   s   t d} g d}| jg dg|d}t |}| }t|g d t jtdd |g d W d   dS 1 s>w   Y  dS )	z?Check behavior of check_feature_names_in for pandas dataframes.r   r   rK  rv  zinput_features is not equal tor   )rM  rN  x3N)	r   r   r   rE  r   rJ  r	   r   r   )r   r9  r  ri  r[   r[   r\   "test_check_feature_names_in_pandas  s   
"rT  )__doc__r  r   r2  tempfiler   	itertoolsr   operatorr   r   r   numpyr=   scipy.sparser  rO   sklearn.utils._testingr   r   r   r	   r
   r   r   sklearn.utilsr   r   r   r   r   sklearn.utils._mockingr   sklearn.utils.fixesr   sklearn.utils.estimator_checksr   sklearn.random_projectionr   sklearn.linear_modelr   sklearn.neighborsr   sklearn.ensembler   sklearn.svmr   sklearn.datasetsr   r   sklearn.utils.validationr   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   sklearn.baser.   r{  sklearn.exceptionsr/   r0   r1   markfilterwarningsr]   parametrizer  r  tocsrre   rk   rv   r   rz  rR   rq   r   r   r   r   r   r   rK   r   r   r   rA   rD   r   r   r  r  r  r  r  fixturer$  r&  r'  r.  r8  r@  rR  rY  r^  rj  rm  rn  rr  ru  rx  r}  r  r  r  r  r  r  r  r  rP   r7  rF  rG  rE  
dia_matrixr  r  r  r  r   r   r  IntegralrE   r   r   r  _psd_cases_validvalueskeysr  _psd_cases_invalidr  r  r  r  r  r  r  r  r   r  r  floatingintegerunsignedintegerr)  r.  r5  r7  r8  r  r<  rA  rB  rD  rE  rR  rT  r[   r[   r[   r\   <module>   s(   P

$+


	(	
r


%	,


:*#$













q




,


	

*

