a
    ;Za`	                     @   s   d dl Zd dlZd dlmZ d dlmZmZmZ d dl	m
Z
 g dg dg dgZdggd	 Zd
d Zdd Zejdeeegdd Zejjeed kdddd Zdd ZdS )    N)assert_array_equal)
bsr_matrix
csc_matrix
csr_matrix)VarianceThreshold)r               )r   r   r   r	      )r   r   r   r
   r   g$b@
   c                  C   s   t tt tt tt fD ]&} t | }tg d|jdd qt	t
" t g dg W d    n1 sr0    Y  t	t
( t ddgddgg W d    n1 s0    Y  d S )N)r   r   r	   r
   Tindices)r   r   r   r	   r   r   )datar   r   r   r   fitr   get_supportpytestraises
ValueError)Xsel r   Vlib/python3.9/site-packages/sklearn/feature_selection/tests/test_variance_threshold.pytest_zero_variance   s    0r   c                  C   s<   t tt fD ]*} tdd| } tt df| jksJ qd S )Ng?Z	thresholdr   )r   r   r   Zfit_transformlenshape)r   r   r   r   test_variance_threshold   s    r   r   c                 C   sJ   t dd}d}tjt|d ||  W d   n1 s<0    Y  dS )z.Test VarianceThreshold with negative variance.g      r   z+^Threshold must be non-negative. Got: -1.0$matchN)r   r   r   r   r   )r   Zvar_thresholdmsgr   r   r   test_variance_negative#   s    
r!   zRThis test is not valid for this platform, as it relies on numerical instabilities.)reasonc               	   C   s`   t tt tt tt fD ]B} d}tjt|d t |  W d    q1 sP0    Y  qd S )Nz4No feature in X meets the variance threshold 0.00000r   )	data2r   r   r   r   r   r   r   r   )r   r    r   r   r   'test_zero_variance_floating_point_error,   s    r$   c                  C   sp   t jtt jd} t j| d< t j| d d df< | t| t| t| fD ]&}t 	|}t
g d|jdd qDd S )N)Zdtype)r   r   r   )r   r	   r
   Tr   )npZarrayr   Zfloat64ZNaNr   r   r   r   r   r   r   )Zarrr   r   r   r   r   test_variance_nan?   s    
r&   )Znumpyr%   r   Zsklearn.utils._testingr   Zscipy.sparser   r   r   Zsklearn.feature_selectionr   r   r#   r   r   ZmarkZparametrizer!   Zskipifvarr$   r&   r   r   r   r   <module>   s    

