3
UdT(                 @   sP   d dl Zd dlZd dlZd dlmZmZmZmZm	Z	 d dl
jZG dd dZdS )    N)	DataFrameIndexSeries
date_rangeoffsetsc               @   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	e
jjddd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )TestDataFrameShiftc             C   s  |j d}tj|j|j |d j d}tj|d | |j d}tj|j|j |d j d}tj|d | |j d}tj|| |j dtj d}t|t|kst	|j ddd}tj|| |jd }|tjd }tj|j
||j
|dd |j d}	tj }
|
j d}|j d}tj|j|
j tj|j|
j tj|jd d df j j|
jd ddf j |
j dd}|
j dtj }tj|| tj|
|j dd d	}tjt|d
 |
j dd W d Q R X ttjjdd}tjttj|jdgd|jd d ddf gddd}|j ddd}tj|| ttjjdd}tjttj|jdgd|jd d ddf gddd}|j ddd}tj|| d S )N   Ar   )freqBF)Zcheck_names   zdoes not match PeriodIndex freq)matchD
   )indexcolumnsT)Zignore_indexaxis)r   r   r   r   r   r   r   )shifttmZassert_index_equalr   assert_series_equalassert_frame_equalr   BDaylenAssertionErrorxsmakePeriodFrameZassert_numpy_array_equalilocZdropnavaluespytestraises
ValueErrorr   nprandomZrandpdconcatnan)selfdatetime_frameZ	int_frameZshiftedFrameZshiftedSeries	unshiftedZshiftedFrame2dZ	shifted_dZint_shiftedpsshiftedshifted2shifted3msgdfexpectedresult r4   Y/var/www/html/virt/lib64/python3.6/site-packages/pandas/tests/frame/methods/test_shift.py
test_shift
   s^    






,((zTestDataFrameShift.test_shiftc             C   sZ   t ddgddgd}|jd}t tjtjtjgddggtdddgd}tj|| d S )	NTF)highlowr   )dtyper7   r8   )r   )r   r   r#   arrayr'   objectr   r   )r(   r1   rsxpr4   r4   r5   test_shift_boolT   s    
z"TestDataFrameShift.test_shift_boolc             C   sj   t jdddgdd}t jdddgdd}t||d	}|jd
}t|jd
|jd
d	}tj|| d S )Nabccategory)r9   r	   r   C)ZoneZtwor   )r%   r   r   r   r   r   )r(   s1s2r1   r<   r=   r4   r4   r5   test_shift_categorical]   s    
z)TestDataFrameShift.test_shift_categoricalc             C   s   t dddddgtddddd	}t d
ddddgtddddd	}|jdd
d}tj|| t d
d
dddgtddddd	}|jdd
d}tj|| d S )Nr            r   z1/1/2000H)Zperiodsr
   )r   r   )
fill_value)r   r   r   r   r   )r(   r1   expr3   r4   r4   r5   test_shift_fill_valuef   s    z(TestDataFrameShift.test_shift_fill_valuec             C   s&   t dg i}|jd}tj|| d S )NZfoor   r   )r   r   r   r   )r(   r1   r<   r4   r4   r5   test_shift_emptyw   s    
z#TestDataFrameShift.test_shift_emptyc             C   s   t tddgd dddddgg}tjjdd}g }xn|D ]f}tj|j |d}x:tdD ].}|jd d |f j	|d |jd d |f< qZW td|_
|j| q:W |d j j }tj|ttdddd	 tj|d |d  tj|d |d  d S )
Nr   r   rG      )r   r      Zint64)r9   )listranger#   r$   Zrandnr%   r   copyr   r   r   appendZisnasumr   r   r   r   )r(   Zcolumn_listsdatar-   r   r1   sZnullsr4   r4   r5   test_shift_duplicate_columns~   s    "
.
z/TestDataFrameShift.test_shift_duplicate_columnsc             C   s   t jtjjdd
d}t jtjjddd}t j||gdd}t|jjdksRt	|j
ddd}|jdddddgdd}tj|jd d d df< |j|_tj|| t j||gdd}t|jjdkst	|j
ddd}|jddd	ddgdd}tj|jd d dd f< |j|_tj|| d S )Ni  r   rH   )sizerG   r   )r   r   rI   )r   rH   )r   rG   r   r   r   r   rZ   )r%   r   r#   r$   randintr&   r   Z_mgrblocksr   r   Ztaker'   r   r   r   r   )r(   Zdf1df2Zdf3r3   r2   r4   r4   r5    test_shift_axis1_multiple_blocks   s     z3TestDataFrameShift.test_shift_axis1_multiple_blocksz)ignore:tshift is deprecated:FutureWarningc             C   sf  t j }|jd}|jd}t j|| |jdd}t j|| |jtj d}t j|| d}tjt|d |jdd W d Q R X |jd}|jd}t j|| |j|j	j
d}t j|| t|jttj|j	|jd}|jd}|jd}	|	j	jd |	_	t j||	 |jd}t j|| |jdd	d
gd d f }
d}tjt|d |
j  W d Q R X d S )Nr   r   )r
   z.Given freq M does not match PeriodIndex freq B)r   M)r   r   r      z6Freq was not set in the index hence cannot be inferredr   r   r   )r   r   tshiftr   r   r   r    r!   r"   r   r
   r   r   r   r#   asarrayr   
_with_freqr   )r(   r)   r,   r-   r*   r.   r/   r0   inferred_tsr2   no_freqr4   r4   r5   test_tshift   s<    







zTestDataFrameShift.test_tshiftc          	   C   s"   t jt |j  W d Q R X d S )N)r   assert_produces_warningFutureWarningra   )r(   r)   r4   r4   r5   test_tshift_deprecated   s    z)TestDataFrameShift.test_tshift_deprecatedc             C   sh   t j }|jddd}|jddd}t j|| |jdd}t j|| |jtj d}t j|| d S )Nr   infer)r
   r   r   )r   r   r   r   r   r   )r(   r,   r-   r*   r.   r/   r4   r4   r5   'test_period_index_frame_shift_with_freq   s    z:TestDataFrameShift.test_period_index_frame_shift_with_freqc             C   s   |j ddd}|j ddd}tj|| |j |jjd}tj|| t|jttj	|j|j
d}|j ddd}|j ddd}|jjd |_tj|| |j ddd}tj|| d S )Nr   rj   )r
   )r   r   r   )r   r   r   r   r
   r   r   r   r#   rb   r   rc   )r(   r)   r-   r*   r.   rd   r2   r4   r4   r5   #test_datetime_frame_shift_with_freq   s    
z6TestDataFrameShift.test_datetime_frame_shift_with_freqc          
   C   s6   t j }d}tjt|d |jdd W d Q R X d S )Nz.Given freq M does not match PeriodIndex freq B)r   r_   )r
   )r   r   r    r!   r"   r   )r(   r,   r0   r4   r4   r5   -test_period_index_frame_shift_with_freq_error  s    z@TestDataFrameShift.test_period_index_frame_shift_with_freq_errorc          
   C   sF   |j dddgd d f }d}tjt|d |jdd W d Q R X d S )Nr   r   r`   z6Freq was not set in the index hence cannot be inferred)r   rj   )r
   )r   r    r!   r"   r   )r(   r)   re   r0   r4   r4   r5   )test_datetime_frame_shift_with_freq_error  s    z<TestDataFrameShift.test_datetime_frame_shift_with_freq_errorc             C   s   t jt jdt jdg}|j }tjt |jddd}W d Q R X t jt jd|d gj }tj|| t j	||d}|j
  tjt |jdddd}W d Q R X t j	t jdt jdg|d d}tj|| d S )	Nz
2020-01-01z
2020-01-02r   r   )rK   )r	   r   )r   rK   r	   )r%   r   	TimestampZto_framer   rg   rh   r   r   r   Z_consolidate_inplace)r(   Zserr1   r3   r2   r]   r4   r4   r5   )test_shift_dt64values_int_fill_deprecated  s     z<TestDataFrameShift.test_shift_dt64values_int_fill_deprecatedN)__name__
__module____qualname__r6   r>   rF   rM   rN   rX   r^   r    markfilterwarningsrf   ri   rk   rl   rm   rn   rp   r4   r4   r4   r5   r   	   s   J		1r   )Znumpyr#   r    Zpandasr%   r   r   r   r   r   Zpandas._testingZ_testingr   r   r4   r4   r4   r5   <module>   s
   
