o
    _~#g                     @   sH   d dl Zd dlZd dlmZ dd Zdd Zdd Z	dd	 Z
d
d ZdS )    Nc                  C   s   t g dg ddd} d}tjt|d | jdgdd	d
d }W d    n1 s0w   Y  d}tjt|d | jdgdd	dd }W d    n1 sVw   Y  t|| d S )N)AliceBobCarl)      r   )nameager   7DataFrameGroupBy.apply operated on the grouping columnsmatchr   F
group_keysc                 S   s   | S N groupr   r   /var/www/static.ux5.de/https/Moving-Object-Detection-with-OpenCV/env/lib/python3.10/site-packages/pandas/tests/groupby/test_apply_mutate.py<lambda>   s    z$test_group_by_copy.<locals>.<lambda>c                 S   s   |   S r   )copyr   r   r   r   r      s    )	pd	DataFrame	set_indextmassert_produces_warningDeprecationWarninggroupbyapplyassert_frame_equal)dfmsggrp_by_same_valuegrp_by_copyr   r   r   test_group_by_copy   s(   r"   c               	   C   s(  t dgd dgd  dgd dgd  dgd  d	gd  dgd  dgd  dgd  d
d tddD tjdjdddd} dd }dd }d}tjt	|d | 
d|}W d    n1 shw   Y  tjt	|d | 
d|}W d    n1 sw   Y  t|| d S )Na   b   c   defc                 S   s   g | ]}d | qS )gr   ).0xr   r   r   
<listcomp>*   s    z&test_mutate_groups.<locals>.<listcomp>      d      )size)cat1cat2cat3valc                 S   s,   |   } | jjdd| d< | dd  S Nmin)methodrankr6   )r   r8   r<   r   r:   r.   r   r   r   f_copy/   s   z"test_mutate_groups.<locals>.f_copyc                 S   s$   | j jdd| d< | dd  S r9   )r8   r<   r   r:   r=   r   r   r   	f_no_copy4   s   z%test_mutate_groups.<locals>.f_no_copyr	   r
   r5   )r   r   rangenprandomdefault_rngintegersr   r   r   r   r   assert_series_equal)r   r>   r?   r   
grpby_copygrpby_no_copyr   r   r   test_mutate_groups   s:   rH   c                  C   s   t g dtdd} d}tjt|d | jdddd	d
 }W d    n1 s,w   Y  tjt|d | jddddd
 }W d    n1 sOw   Y  t|| d S )N)	r0   r0   r0   r(   r(   r(      rI   rI   	   )keyvaluer	   r
   rK   Tr   c                 S   s   | d d  j S r   rK   r=   r   r   r   r   H   s    z/test_no_mutate_but_looks_like.<locals>.<lambda>c                 S   s   | j S r   rM   r=   r   r   r   r   J   s    )	r   r   r@   r   r   r   r   r   rE   )r   r   result1result2r   r   r   test_no_mutate_but_looks_like@   s   rP   c                 C   s   t g dg dd}dd }d}tjt||  d |jdgd	d
|}W d    n1 s1w   Y  t jg dt j	g ddd}t
|| d S )N)ArQ   rQ   BrR   rR   )r0   r(   rI         r&   )col1col2c                 S   s   d| j | jd df< | jS )Nr   rV   )locindexrV   r=   r   r   r   fnT   s   z-test_apply_function_with_indexing.<locals>.fnr	   )r   raise_on_extra_warningsrU   F)as_index)r0   r(   r   rS   rT   r   ))r   r   )r   r0   )r   r(   )r0   rI   )r0   rS   )r0   rT   rV   )rY   r   )r   r   r   r   r   r   r   Series
MultiIndexfrom_tuplesrE   )warn_copy_on_writer   rZ   r   resultexpectedr   r   r   !test_apply_function_with_indexingN   s$   rc   c                  C   s   t jg dg dg dg dg dg ddt jg dd} dd }d}tjt|d | jd	d	d
}W d    n1 s?w   Y  ||}t jg dg dg dgt jg dd}t	|| d S )N)r0   r(   rI   )CjulianrR   geoffreyrQ   rf   rR   rf   rQ   rh   re   rh   )ri   rk   rj   rg   rd   rl   )columnsc                 S   s&   | j d d }| jdd| d|f< | S )Nr   r0   )axissum)rm   ro   )groupedr   r   r   r   
add_column~   s   z8test_apply_mutate_columns_multiindex.<locals>.add_columnz+DataFrame.groupby with axis=1 is deprecatedr
   r0   )levelrn   )r0   r0   r0   rI   r0   r0   r0   rI   )r(   r(   r(   r&   r(   r(   r(   r&   )rI   rI   rI   rJ   rI   rI   rI   rJ   ))rh   rQ   rh   )rh   rR   rh   )rh   re   rh   )rh   ro   rh   )rf   rQ   rf   )rf   rR   rf   )rf   re   rf   )rf   ro   rf   )
r   r   r^   r_   r   r   FutureWarningr   r   r   )r   rq   r   gbra   rb   r   r   r   $test_apply_mutate_columns_multiindexg   s8   
ru   )numpyrA   pandasr   pandas._testing_testingr   r"   rH   rP   rc   ru   r   r   r   r   <module>   s    #