3
Ud                 @   sH   d dl Zd dlZd dlZd dlmZmZmZ d dlj	Z
G dd dZdS )    N)	DataFrameSeries
date_rangec               @   sL   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S )TestDataFrameRoundc          D   C   s  t  }tj||j  t dddgdddgd}t dd	d
gdd	d
gd}tj|j | d}t dddgdddgd}tj|j|| tjtj||| ddg}d}tjt|d |j| W d Q R X t dddgdddgd}ddd}tj|j|| t dddgdddgd}ddi}tj|j|| ddd}	tj|j|	| ddd}
d}tjt|d |j|
 W d Q R X ddd}
d }tjt|d |j|
 W d Q R X t|
}tjt|d |j| W d Q R X dddgd}
d!}tjt|d |j|
 W d Q R X t|
}tjt|d |j| W d Q R X t|
}tjt|d |j| W d Q R X t|
}tjt|d |j| W d Q R X d+d,d}|d" }t d#d$d%gd&d'd(gd}tj|j|| ttj	dd}d}tjt|d |j| W d Q R X tj
|d) jd|d)  d}t dddgdddgd}d*|j_d*|j_tj|j|| tj
|d) j||d)  tj
|j|d) |d)  d S )-Ng+?gCl @gCl@gX9v?gZd;@gZd;	@)col1col2g      ?g       @g      @   gQ?g(\ @g(\@gGz?gףp=
@gףp=
	@   z4decimals must be an integer, a dict-like or a Series)matchg?g @g@g333333?g@g	@r   )col3r   g      ?z$integer argument expected, got floatZfooz'an integer is required \(got type str\)z(an integer is required \(got type list\)d   g     [@   i6  g      Y@   i,  r   cols)r   tmassert_frame_equalroundnppytestraises	TypeErrorr   nanZassert_series_equalcolumnsname)selfdfexpected_roundeddecimalsZ
round_listmsgZ
round_dictZexpected_partially_roundedZpartial_round_dictZwrong_round_dictZnon_int_round_dictZnon_int_round_SeriesZnegative_round_dictZbig_dfZexpected_neg_roundedZnan_round_Series r!   Y/var/www/html/virt/lib64/python3.6/site-packages/pandas/tests/frame/methods/test_round.py
test_round
   s    




zTestDataFrameRound.test_roundc             C   st   t ddgddgg}tj|dd}t ddgd	d
gg}tj|| d}tjt|d tj|d|d W d Q R X d S )Ng{Gz?g(\?gQ?g
ףp=
@r   )r   g       @g      ?g        g      @z$the 'out' parameter is not supported)r
   )r   out)r   r   r   r   r   r   r   
ValueError)r   r   r$   expectedr    r!   r!   r"   test_round_numpy~   s    z#TestDataFrameRound.test_round_numpyc             C   sV   t dtjdgj }tjd  |j }W d Q R X t dtjdgj }tj|| d S )Ng{Gz?gQ?g       @g        )r   r   r   Zto_framer   Zassert_produces_warningr   r   )r   r   resultr&   r!   r!   r"   test_round_numpy_with_nan   s
    z,TestDataFrameRound.test_round_numpy_with_nanc             C   s   t ddddgddddgtd	d
dd}t ddddgddddgtd	d
dd}tj|j | tj|jd| tj|jddi| tj|jddi| tj|jddd| tj|jddi| d S )Ng?g@gffffff
@g@1acfZ20111111   )Zperiods)r   r   r   g      ?g       @g      @g      @r	   r   r   )r   r   r   )r   r   r   r   r   )r   r   Zround_0r!   r!   r"   test_round_mixed_type   s    



z(TestDataFrameRound.test_round_mixed_typec          	   C   s   t jtjjddgdddgdddgd}t j||fd	d
}|j }tj|j|j t j	d	ddgdddgd}d}t
jt|d |j| W d Q R X d S )N   ABCfirstsecondthird)r   indexr	   )Zaxisr   r   )r7   z Index of decimals must be unique)r
   )pdr   r   randomconcatr   r   Zassert_index_equalr7   r   r   r   r%   )r   r   dfsZroundedr   r    r!   r!   r"   !test_round_with_duplicate_columns   s    z4TestDataFrameRound.test_round_with_duplicate_columnsc             C   sH   t dddgdddgd}t dd	d
gdd	d
gd}tjt|| d S )Ng+?gCl @gCl@gX9v?gZd;@gZd;	@)r   r   g      ?g       @g      @)r   r   r   r   )r   r   r   r!   r!   r"   test_round_builtin   s    z%TestDataFrameRound.test_round_builtinc             C   s   t jdgd dgd  }t jtjjddtdd}|jd}||_|j	 j
|}|jdksbt|jd}|jdkszttj|| d S )	Nlowr0   hi   abc)r   )r@   r0   )r@   r0   )r8   CategoricalIndexr   r   r9   Zrandlistr   r7   copyZ	set_indexshapeAssertionErrorr   r   )r   idxr   r&   Zdf_categoricalr(   r!   r!   r"    test_round_nonunique_categorical   s    

z3TestDataFrameRound.test_round_nonunique_categoricalc             C   sZ   t jt jdd}tddgddgg|d}|j }tddgd	d	gg|d}tj|| d S )
Nr   r   gQ?g?g333333?g      ?)r   g      ?g        )r8   rB   Zinterval_ranger   r   r   r   )r   r   r   r(   r&   r!   r!   r"   $test_round_interval_category_columns   s
    z7TestDataFrameRound.test_round_interval_category_columnsN)__name__
__module____qualname__r#   r'   r)   r/   r<   r=   rH   rI   r!   r!   r!   r"   r   	   s   t	r   )Znumpyr   r   Zpandasr8   r   r   r   Zpandas._testingZ_testingr   r   r!   r!   r!   r"   <module>   s
   
