o
    ҷh                     @   s   d dl Zd dlZd dlmZmZmZmZmZm	Z	 d dl
mZ dd Zdd Zdd Zd	d
 Zdd Zejdedededgedededgg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 ),    N)	DataFrameNaTSeries	Timedelta	Timestamp
date_rangec                     sr   d t dd t D tg dd d} | ddg}t  fddt D td	gd d}|d
}t|| d S )Ni  c                 S   s,   g | ]}|d  |d r|d nt j|fqS       npnan.0i r   _/var/www/html/venv/lib/python3.10/site-packages/pandas/tests/groupby/test_groupby_shift_diff.py
<listcomp>   s   , z2test_group_shift_with_null_key.<locals>.<listcomp>ABZdtypecolumnsindexr   r   c                    s.   g | ]}|d  r| d k r|d nt jqS )r
   r	   r   r   n_rowsr   r   r       s   . r   r   rangefloatgroupbyshifttmassert_frame_equaldfgexpectedresultr   r   r   test_group_shift_with_null_key   s    
r+   c                     sv   d t dd t D tg dd d} | ddg}t  fddt D td	gd d}|jd
dd}t|| d S )N   c                 S   s   g | ]}|d  |d |fqS r   r   r   r   r   r   r   .   s    z4test_group_shift_with_fill_value.<locals>.<listcomp>r   r   r   r   c                    s$   g | ]}| d  k r|d  ndqS )r	   r   r   r   r   r   r   r   6   s   $ r   r   r   
fill_valuer   r&   r   r   r    test_group_shift_with_fill_value*   s    r/   c                  C   sX   t  d} tddg| d}|ddjd }td| i|jd}t	
|| d S )Nns   )adater2   r   r3   name)r   utcnowas_unitr   r"   r#   ilocr   r5   r$   assert_series_equal)now_dtr'   r*   r)   r   r   r   test_group_shift_lose_timezone@   s
   r;   c                 C   sj   t g dg dd| d}|dd  }d}| dv rd	}ttjtjtjd
dg|dd}t|| d S )Nr1      r
   r
   r=   r1   r=   r
         r2   br   r2   rB   r!   int8int16float32rG         ?      @)r   r5   r   r"   diffr   r   r   r$   r9   any_real_numpy_dtyper'   r*   	exp_dtyper)   r   r   r   test_group_diff_real_seriesI   s   rO   c                 C   s   t g dg dg dd| d}|d }d}| dv rd	}t tjtjtjd
dgtjtjtjd
dgd|d}t|| d S )Nr<   r>   )r1   r=   r
   r?      r2   rB   crC   r2   r!   rD   rG   rH   rI         @)rB   rR   )r   r"   rK   r   r   r$   r%   rL   r   r   r   test_group_diff_real_frameV   s$   rT   dataz
2013-01-01z
2013-01-02z
2013-01-03z5 daysz6 daysz7 daysc                 C   sJ   t g d| d}|dd  }ttttdgdd}t|| d S )N)r1   r=   r=   rA   r2   rB   z1 daysr4   )r   r"   rK   r   r   r   r$   r9   rU   r'   r*   r)   r   r   r   test_group_diff_datetimelikem   s   rW   c                  C   sT   t g dg dd} | dd  }ttjtjtjddgdd}t|| d S )Nr<   TTFFTrA   r2   rB   Fr4   rJ   )r'   r*   r)   r   r   r   test_group_diff_bool   s   rY   c                 C   s`   t g dg dd| d}tjtdd |dd   W d    d S 1 s)w   Y  d S )	N)foobarr[   )bazrZ   rZ   rA   rC   z#unsupported operand type\(s\) for -matchr2   rB   )r   pytestraises	TypeErrorr"   rK   )object_dtyper'   r   r   r   test_group_diff_object_raises   s   "rc   c                  C   sV   t g dd} | dgd}| dgjddd}t|| t|j|j d S )NrQ   r   r2   r1   r   r-   r   r"   r#   r$   r%   assert_index_equalr   r'   shiftedshifted_with_fillr   r   r   test_empty_shift_with_fill   s
   rj   c                  C   sZ   t g dd} | ddgd}| ddgjddd}t|| t|j|j d S )NrQ   rd   r2   rB   r1   r   r-   re   rg   r   r   r   $test_multindex_empty_shift_with_fill   s
   rk   c                  C   s`   g dg dd} t | tdddd}||jjdd	d
}t | tdddd}t|| d S )Nr1   r=   r
   r?   r@   rP   r   r   r   r1   r1   r1   rA   20100101rP   startperiodsr   Drq   freqz
2009-12-30)r   r   r"   r   r#   r$   r%   rV   r   r   r   test_shift_periods_freq   s
   rw   c                  C   sv   g dg dd} t | tdddd}d}tjt|d	 ||jjd
ddd W d    d S 1 s4w   Y  d S )Nrl   rm   rA   rn   rP   ro   rr   MPassing a 'freq' together with a 'fill_value' silently ignores the fill_valuer]   rs   rt   1)rq   rv   r.   )r   r   r$   assert_produces_warningFutureWarningr"   r   r#   rU   r'   msgr   r   r   (test_shift_deprecate_freq_and_fill_value   s   "r~   c                  C   sf   g dg dd} t | }d}tjt|d |djddd	 W d    d S 1 s,w   Y  d S )
Nrl   rm   rA   z/Cannot specify `suffix` if `periods` is an int.r]   rB   r1   fails)suffix)r   r_   r`   
ValueErrorr"   r#   r|   r   r   r   ,test_shift_disallow_suffix_if_periods_is_int   s   "r   c                  C   s   t g dg dd} | ddg ddg}t g dtjdtjd	d
gd}t|| | dd ddg}t|| d S )Nr<   rX   rA   rB   r2   r   r1   rH   rI          @a_0a_1)r   r"   r#   r   r   r$   r%   )r'   
shifted_dfexpected_dfshifted_seriesr   r   r   &test_group_shift_with_multiple_periods   s   r   c                  C   s   t g dg ddtddddd} | d	d
g jddgdd}t dddddtjgtjdddddgdtddddd}t|| d S )Nr>   rX   rA   1/1/2000r@   Hru   rr   rB   r2   r   r1   )rv   rH   r   rI   rS   g      @r   rP   )r   r   r"   r#   r   r   r$   r%   r'   r   r   r   r   r   /test_group_shift_with_multiple_periods_and_freq   s*   r   c                  C   sZ   t g dg dd} | ddg jddgdd	}t g dg d
d}t|| d S )Nr>   rX   rA   rB   r2   r   r1   r   r-   )r   r1   r   r
   r=   r   )r   r"   r#   r$   r%   r   r   r   r   5test_group_shift_with_multiple_periods_and_fill_value   s   r   c                  C   s|   t g dg ddtddddd} d	}tjt|d
 | ddg jddgddd W d    d S 1 s7w   Y  d S )Nr>   rX   rA   r   r@   r   ru   rr   rx   r]   rB   r2   r1   r=   )r.   rv   )r   r   r$   rz   r{   r"   r#   )r'   r}   r   r   r   Htest_group_shift_with_multiple_periods_and_both_fill_and_freq_deprecated   s   ""r   ) numpyr   r_   pandasr   r   r   r   r   r   pandas._testing_testingr$   r+   r/   r;   rO   rT   markparametrizerW   rY   rc   rj   rk   rw   r~   r   r   r   r   r   r   r   r   r   <module>   s<     	
				