3
Ud31                 @   sp   d dl Zd dlZd dlmZ d dlZd dlmZmZm	Z	m
Z
mZmZmZ d dljZd dlmZ G dd dZdS )    N)NullFrequencyError)DatetimeIndexIndexNaTSeriesTimedeltaIndex
date_rangeoffsets)BDayc               @   s   e Z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d Zdd Zdd Zej	jd d!d"d#d$gd%d& Zej	jd'ejd.d)g fejd/d)ejd*gfgd+d, Zd-S )0	TestShiftc             C   s  |j d}|j d}tj|j|j tj|j|j tj|j j|jd d  t }|j d|d}|j d|d}tj|| |j d|d}tj|| |j ddd}|j ddd}tj|| |j d}tj|| tj	 }|j d}|j d}tj|j|j tj|j|j tj|j j|jd d   |j dd}|j dt }tj|| tj||j d!d d}t
jt|d |j dd W d Q R X |j ddd}	tj||	 |j dt d}
tj|
|	 tdd	d
}x^d"D ]V}ttjd	|d|d}|jd }|j |d
}ttjddddg|d}tj|| qW ttdd	dddd}||j   }ttdgdgd  dd}tj|| ttdd	dddd}d}t
jt|d ||  W d Q R X d S )#N   )freqr   Bz.Given freq D does not match PeriodIndex freq B)matchDz
2000-01-01   )periodsint32int64)dtype)index      z2000-01-01 09:00:00z
US/Eastern)r   tzZfoo)namer   z1 days   ZCETzFDatetimeArray subtraction must have the same timezones or no timezonesr   r   r   r   r   r   )r   r   )shifttmassert_index_equalr   Zassert_numpy_array_equaldropnavaluesr
   assert_series_equalmakePeriodSeriespytestraises
ValueErrorr   r   nparangeilocnanr   	TypeError)selfdatetime_seriesshifted	unshiftedoffsetpsshifted2shifted3msgZshifted4Zshifted5r   r   s1presultexpectedsexps2 r<   Z/var/www/html/virt/lib64/python3.6/site-packages/pandas/tests/series/methods/test_shift.py
test_shift   sd    






zTestShift.test_shiftc          	   C   s   t tjjdtddddd}|jddd}|jjddd}tj|j| |jdd	d}|jt	j
d
 }tj|j| tdddg}d}tjt|d |jd W d Q R X d S )Nr   z1/1/2000H)r   r   )r   r   Z5T)r   Z4Hr   z
2000-01-01z
2000-01-02z
2000-01-04zCannot shift with no freq)r   )r   r'   randomZrandnr   r   r   r   r   r	   ZHourr   r$   r%   r   )r,   tsr7   Z	exp_indexidxr4   r<   r<   r=   test_shift2d   s    zTestShift.test_shift2c             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|| tj dddg}|jddd}|j|jkstd S )Ng      ?g       @g      @g      @g      @z1/1/2000r   r?   )r   r   )r   g        r   )
fill_valuer   r   r   )r   r   r   r   r"   pdr   AssertionError)r,   rA   r:   r7   resr<   r<   r=   test_shift_fill_valuew   s    zTestShift.test_shift_fill_valuec             C   s   t jddddgdd}|jddd}t jt jddddgddddgd	d
}tj|| d}tjt|d |jddd W d Q R X d S )Nabcdcategory)r   r   )rD   F)
categoriesZorderedz>'fill_value=f' is not present in this Categorical's categories)r   f)	rE   r   r   ZCategoricalr   Zassert_equalr$   r%   r&   )r,   rA   rG   r8   r4   r<   r<   r=   !test_shift_categorical_fill_value   s    z+TestShift.test_shift_categorical_fill_valuec             C   s  t ddddd}t|}|jd}tj|| |jdks<t|jd}tg|jt	j
j d d	  }t|}tj|| |jdkst|jd}|jt	j
j d
d  ttg }t|}tj|| |jdkstxBdD ]:}|j|}ttgd dd}tj|| |jdkstqW d S )Nz
2016-11-06r?   
   z
US/Eastern)r   r   r   r   zdatetime64[ns, US/Eastern]r   	   r      )r   )rQ   rU   rS   rV   )r   r   r   r   r"   r   rF   r   astypeobjectr!   tolist)r,   datesr9   rG   Zexp_valsr:   exr<   r<   r=   test_shift_dst   s(    


 

zTestShift.test_shift_dstz)ignore:tshift is deprecated:FutureWarningc             C   sX  t j }|jd}|jd}t j|| |jdd}t j|| |jt 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dd}|jd}|jd}	|	jjd |	_t j||	 |jd}t j|| |d	d
dg }
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   MrA   )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'   asarray
_with_freq)r,   r-   r1   r.   r/   r2   r3   r4   inferred_tsr8   no_freqr<   r<   r=   test_tshift   s8    






zTestShift.test_tshiftc          	   C   s"   t jt |j  W d Q R X d S )N)r   assert_produces_warningFutureWarningr_   )r,   r-   r<   r<   r=   test_tshift_deprecated   s    z TestShift.test_tshift_deprecatedc             C   sf   t j }|jddd}|jddd}t j|| |jdd}t j|| |jt d}t j|| d S )Nr   infer)r   r   r   )r   r#   r   r"   r
   )r,   r1   r.   r/   r2   r3   r<   r<   r=   (test_period_index_series_shift_with_freq   s    z2TestShift.test_period_index_series_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dd}|j ddd}|j ddd}|jj
d |_tj|| |j ddd}tj|| d S )Nr   rh   )r   rA   )r   r   r   )r   r   r"   r   r   r   r!   r   r'   r`   ra   )r,   r-   r.   r/   r2   rb   r8   r<   r<   r=   $test_datetime_series_shift_with_freq   s    z.TestShift.test_datetime_series_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,   r1   r4   r<   r<   r=   .test_period_index_series_shift_with_freq_error  s    z8TestShift.test_period_index_series_shift_with_freq_errorc          
   C   s<   |dddg }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   rh   )r   )r$   r%   r&   r   )r,   r-   rc   r4   r<   r<   r=   *test_datetime_series_shift_with_freq_error  s    z4TestShift.test_datetime_series_shift_with_freq_errorc             C   s4   |j t}|jd}|j tjd}tj|| d S )Nr   )rW   intr   floatr   r"   )r,   r-   rA   r.   r8   r<   r<   r=   test_shift_int  s    

zTestShift.test_shift_intc             C   s   t td}tjtdd |jdg d W d Q R X |j }tjtdd |jdtjdd W d Q R X |j	t
}|jdi d}|d i kst|j }|jdi d}|jd i kstd S )Nr   zfill_value must be a scalar)r   r   )rD   r   )r   r   )r   ranger$   r%   r&   r   Zto_framer'   r(   rW   rX   rF   r)   )r,   serdfZobj_serr7   Zobj_dfr<   r<   r=   !test_shift_object_non_scalar_fill  s    
z+TestShift.test_shift_object_non_scalar_fillc             C   s.  t jddddgdd}tj|jd d	 |jdjd
j  |jd}tj|j|j t	j
|jjd d dksttt	j
|jjd d |jjdd  kst|jd}tj|j|j t	j
|jjdd  dkstt	j
|jjdd  |jjd d ksttj|jj|jj tj|jj|jj d S )NrI   rJ   rK   rL   rM   )r   r   r   r   r   r   r   rT   rT   r   rT   )rE   r   r   r"   r)   r   r    r   r   r'   allr!   codesrF   rN   )r,   r9   Zsp1Zsn2r<   r<   r=   test_shift_categorical/  s    &
*
,z TestShift.test_shift_categoricalc             C   sf   t jt jdt jdg}tjt |jddd}W d Q R X t jt jd|d g}tj|| d S )Nz
2020-01-01z
2020-01-02r   r   )rD   )rE   r   	Timestampr   re   rf   r   r"   )r,   rq   r7   r8   r<   r<   r=   )test_shift_dt64values_int_fill_deprecatedB  s
    z3TestShift.test_shift_dt64values_int_fill_deprecatedr   r   r   r   r   c             C   sX   t jt|t jd|ddd}|jdd}t jt|t jd|ddd}tj|| d S )Nz2016-1-1 00:00:00r?   )r   r   )r   r   Z2Hz2016-1-1 02:00:00)rE   r   rp   r   r   r   r"   )r,   r   rq   r7   r8   r<   r<   r=   test_shift_preserve_freqstrL  s    z%TestShift.test_shift_preserve_freqstrzinput_data, output_datar   )shapeg      ?c             C   s:   |j dd tj|jd}tj|dd}tj|| d S )NF)writer   Zfloat64)r   )ZsetflagsrE   r   r   r   r"   )r,   Z
input_dataZoutput_datar7   r8   r<   r<   r=   test_shift_non_writable_array\  s    z'TestShift.test_shift_non_writable_arrayN)r   )r   )__name__
__module____qualname__r>   rC   rH   rP   r\   r$   markfilterwarningsrd   rg   ri   rj   rk   rl   ro   rs   rv   rx   Zparametrizery   r'   emptyZonesr*   r|   r<   r<   r<   r=   r      s&   N.
r   )Znumpyr'   r$   Zpandas.errorsr   ZpandasrE   r   r   r   r   r   r   r	   Zpandas._testingZ_testingr   Zpandas.tseries.offsetsr
   r   r<   r<   r<   r=   <module>   s   $	
