U
    sVc(                     @   sV   d dl Z d dlZd dlZd dlZd dlZd dlmZmZ d dl	m
Z G dd dZdS )    N)	DataFrameSeriesc                   @   s   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd ZdS ) TestDataFrameMissingDatac                 C   s
  t |j}tj|}tj|d d< td|i|jd}t||jdd}| }|	 |	  }}|jdd}	t
|d | |jddd}
t
|	d | t
|d | |
d kst|jddgd	}	|jddgdd
}
t
|	d | t
|d | |
d kstd S )N   fooindexr   nameallhowT)r   inplace)r   subset)r   r   r   )lenr   nprandomrandnnanr   r   dropnacopytmassert_series_equalAssertionError)selffloat_frameNmatframeoriginalexpectedZinplace_frame1Zinplace_frame2smaller_framereturn_value r#   J/tmp/pip-unpacked-wheel-xj8nt62q/pandas/tests/frame/methods/test_dropna.pytest_dropEmptyRows   s$    
z+TestDataFrameMissingData.test_dropEmptyRowsc                 C   sF  t |j}tj|}tj|d d< td|i|jd}d|d< t||jdd}| |  }}|	 }t
|d | |j	dd}	t|dd  |jdd  dd}
t
|d |
 t
|d |
 |	d kst|j	dgd}t
|d | |d dk st|j	dgdd	}	t
|j|j t
|j|j |	d ksBtd S )
Nr   r   r   barr	   Tr   r   )r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   Zassert_index_equal)r   r   r   r   r   r   Z
inp_frame1Z
inp_frame2r!   r"   expZsamesize_framer#   r#   r$   test_dropIncompleteRows(   s*    
 z0TestDataFrameMissingData.test_dropIncompleteRowsc              	   C   s  t tjdd}tj|jd ddf< |jdd}|jd d dddgf }| }|jddd	}t	
|| t	
|| |d kst|jdd}|jttdd }| }|jddd	}t	
|| t	
|| |d kst|jdd
d}|jd d dddgf }| }|jdd
dd}t	
|| t	
|| |d ksBt|jddd}|jtdd }| }|jdddd}t	
|| t	
|| |d kst|jddd}t	
|| |jddd}t	
|| |jddddgd}| }|jddddgdd}t	
|| t	
|| |d ks*t|jddd}t	
|| tj|d< |jddd}|jd d dddgf }t	
|| d}tjt|d |jdd W 5 Q R X d S )N            axisr      T)r0   r   r   )r0   thresh)r0   r2   r   )r0   r   )r0   r   r   r   )r0   r   z)No axis named 3 for object type DataFramematch)r   r   r   r   r   ilocr   locr   r   assert_frame_equalr   listrangepytestraises
ValueError)r   dfZdroppedr    inpr"   msgr#   r#   r$   test_dropnaC   sb    
z$TestDataFrameMissingData.test_dropnac                 C   s  t ddtjgdd}t ddg|jdd}td|j i}| }|d   t	|d | |d }|jdd}t	|| t	|d | |d kst
|d dg t	|d | |d }|jdgdd}t	||dg t	|d | |d kst
d S )Nr.   r-   A)r
   )dtyper
   Tr'   )r   r   r   rB   r   valuesr   r   r   r   r   Zdrop)r   r   r    r=   Zdf2Zserr"   r#   r#   r$   test_drop_and_dropna_caching   s$    z5TestDataFrameMissingData.test_drop_and_dropna_cachingc              	   C   sX   d}t jt|d |jdd W 5 Q R X t jtdd |jddgd W 5 Q R X d S )	Nzinvalid how option: foor3   r   r   z	^\['X'\]$rA   Xr(   )r:   r;   r<   r   KeyError)r   r   r?   r#   r#   r$   test_dropna_corner   s
    z+TestDataFrameMissingData.test_dropna_cornerc              	   C   s   t dtjddgdtjddgtjtjtjtjgdtjdd	gg}tjtd
d |jdddgd W 5 Q R X tjtd
d |jddd W 5 Q R X | }tjtd
d |jdddd W 5 Q R X d S )Nr.   r-   r1   r,   r   r+         	   zsupplying multiple axesr3   r   r   )r   r0   )r   r.   T)r   r0   r   )r   r   r   r:   r;   	TypeErrorr   r   )r   r=   r>   r#   r#   r$   test_dropna_multiple_axes   s    
z2TestDataFrameMissingData.test_dropna_multiple_axesc                 C   s   t  }tjdddtj d}tjdddtj d}|g|d< |jdd}t d|gi}t|| t d|d tj	|gi}|jdd}t ||gdgddgd	}t|| d S )
Ni  r.   )tzinfor-   ZTimer   r/   r1   )columnsr   )
r   datetimedateutiltzZtzutcr   r   r7   r   r   )r   r=   Zdt1Zdt2resultr    r#   r#   r$   test_dropna_tz_aware_datetime   s    
z6TestDataFrameMissingData.test_dropna_tz_aware_datetimec                 C   sN   t jddddg}t |}tdtdi|d}|}| }t|| d S )Nr   g=
ףp=@gQ	@gQ@rA   abcr   )	pdZIntervalIndexZfrom_breaksZCategoricalIndexr   r8   r   r   r7   )r   iicir=   r    rR   r#   r#   r$   &test_dropna_categorical_interval_index   s    
z?TestDataFrameMissingData.test_dropna_categorical_interval_indexc              	   C   s   t tjdtjdtjddddddgd}tj|jdd	d
dgf< tj|jd< tj|jd< d}tjt|d tj|jd d df< W 5 Q R X |j	dddgdd}ddddg|_
ddddg|_
|j	ddgdd}t|| d S )Nr   abcde)rA   BCDr-   r   r.   )r   r   )r.   r.   z.will attempt to set the values inplace insteadr3   r1   rA   r^   r_   r   )r   r   )r   r   r   r   r   r5   r   assert_produces_warningDeprecationWarningr   rN   r7   )r   r=   r?   r    rR   r#   r#   r$   "test_dropna_with_duplicate_columns   s$    


z;TestDataFrameMissingData.test_dropna_with_duplicate_columnsc              	   C   s\   t ddddgi}d}tjt|d |d}W 5 Q R X t ddddgi}t|| d S )NrY   r.   r-   r1   zUIn a future version of pandas all arguments of DataFrame\.dropna will be keyword-onlyr3   )r   r   ra   FutureWarningr   r7   )r   r=   r?   rR   r    r#   r#   r$    test_dropna_pos_args_deprecation   s    z9TestDataFrameMissingData.test_dropna_pos_args_deprecationc                 C   sb   t dddgtddtjdgd}t ddgtdd	d
gdddgd}|jdd}t|| d S )Nr.   r-   r1   rT   r,   r   rA   r^   r_   ac      @g      @r   r   r_   r(   )r   r8   r   NaNr   r   r7   r   r=   r    rR   r#   r#   r$   test_set_single_column_subset   s    " z6TestDataFrameMissingData.test_set_single_column_subsetc              	   C   s>   t ddddgi}tjtdd |jddd	 W 5 Q R X d S )
NrA   r.   r-   r1   z['D']r3   r`   r   )r   r0   )r   r:   r;   rF   r   )r   r=   r#   r#   r$   &test_single_column_not_present_in_axis   s    z?TestDataFrameMissingData.test_single_column_not_present_in_axisc                 C   s`   t ddtjgtddtjdgd}t dgdgd	gd}|jtd
dgd}t|| d S )Nr.   r-   rT   r,   r   rf   g      ?rY   rh   rA   r_   r(   )r   r   ri   r8   r   arrayr   r7   rj   r#   r#   r$   test_subset_is_nparray  s    $z/TestDataFrameMissingData.test_subset_is_nparrayc                 C   sH   t ddgddggtddd}| }|j|d}tj||dd	 d S )
Nr.   r-   r1   r,   r   )rN   r/   T)Zcheck_index_type)r   rU   Z
RangeIndexr   r   r   r7   )r   r0   r=   r    rR   r#   r#   r$   test_no_nans_in_frame  s     z.TestDataFrameMissingData.test_no_nans_in_framec              	   C   s   t ddtjg}d}tjt|d |jddd W 5 Q R X tjt|d |jddd W 5 Q R X tjt|d |jd d d W 5 Q R X d S )Nr.   r-   zAYou cannot set both the how and thresh arguments at the same timer3   r   )r   r2   any)r   rU   ZNAr:   r;   rK   r   )r   r=   r?   r#   r#   r$   "test_how_thresh_param_incompatible  s    z;TestDataFrameMissingData.test_how_thresh_param_incompatibleN)__name__
__module____qualname__r%   r*   r@   rD   rG   rL   rS   rX   rc   re   rk   rl   rn   ro   rq   r#   r#   r#   r$   r      s   A	
	r   )rO   rP   Znumpyr   r:   ZpandasrU   r   r   Zpandas._testingZ_testingr   r   r#   r#   r#   r$   <module>   s   