HOME


sh-3ll 1.0
DIR:/usr/local/lib64/python3.6/site-packages/pandas/tests/groupby/__pycache__/
Upload File :
Current File : //usr/local/lib64/python3.6/site-packages/pandas/tests/groupby/__pycache__/test_nth.cpython-36.pyc
3

���hxR�@s
ddlZddlZddlZddlmZmZmZmZm	Z	m
Z
ddljZ
dd�Zejjdddg�dd	��Zejjd
ddXg�dd
��Zejjdddg�dd��Zejjdddg�ejjdedddejgd��eddgiedgdd�d�fedejgd�ed�eddgiedgdd�d�fg�dd���Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zejjd%d&ge	d'd(d)�dgd*�d&ge	d'd(d)�dgd*�d&ge	d'd(d)�dgd*�fd&d+d&ge	d,d-d)�e	d'd(d)�e	d.d/d)�gdd0d1gd*�d&d+ge	d,d-d)�e	d'd(d)�gdd0gd*�d&d+ge	d.d/d)�e	d'd(d)�gd1d0gd*�fg�d2d3��Zejjd4de	d5d6d)�dgde	d7d6d)�d8gg�d9d:��Zejjd;ejd<d=gd>d�ejdd0gd?d�ejd@dAg�ej dd0gdBdC�g�ejjdDdddEdFg�dGdH���Z!dIdJ�Z"dKdL�Z#dMdN�Z$dOdP�Z%dQdR�Z&ejjdSddTdUg�dVdW��Z'dS)Y�N)�	DataFrame�Index�
MultiIndex�Series�	Timestamp�isnacCs|jd�}|j�}|jddgdddgf}tddgdd	�|_|j�}tj||�|jd�}tj||�|j	�}|jd
dgdddgf}tddgdd	�|_tj||�|jd�}tj||�|jd�}|jdd
gdddgfj
�}tddgdd	�|_|j�}tj||�|dj�|dj	�|djd�tj|j|ddkdf<t
|dj�d��s^t�t
|dj	�d��sxt�t
|djd�d��s�t�tdtjgddgd
dggddgd�}|jd�}|j�}|jddgjd�}tj||�|jddgjd�}|jddd�}tj||�dS)N�A�r�B�C�D�bar�foo)�name������)�columns�any)�dropna���)�groupby�first�locr�index�
sort_index�tm�assert_frame_equal�nth�last�copy�np�nanr�AssertionErrorr�iloc�	set_index)�df�groupedr�expectedr!r"�g�result�r.�?/tmp/pip-build-5_djhm0z/pandas/pandas/tests/groupby/test_nth.py�test_first_last_nth	sD



$
r0�methodrr"cCs�tjddddgddd|gd��jd�}t||��}|dkrDddg}nddg}tj||djd�}tjddgdd	�}tjd|i|d
�}tj	||�dS)Nr	rr)�a�br2rr3)�dtype)r)r)
�pdrr�getattrr$�arrayr4rrr )r1�
nulls_fixture�groupsr-�values�idxr+r.r.r/�test_first_last_with_na_object9s 
r<rr	cCs�tjddddgddd|gd��jd�}|j|�}|dkrBddg}nd|g}tj||djd�}tjddgdd	�}tjd|i|d
�}tj	||�dS)Nr	rr)r2r3r2rr3)r4)r)r)
r5rrr!r$r7r4rrr )rr8r9r-r:r;r+r.r.r/�test_nth_with_na_objectMs 

r=cCs@tjjdgdgd��}|jddd�}t||��}tj||�dS)Nr2)�id�valuer>F)�as_index)r5rZ	from_dictrr6rr )r1r)r9r-r.r.r/�test_first_last_with_NoneasrAzdf, expectedr2r)r>r?r?r>)r)r)r4cCs"t|jd�|��}tj||�dS)Nr>)r6rrr )r1r)r+r-r.r.r/�"test_first_last_with_None_expandedlsrBc
Cs^|j�}d|d<d|d<|jd�}|j�}|jddgddd	ddgf}td
dgdd�|_|j�}tj||�|j	�}|jd
dgddd	ddgf}td
dgdd�|_|j�}tj||�|j
d�}|jddgddd	ddgf}td
dgdd�|_|j�}tj||�ttd��}|j
d�ttd�|dd�}|jdk�s:t�|jdd�j�}	|	jdk�sZt�dS)NT�Er	�Frrr
rrr
r)rrrrr�
�	�ZIntCol)�datarr�int64)�level)r#rrrrrrrr r"r!�list�range�appendrr4r&)
Zdf_mixed_floatsr)r*rr+r"r!r;�s�fr.r.r/�test_first_last_nth_dtypes�s2


rPcCs�tjdgtjtjgtd�d��}|jd�}|jd�j}t	j
|jj�|�t	j
|jj�|�t	j
|jj
d�|�t	j
|jj
d�|�dS)Nr)r4)rH�nansrHr	rr)r5rrr$r%�objectrr(rQr�assert_series_equalrr"r!)r)r*r+r.r.r/�test_first_last_nth_nan_dtype�s 
rTc
Cs�tjtjd�ddgtjd�ddgdddgd	d
dgi�}|jd�j�}tddd
ggttd�td
�d	g�tdgdd�d�}tj||�dS)Nz2012-01-01 00:00:00r2r3z2012-01-02 00:00:00�c�dr�eZaaaarOr,z
2012-01-01z
2012-01-02)r)rr)r5rrrrrrr )�testr-r+r.r.r/�test_first_strings_timestamps�s
rYcCstdtjgddgddggddgd�}|jd�}tj|jd�|jdd	gjd��tj|jd�|jdgjd��tj|jd	�|j	gjd��tj|jdC�|jdd	gjd��tj|jdD�|jdgjd��tj|jdE�|j	gjd��tj
|jjd�|jd�jjdd	g�tj
|jjd�|jd�jjdg�tj|dgjd�|j	dd	gddgfjd��|jd�}tj|jddd�|jdd	g�tj|jdFdd�|jdd	g�tj|d<tj|jd
dd�|jdd	g�tj|jd	dd�|jdd	g�tdddddd�dddddd�ddGdHddd�ddIddJdd�d��jdd g�}|jdd!d"�jd	�}|jdKg}tj||�|jdd!d"�jd
�}|j	g}tj||�ttjj
dd#dL�d%d&�}|d}|d}|j|�j�}|j|�jd'd(��}tj
||d!d)�|jdk�st�|jdk�st�||dkjd}|jd|k�s>t�|jd|k�sRt�|j|d!d*�j�}|j|d!d*�jdd+d�}tj
||�tjtd,d-��|j|d!d*�jdd.d�WdQRXtdtjgddgddggddgd�}|jd�}|jjdd+d�}|jj�}tj
||�tdtjgdd
gddgddgdd
ggddgd�}|jd�}tj|jd�|jdd
gjd��tj|jdg�|jdd
gjd��tj|jddg�|jddd
dgjd��tj|jddMg�|jdd	d
dgjd��tj|jddd	g�|jddd	d
dgjd��tj|jdddNg�|jddd	d
dgjd��tj|jd	g�|jd	gjd��tj|jd
dg�|j	gjd��tjd/d0dd1�}td|d2d3gd4�}|jj|jjg}	|j|	d!d5�jdd
dOdPg�}tjd6d7d8d9d:d;d<d=d>d?d@dAg�}
tdd2d3g|
dB�}tj||�dS)QNr	rrrrr
)rrrrr)rrZgreenZred)rr	rrrZham�eggsZporkg�I|���?g�oB!�?gHk:!4@gn�2d��?gC8fٓ��?g�W���?gV���,�?gN'��r��?g�GĔH"�?g���(	��?)�color�food�two�oner[r\F)rJr@rE�drI)r4cSs
|jdS)Nr)r')�xr.r.r/�<lambda>�sztest_nth.<locals>.<lambda>)Zcheck_names)�sort�allzFor a DataFrame groupby)�matchTz4/1/2014z	6/30/2014)�start�end�freqr2r3)rr)r@z2014/4/1z2014/4/4z	2014/4/29z	2014/4/30z2014/5/1z2014/5/6z	2014/5/29z	2014/5/30z2014/6/2z2014/6/5z	2014/6/27z	2014/6/30)rrr������rg�oB!��gHk:!4�gV���,�g�GĔH"�r)r_rrrrhr)rr$r%rrr r!r'r(rrSr
�random�randintr�applyrr&�pytestZraises�
ValueErrorr5�
date_ranger�year�month�to_datetime)r)r,�expr-r+rNZ	expected2�vZbusiness_dates�keyZexpected_datesr.r.r/�test_nth�s�$
" " &$0
  
  

"$

0
"$**..""rvcCs0|jddg�}|jd�}|j�}tj||�dS)Nrr
r)rr!rrr )�three_groupr*r-r+r.r.r/�test_nth_multi_index>s
rxz#data, expected_first, expected_lastrz2012-02-01 14:00:00z
US/Central)�tz)r>�timerr
z2012-01-01 13:00:00zAmerica/New_Yorkz2012-03-01 12:00:00z
Europe/LondonrrcCs�t|�}|jddd�j�}t|�}dddg}tj||||�|jddd�dj�}tj||ddg�|jddd�j�}t|�}dddg}tj||||�|jddd�dj�}tj||ddg�dS)Nr>F)r@rzr)rrrrr r")rHZexpected_firstZ
expected_lastr)r-r+�colsr.r.r/�test_first_last_tzGs6

r|zmethod, ts, alphaz
2013-01-01z
US/Easternz
2013-01-02r3cCs�tjtd��jd�}tjdddg|tjdddd�d	��}t|jd
�|��}tjtj|dg|j	d�|t
d
dd�gd�tjddgd
d�d�}tj
||�dS)N�abc�categoryr	rZ20130101rz
US/Eastern)Zperiodsry)�group�category_string�
datetimetzrrU)r4z
2013-01-03)ry)r�r�)r)r)r5rrK�astyperror6rZCategoricalr4rrrr )r1�ts�alphar�r)r-r+r.r.r/�test_first_last_tz_multi_column�s	r�r:TF�booleanZInt64z
2020-01-01z
2020-02-01r)�unit�function�min�maxc	Cs�tddg|d��}|jd�}tddgdd�}t|d|d�}td|i|d�}t|d|��}tj||�|jd|i�}tj||�dS)	Nr	r)r2r3r2)rr3)rr)r)	rrrrr6rrSZaggr )	r:r�r)r*r;Zexpected_seriesZexpected_frameZ
result_seriesZresult_framer.r.r/�+test_first_last_extension_array_keeps_dtype�s

r�cCs�tdddddddddddgdddddddddddgdddddddddddgd��}|jdd	g�}|jd
�}tdddddgitjddddgddddggdd	gd�d
�}tj||�dS)Nrr
r^r]ZdullZshiny)rr
rrr
rr)�names)r)rrr!rZfrom_arraysrr )rwr*r-r+r.r.r/� test_nth_multi_index_as_expected�sT
r�cCsJtddgddgddggddgd�}|jdd	d
�}|jddd
�}tj|jddg|jd��tj|jddg|jd��t|jtj	g|j
jd
�d�}|dj|j
j�|d<|dj|jj�|d<tj||jd��tj||jd��tj||jd��tj||jd��tj||jd��tj||jd��|}tj|jddg|jd��tj|jddg|jd��t|j
dd�|jd�}|dj|j
j�|d<|dj|jj�|d<tj||jd��tj||jd��tj||jd��tj||jd��tj||jd��tj||jd��tj|gjd�|jddggf�tj|dgjd�|jddgdgf�tj|dgjd�|jddgdgf�tj|ddgjd�|jddg�tj|gjd�|jddggf�tj|dgjd�|jddgdgf�tj|dgjd�|jddgdgf�tj|ddgjd�|jddg�dS)Nr	rrrrrr
)rT)r@Fr)r4)rrr)rrrrrr)rrrr r�head�tailrr5rrr4r�rr
)r)Zg_asZg_not_asZempty_not_asZdf_asZempty_asr.r.r/�test_groupby_head_tailsF"$(($$((r�cCstddgddgddggddgd�}|jd	dgjd�}|jd�}|jdd
�}|jd	�}tj||�tj||�|jd�}|jdd
�}|jd	�}tj||�tj||�|jd�}|jd	�}|jdd
�}tj||�tj||�|jd�}|jd	�}|jdd
�}tj||�tj||�dS)Nr	rrrrrr
)rr)�n)	rr'r(rr�r!rr r�)r)r+r,Zresult1Zresult2r.r.r/�test_group_selection_cache5s,"







r�cCs�tdgdddgd�}|jd�jd�}ttgdd�ddgd�}tj||�|jddg�jd�}ttggggggddgd�dgd�}tj||�dS)	Nrr2r3rU)rrrE)r)r�)rrr!rrr r)r)r-r+r.r.r/�test_nth_emptySs"r�cCs�tdddgdddgddtjgdddgdd	d
ggddd
gd�}|jd�jd�}tddgddggdd
gtddgdd�d�}tj||�|jd�jddd�}tddgd	dggdd
gtddgdd�d�}tj||�dS)Nr	r3r_r2�2rrU��rV�rrr
)rrgY@gi@)r)rrr)rgI@g�b@r)rr$r%rr!rrr )r)r-r+r.r.r/�test_nth_column_orderas,((r�rrrccCs�ttjddgdddgtjddgdd	d
gtjddggtd�d
�}|jd�jd|d�}tjddgd	d
ggtd�tddgdd�d�}tj	||�dS)Nrr	r}rrrr�defrr�rF)rr2)rZbc)r)rr)
rr$r%rKrr!r5rrr )rr)r-r+r.r.r/�test_nth_nan_in_grouperus0(r�r)(Znumpyr$rmZpandasr5rrrrrrZpandas._testingZ_testingrr0�markZparametrizer<r=rAr%rRrBrPrTrYrvrxr|r�r7rrZto_timedeltar�r�r�r�r�r�r�r.r.r.r/�<module>sz 
0,
#|	








 :3