U
    3d                     @   sL   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 Zd	d
 ZdS )    N)sparse)suppress   )is_scalar_nan)_object_dtype_isnanc              
   C   s   t tt. dd l}||jkr4|| W  5 Q R  S W 5 Q R X t|r| jjdkr^t	
| }q| jjdkr|t	j| jtd}qt| }n| |k}|S )Nr   f)iu)dtype)r   ImportErrorAttributeErrorpandasZNAZisnar   r
   kindnpisnanzerosshapeboolr   )Xvalue_to_maskr   Xt r   7/tmp/pip-unpacked-wheel-zrfo1fqw/sklearn/utils/_mask.py_get_dense_mask	   s    
 
r   c                 C   s\   t | st| |S t| j|}| jdkr0t jnt j}||| j | j	 f| j
td}|S )a  Compute the boolean mask X == value_to_mask.

    Parameters
    ----------
    X : {ndarray, sparse matrix} of shape (n_samples, n_features)
        Input data, where ``n_samples`` is the number of samples and
        ``n_features`` is the number of features.

    value_to_mask : {int, float}
        The value which is to be masked in X.

    Returns
    -------
    X_mask : {ndarray, sparse matrix} of shape (n_samples, n_features)
        Missing mask.
    Zcsr)r   r
   )spissparser   dataformatZ
csr_matrixZ
csc_matrixindicescopyZindptrr   r   )r   r   r   Zsparse_constructorZ	Xt_sparser   r   r   	_get_mask!   s    

  r    )Znumpyr   Zscipyr   r   
contextlibr    r   fixesr   r   r    r   r   r   r   <module>   s   