U
    >vfAO                     @   sv  d dl Z d dlZd dlZd dlmZmZmZmZ d dl	m
Z
 ejddgddgedddd d d d d	d
d
d
ddg	ed d d d	d
d
d
ddg	eeedd d d d	d
d
d
ddg	ed	d	d	d	d	d
d
d
d
g	ed	d	d	d	d	d
d
d
d
g	edddddddddg	gg
ddd Zejddgddd Zejddddgdd Zejdddgdd Zejdddgejdejejgdd Zejddddgd d! Zejdddgd"d# Zejdddgejdejejgd$d% Zejddddgd&d' Zejdddgd(d) Zejdddgejdejejgd*d+ Zejddddgd,d- Zd.d/ Z dS )0    N)Categorical	DataFrameGrouperSeries)get_groupby_method_argsab)keyc                 C   s   | d S )N    xr   r   D/tmp/pip-unpacked-wheel-vdrwu74i/pandas/tests/groupby/test_raises.py<lambda>       r      r
      	      )paramsc                 C   s   | j S Nparamrequestr   r   r   by   s    r   TFc                 C   s   | j S r   r   r   r   r   r   groupby_series%   s    r   howmethodagg	transformc           	   #   C   s  t dddddddddg	dddddddddg	tdtdd}t||}|j|d}|rz|d	 }|d
krzt|d
rvtd S dddtdfddttfdfttfdfttfdfttfdftdfdddtdftdfddtdftdfdddtdftdftdfdt	dfddtdft	dfdtdfd"| \}}|d krr| dkrDt
|||  n,| dkr`|j|f|  n|j|f|  n`tj||dL | dkrt
|||  n,| dkr|j|f|  n|j|f|  W 5 Q R X d S )Nr   r
   r   r   r   	xyzwtyuior   r   cdr   r$   corrwithN zCould not convertzH(function|cummax) is not (implemented|supported) for (this|object) dtypezH(function|cummin) is not (implemented|supported) for (this|object) dtypezI(function|cumprod) is not (implemented|supported) for (this|object) dtypezH(function|cumsum) is not (implemented|supported) for (this|object) dtypeunsupported operand typez#'argmax' not allowed for this dtypez#'argmin' not allowed for this dtype.Could not convert xy?z?w?t?y?u?i?o? to numericz!could not convert string to floatz0can't multiply sequence by non-int of type 'str'z,cannot be performed against 'object' dtypes!"allanyZbfillr&   countZcumcountZcummaxZcumminZcumprodZcumsumZdiffZffillZfillnafirstZidxmaxZidxminlastmaxmeanZmedianminZngroupZnuniqueZ
pct_changeprodZquantileZrankZsemshiftsizeZskewZstdsumvarr   r   match)r   rangelistr   groupbyhasattrAssertionError	TypeErrorNotImplementedError
ValueErrorgetattrr   r    pytestraises	r   r   r   groupby_funcdfargsgbklassmsgr   r   r   test_groupby_raises_string*   s    
/1




rM   c                 C   s   t dddddddddg	dddddddddg	tdtdd}|j|d}|rV|d	 }d
d }tjtdd t|| | W 5 Q R X d S )Nr   r
   r   r   r   r!   r"   r%   r$   c                 S   s   t dd S NTest error messager@   r   r   r   r   func   s    z,test_groupby_raises_string_udf.<locals>.funcrO   r9   )r   r;   r<   r=   rD   rE   r@   rC   r   r   r   rH   rJ   rQ   r   r   r   test_groupby_raises_string_udf   s    rS   groupby_func_npc                 C   s   t dddddddddg	dddddddddg	tdtdd}|j|d}|rV|d	 }tjd
tjtdfi| \}}|d krt|| | n(t	j
||d t|| | W 5 Q R X d S )Nr   r
   r   r   r   r!   r"   r%   r$   r'   r*   r9   )r   r;   r<   r=   npr7   r2   r@   rC   rD   rE   r   r   r   rT   rH   rJ   rK   rL   r   r   r   test_groupby_raises_string_np   s*      rW   c           	   #   C   s  t dddddddddg	dddddddddg	tdtdddddd	d
d}t||}|j|d}|r|d }|dkrt|drtd S dddtdfddddtdftdfdddddddddddddtdftdfdddddtdfdtdfdd"| \}}|d krH| dkrt|||  n,| dkr6|j	|f|  n|j
|f|  n`tj||dL | dkrrt|||  n,| dkr|j	|f|  n|j
|f|  W 5 Q R X d S )Nr   r
   r   r   r     
         `= r"   r%   r$   r&   r'   z+cannot perform __mul__ with this index typez3datetime64 type does not support cumprod operationsz2datetime64 type does not support cumsum operationsz/cannot perform __truediv__ with this index typez%datetime64 type does not support prodz1dtype datetime64\[ns\] does not support reduction/datetime64 type does not support sum operationsr+   r   r   r9   )r   r;   datetimer   r=   r>   r?   r@   rC   r   r    rD   rE   rF   r   r   r   test_groupby_raises_datetime   s~    
#%




r_   c                 C   s   t dddddddddg	dddddddddg	tdtdddddd	d
d}|j|d}|rd|d }dd }tjtdd t|| | W 5 Q R X d S )Nr   r
   r   r   r   rX   rY   rZ   r[   r\   r"   r%   r$   c                 S   s   t dd S rN   rP   r   r   r   r   rQ     s    z.test_groupby_raises_datetime_udf.<locals>.funcrO   r9   )r   r;   r^   r=   rD   rE   r@   rC   rR   r   r   r    test_groupby_raises_datetime_udf   s    	r`   c                 C   s   t dddddddddg	dddddddddg	tdtdddddd	d
d}|j|d}|rd|d }tjtdftjdi| \}}|d krt|| | n(t	j
||d t|| | W 5 Q R X d S )Nr   r
   r   r   r   rX   rY   rZ   r[   r\   r"   r%   r$   r]   r'   r9   )r   r;   r^   r=   rU   r7   r@   r2   rC   rD   rE   rV   r   r   r   test_groupby_raises_datetime_np  s*      ra   c           
   #   C   s  t dddddddddg	dddddddddg	tdtdddddddddg	dddd	gd
dd}t||}|j|d}|r|d	 }|dkrt|drtd S dddtdfddttfdfttfdfttfdfttfdftdfd|stdfnddddddtdftdfdddtdftdftdfdt	dfddtdft	dftdftdfd "| \}}	|d kr| d!krlt
|||  n,| d"kr|j|f|  n|j|f|  n`tj||	d#L | d!krt
|||  n,| d"kr|j|f|  n|j|f|  W 5 Q R X d S )$Nr   r
   r   r   r   r   r   r#   r$   T
categoriesZorderedr"   r%   r&   r'   =unsupported operand type\(s\) for \*: 'Categorical' and 'int'zz(category type does not support cummax operations|category dtype not supported|cummax is not supported for category dtype)zz(category type does not support cummin operations|category dtype not supported|cummin is not supported for category dtype)z|(category type does not support cumprod operations|category dtype not supported|cumprod is not supported for category dtype)zz(category type does not support cumsum operations|category dtype not supported|cumsum is not supported for category dtype)zDunsupported operand type\(s\) for -: 'Categorical' and 'Categorical'SCannot setitem on a Categorical with a new category \(0\), set the categories firstC'Categorical' with dtype category does not support reduction 'mean'E'Categorical' with dtype category does not support reduction 'median'zDunsupported operand type\(s\) for /: 'Categorical' and 'Categorical'.category type does not support prod operationszNo matching signature found#Cannot cast object dtype to float64C'Categorical' with dtype category does not support reduction 'skew'-category type does not support sum operationsB'Categorical' with dtype category does not support reduction 'var'r+   r   r   r9   )r   r;   r   r   r=   r>   r?   r@   rA   rB   rC   r   r    rD   rE   )
r   r   r   rG   using_copy_on_writerH   rI   rJ   rK   rL   r   r   r   test_groupby_raises_category1  s    

RT




rn   c                 C   s   t dddddddddg	dddddddddg	tdtdddddddddg	dddd	gd
dd}|j|d}|rv|d	 }dd }tjtdd t|| | W 5 Q R X d S )Nr   r
   r   r   r   r   r   r#   r$   Trb   r"   r%   c                 S   s   t dd S rN   rP   r   r   r   r   rQ     s    z.test_groupby_raises_category_udf.<locals>.funcrO   r9   )r   r;   r   r=   rD   rE   r@   rC   rR   r   r   r    test_groupby_raises_category_udf  s"    
ro   c                 C   s   t dddddddddg	dddddddddg	tdtdddddddddg	dddd	gd
dd}|j|d}|rv|d	 }tjtdftjtdfi| \}}|d krt|| | n(t	j
||d t|| | W 5 Q R X d S )Nr   r
   r   r   r   r   r   r#   r$   Trb   r"   r%   rk   rf   r9   )r   r;   r   r=   rU   r7   r@   r2   rC   rD   rE   rV   r   r   r   test_groupby_raises_category_np  s6    
 rp   c              #   C   sH  t tdddddddddg	ddddgdddddddddddg	td	tdddddddddg	ddddgddd
}t||}|j||d}|r|d }|dkrt|drtd S tdd |j	 D }	dddt
dfddtt
fdftt
fdftt
fdftt
fdft
dfd|st
dfndd|	r&tdfnd|	r6tdfndddt
dft
dfdddt
dft
dft
dfdtdfddt
dftdft
dft
d fd!"| \}
}|
d kr| d"krt|||  n,| d#kr|j|f|  n|j|f|  n`tj|
|d$L | d"krt|||  n,| d#kr*|j|f|  n|j|f|  W 5 Q R X d S )%Nr   r   r#   r$   Trb   r   r   r   r"   )r   observedr&   c                 s   s   | ]}|j V  qd S r   )empty).0groupr   r   r   	<genexpr>  s     z;test_groupby_raises_category_on_category.<locals>.<genexpr>r'   rd   zz(cummax is not supported for category dtype|category dtype not supported|category type does not support cummax operations)zz(cummin is not supported for category dtype|category dtype not supported|category type does not support cummin operations)z|(cumprod is not supported for category dtype|category dtype not supported|category type does not support cumprod operations)zz(cumsum is not supported for category dtype|category dtype not supported|category type does not support cumsum operations)r)   re   z*attempt to get argmax of an empty sequencez*attempt to get argmin of an empty sequencerf   rg   rh   r(   ri   rj   rk   rl   r+   r   r   r9   )r   r   r;   r   r=   r>   r?   r-   groupsvaluesr@   rA   rB   rC   r   r    rD   rE   )r   r   r   rG   rq   rm   rH   rI   rJ   Zempty_groupsrK   rL   r   r   r   (test_groupby_raises_category_on_category  s    


PR




rx   c               	   C   sJ   t dgdgdgd} | jddd}tjtdd |d	  W 5 Q R X d S )
Nr   r
   r   )r   r   r#   r   )Zaxisz'Cannot subset columns when using axis=1r9   r   )r   r=   rD   rE   rB   )rH   rJ   r   r   r   %test_subsetting_columns_axis_1_raisest  s    ry   )!r^   ZnumpyrU   rD   Zpandasr   r   r   r   Zpandas.tests.groupbyr   Zfixturearraydictzipr;   r   r   markZparametrizerM   rS   r7   r2   rW   r_   r`   ra   rn   ro   rp   rx   ry   r   r   r   r   <module>   sZ   "2


U

I


"
 