o
    õ­dÜ1  ã                   @   s¦   d dl mZ d dlmZ d dlZd dlZd dlmZm	Z	m
Z
mZmZmZmZmZ d dlmZ G 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S )é    )Úproduct)Úascii_lowercaseN)Ú	DataFrameÚIndexÚ
MultiIndexÚPeriodÚSeriesÚ	TimedeltaÚ	TimestampÚ
date_rangec                   @   s  e Z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d„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zej d#d$d%„ ed&d'ƒD ƒd(d%„ ed&d'ƒD ƒd)d%„ ed&d'ƒD ƒd*d%„ ed&d'ƒD ƒd+d%„ ed&d'ƒD ƒg¡d,d-„ ƒZd.d/„ Zd0d1„ Zd2d3„ Zd4S )5ÚTestCountingc                 C   sb   t dgdgdgdgdggdgd}| d¡}|j}tg d¢ƒ}t || ¡ ¡ t || ¡ ¡ d S )NÚaÚbÚA©Úcolumns©r   é   é   r   é   ©r   Úgroupbyr   r   ÚtmÚassert_series_equalÚcumcount©ÚselfÚdfÚgÚsgÚexpected© r!   úg/var/www/html/visualizacion-main/env/lib/python3.10/site-packages/pandas/tests/groupby/test_counting.pyÚtest_cumcount   s   "
zTestCounting.test_cumcountc                 C   óN   t ƒ jdd}ttdjdd}tdd}t || ¡ ¡ t || ¡ ¡ d S ©Nr   )Úlevel©ÚdtypeÚint64)r   r   r   Úobjectr   r   r   ©r   ÚgeÚseÚer!   r!   r"   Útest_cumcount_empty   ó
   
z TestCounting.test_cumcount_emptyc                 C   st   t dgdgdgdgdggdgdgd d}| d¡}|j}tg d¢dgd d}t || ¡ ¡ t || ¡ ¡ d S )	Nr   r   r   r   é   ©r   Úindexr   ©r3   r   r   r!   r!   r"   Útest_cumcount_dupe_index)   s   "ÿ
z%TestCounting.test_cumcount_dupe_indexc                 C   s   t  ddgddgddgddgddgg¡}tdgdgdgdgdggdg|d}| d¡}|j}tg d¢|d	}t || ¡ ¡ t || ¡ ¡ d S )
Nr   r   r   r   r   r   r2   r   r4   )	r   Úfrom_tuplesr   r   r   r   r   r   r   ©r   Úmir   r   r   r    r!   r!   r"   Útest_cumcount_mi5   s   ($
zTestCounting.test_cumcount_mic                 C   sx   t dgdgdgdgdggdgdgd d}| g d¢¡}|j}tg d¢dgd d	}t || ¡ ¡ t || ¡ ¡ d S )
Nr   r   r   r   r1   r2   ©r   r   r   r   r   r   r4   r   r   r!   r!   r"   Útest_cumcount_groupby_not_col@   s   "ÿz*TestCounting.test_cumcount_groupby_not_colc                 C   sP   t dtdƒiƒ}| d¡}|j}tg d¢ƒ}t || ¡ ¡ t || ¡ ¡ d S )Nr   Úaaabar:   ©r   Úlistr   r   r   r   r   Úngroupr   r!   r!   r"   Útest_ngroupL   s   
zTestCounting.test_ngroupc                 C   sT   t dtdƒiƒ}| d¡}|j}ttdƒdd}t || ¡ ¡ t || ¡ ¡ d S )Nr   Úabcder1   r)   r'   )	r   r>   r   r   r   Úranger   r   r?   r   r!   r!   r"   Útest_ngroup_distinctV   s   
z!TestCounting.test_ngroup_distinctc                 C   sT   t ddgd iƒ}| d¡}|j}tdgd ƒ}t || ¡ ¡ t || ¡ ¡ d S )Nr   r   r1   )r   r   r   r   r   r   r?   r   r!   r!   r"   Útest_ngroup_one_group`   s   
z"TestCounting.test_ngroup_one_groupc                 C   r$   r%   )r   r   r   r*   r   r   r?   r+   r!   r!   r"   Útest_ngroup_emptyj   r0   zTestCounting.test_ngroup_emptyc                 C   s@   t dtdƒiƒ}ttdƒƒ}t | |¡ ¡ | |¡ ¡ ¡ d S )Nr   r<   )r   r>   r   r   r   r   r?   )r   r   Úsr!   r!   r"   Ú test_ngroup_series_matches_framet   s   $z-TestCounting.test_ngroup_series_matches_framec                 C   sd   t dtdƒidgd d}| d¡}|j}tg d¢dgd d}t || ¡ ¡ t || ¡ ¡ d S ©Nr   r<   r   r1   r4   r:   r=   r   r!   r!   r"   Útest_ngroup_dupe_indexz   s   
z#TestCounting.test_ngroup_dupe_indexc                 C   s€   t  ddgddgddgddgddgg¡}tdtdƒi|d}| d¡}|j}tg d¢|d}t || 	¡ ¡ t || 	¡ ¡ d S )Nr   r   r   r   r<   r4   r:   )
r   r6   r   r>   r   r   r   r   r   r?   r7   r!   r!   r"   Útest_ngroup_mi„   s   (
zTestCounting.test_ngroup_mic                 C   sh   t dtdƒidgd d}| g d¢¡}|j}tg d¢dgd d}t || ¡ ¡ t || ¡ ¡ d S rH   r=   r   r!   r!   r"   Útest_ngroup_groupby_not_colŽ   s   z(TestCounting.test_ngroup_groupby_not_colc                 C   sx   t g d¢dgd}| dg¡}tg d¢ƒ}tg d¢ƒ}t ||jd | ¡ t ||jdd¡ t ||jd	d¡ d S )
N)r   r   r   r   r   r   r   )r   r   r   r   r   )r   r   r   r   r   r   T)Ú	ascendingF)r   r   r   r   r   Úngroupsr?   )r   r   r   rL   Ú
descendingr!   r!   r"   Útest_ngroup_descending˜   s   z#TestCounting.test_ngroup_descendingc                 C   s€   t ddgddgddgddgddggddgd}| ddg¡}| ¡ }| ¡ }tg d¢ƒ}tg d	¢ƒ}t ||¡ t ||¡ d S )
Nr   ÚxÚyr   r   ÚXr   r   r:   )r   r   r?   r   r   r   r   )r   r   r   Úg_ngroupÚ
g_cumcountÚexpected_ngroupÚexpected_cumcountr!   r!   r"   Útest_ngroup_matches_cumcount£   s    þz)TestCounting.test_ngroup_matches_cumcountc                    sŽ   t tdƒddD ]<‰tdˆiƒ}| dg¡}ttˆƒƒ‰ ‡ fdd„ˆD ƒ}‡fdd„tˆƒD ƒ}t | 	¡ t
|ƒ¡ t | ¡ t
|ƒ¡ qd S )Nr   é   )Úrepeatr   c                    s   g | ]}ˆ   |¡‘qS r!   r4   )Ú.0Úval)Úorderr!   r"   Ú
<listcomp>¹   s    z:TestCounting.test_ngroup_cumcount_pair.<locals>.<listcomp>c                    s"   g | ]\}}ˆ d |…   |¡‘qS ©N)Úcount)rZ   Úir[   )Úpr!   r"   r]   º   ó   " )r   rB   r   r   ÚsortedÚsetÚ	enumerater   r   r?   r   r   )r   r   r   ÚngroupdÚ
cumcountedr!   )r\   ra   r"   Útest_ngroup_cumcount_pair²   s   ÷z&TestCounting.test_ngroup_cumcount_pairc           	      C   sÄ   t j d¡ tdt j tdƒd¡iƒ}|jd|d}d|d< d|d< t|ƒD ]\}\}}||j|j	df< t|j	ƒD ]\}}||j|df< q9q&t
 t|d jƒ| ¡ ¡ t
 t|d jƒ| ¡ ¡ d S )	Nr   r   Úabcdeféd   )ÚsortéÿÿÿÿÚgroup_idÚgroup_index)ÚnpÚrandomÚseedr   Úchoicer>   r   re   Úlocr3   r   r   r   Úvaluesr?   r   )	r   rk   r   r   r`   Ú_ÚgroupÚjÚindr!   r!   r"   Ú"test_ngroup_respects_groupby_order¿   s   ÿz/TestCounting.test_ngroup_respects_groupby_orderÚdatetimelikec                 C   ó   g | ]}t d |d›dƒ‘qS )ú2016-05-Ú02dz 20:09:25+00:00©r
   ©rZ   r`   r!   r!   r"   r]   Ñ   ó    zTestCounting.<listcomp>r   rX   c                 C   r{   )r|   r}   ú	 20:09:25r~   r   r!   r!   r"   r]   Ò   r€   c                 C   s"   g | ]}t d |d›ddd‘qS )r|   r}   r   ÚUTC)Útzr~   r   r!   r!   r"   r]   Ó   rb   c                 C   s   g | ]}t |d d‘qS )Úh)Úunit)r	   ©rZ   rP   r!   r!   r"   r]   Ô   s    c                 C   s   g | ]	}t d d|d‘qS )Ú2Wiá  )ÚfreqÚyearÚmonth)r   r†   r!   r!   r"   r]   Õ   s    c                 C   sP   t g d¢|dœƒ}| d¡ ¡ }t dddgiddgd	}d|j_t ||¡ d S )
N)r   r   r   )rP   rQ   rP   rQ   r   r   r   r   r4   )r   r   r_   r3   Únamer   Úassert_frame_equal)r   rz   r   Úresr    r!   r!   r"   Útest_count_with_datetimelikeÎ   s
   z)TestCounting.test_count_with_datetimelikec                 C   sx   t tjtjgddgddgdœƒ}| ddg¡j ¡ }tg ddggg g gddgd}tg |tjd	d
}t	j
||dd d S )Nr   r   r   r   ©r   ÚBÚCr   r   )ÚlevelsÚcodesÚnamesr‘   )r3   r(   r‹   F)Úcheck_index_type)r   ro   Únanr   r‘   r_   r   r   r)   r   r   )r   r   Úresultr8   r    r!   r!   r"   Ú(test_count_with_only_nans_in_first_groupâ   s
    z5TestCounting.test_count_with_only_nans_in_first_groupc                 C   s^   t g d¢ddtjddgdœƒ}| dg¡ ¡ }t tg d¢dd	d
g d¢id}t ||¡ d S )N)r   r   r   r   r   r1   rX   r   r   )r   r   r   )g        g      @g      @g      @©r‹   r   )r   r   r   r   )r3   Údata)r   ro   ÚNaNr   r_   r   r   rŒ   )r   r   r   r    r!   r!   r"   Ú4test_count_groupby_column_with_nan_in_groupby_columnê   s   ÿzATestCounting.test_count_groupby_column_with_nan_in_groupby_columnc                 C   s‚   t dddd}tt d¡|t d¡gd}| dd„ ¡}| ¡ }tt d¡t d¡|gd}| dd„ ¡}| ¡ }t ||¡ d S )	Nz1/1/2012Ú5miné
   )Ústartrˆ   Úperiodsr4   c                 S   s   | d d dkS )Nr   r   r   r!   ©rP   r!   r!   r"   Ú<lambda>ø   ó    z@TestCounting.test_groupby_count_dateparseerror.<locals>.<lambda>c                 S   s   | d d dkS )Nr   r   r!   r¡   r!   r!   r"   r¢   ü   r£   )r   r   ro   Úaranger   r_   r   r   )r   ÚdrÚserÚgroupedr—   r    r!   r!   r"   Ú!test_groupby_count_dateparseerroró   s   z.TestCounting.test_groupby_count_dateparseerrorN)Ú__name__Ú
__module__Ú__qualname__r#   r/   r5   r9   r;   r@   rC   rD   rE   rG   rI   rJ   rK   rO   rW   rh   ry   ÚpytestÚmarkÚparametrizerB   rŽ   r˜   rœ   r¨   r!   r!   r!   r"   r      s>    








ûþ


	r   c                  C   s\   t tdƒt d¡ d¡dœƒ} tddgtddgdd	d
d}|  d¡j 	¡ }t
 ||¡ d S )NÚababrX   ztimedelta64[ns])r   Údeltr   r   r   r   r™   r°   ©r3   r‹   )r   r>   ro   r¤   Úastyper   r   r   r°   r_   r   r   )r   r    r—   r!   r!   r"   Ú#test_groupby_timedelta_cython_count  s   ÿr³   c                  C   sF  d} t d| d dd}ttj ttƒ| ¡tj dd| ¡tj | ¡ 	d¡tj d	d| ¡tj || ¡tj | ¡ 	d¡tj | ¡ 	d¡tj || ¡tj |d
¡ tj ttƒ| ¡dœ	ƒ}|j
 g d¢¡D ]}tj|jtj | | d ¡|f< qa|d  d¡|d< ddddgfD ]}| |¡ ¡ }| |¡ tj¡j|d
d}t ||¡ qƒd S )Ni €  z
2015-08-30rž   ÚT)r    rˆ   r   r1   r   iöÿÿÿr   )	Ú1stÚ2ndÚ3rdÚ4thÚ5thÚ6thÚ7thÚ8thÚ9th)rµ   r¶   r¸   r½   Úcategoryrµ   r¶   )Úaxis)r   r   ro   rp   rr   r>   r   ÚrandintÚrandnÚroundr   Údropr–   rs   r²   r   r_   Úapplyr   rŒ   )Únr¥   r   ÚcolÚkeyÚleftÚrightr!   r!   r"   Ú
test_count  s,   ÷ÿ ýrÊ   c                  C   s¸   t g d¢dtjdgdtjtjggg d¢d} |  d¡ ¡ }| jddd	 ¡ }t dd
gddggddgddgd}d|j_t || 	¡ ¡ t ||¡ |  d¡d  ¡ }t 
||d ¡ d S )N)r   r   Úfoor   Úbarr   r   r   r   F)Úas_indexr   r   r   r‘   r2   )r   ro   r–   r   r_   r3   r‹   r   rŒ   Úreset_indexr   )r   Úcount_asÚcount_not_asr    Úcount_Br!   r!   r"   Útest_count_non_nulls(  s   þ"rÒ   c                  C   sØ   t dgd dgd  dgd dgd  dœƒ} |  d¡j ¡ }tddgtddgdddd}t ||¡ t dtj	tj	gdgd  dgd dgd  dœƒ} |  d¡j ¡ }td	dgtddgdddd}t ||¡ d S )
Nr   r   r   r   )r   ÚcrÓ   r™   r±   r   )
r   r   r   r_   r   r   r   r   ro   r–   ©r   r—   r    r!   r!   r"   Útest_count_object<  s   .2rÕ   c                  C   s¦   t  t j ddd¡t j ddd¡f¡} t| g d¢d}t j||dk< | ddg¡ ¡ }d	D ]#}|d
  |¡|d
< |d  |¡|d< | ddg¡ ¡ }t	 
||¡ q-d S )Nr   r1   )rj   r   r   )r   r   rÓ   Údr   rÓ   rÖ   )Úfloat32r*   r   r   )ro   Úhstackrp   rÀ   r   r–   r   r_   r²   r   rŒ   )Úvalsr   r    Útr—   r!   r!   r"   Útest_count_cross_typeH  s   ÿürÛ   c                  C   sŠ   t t g d¢tj¡t g d¢tj¡t g d¢tj¡tdƒdœƒ} |  d¡ ¡ }t ddgddgddgdœt	td	ƒdd
d}t
 ||¡ d S )N)r   r   r   rj   )r   r   r   é   )rX   r1   rÜ   é   r¯   )r   r   rÓ   ÚgrprÞ   r   )r   r   rÓ   Úabr™   r4   )r   ro   ÚarrayÚint8Úuint32Úint16r>   r   r_   r   r   rŒ   rÔ   r!   r!   r"   Útest_lower_int_prec_countY  s   üÿ$ÿrä   c                     s„   G dd„ dt ƒ‰G ‡fdd„dƒ‰ t‡ fdd„tdƒD ƒtdƒd	œƒ} |  d
¡ ¡ }tdddgittdƒd
dd}t ||¡ d S )Nc                   @   s   e Zd ZdS )zAtest_count_uses_size_on_exception.<locals>.RaisingObjectExceptionN)r©   rª   r«   r!   r!   r!   r"   ÚRaisingObjectExceptionj  s    rå   c                       s,   e Zd Zdd	‡ fdd„Z‡fdd„Z‡  ZS )
z8test_count_uses_size_on_exception.<locals>.RaisingObjectúI will raise inside CythonÚreturnNc                    s   t ƒ  ¡  || _d S r^   )ÚsuperÚ__init__Úmsg)r   rê   ©Ú	__class__r!   r"   ré   n  s   

zAtest_count_uses_size_on_exception.<locals>.RaisingObject.__init__c                    s
   ˆ | j ƒ‚r^   )rê   )r   Úother©rå   r!   r"   Ú__eq__r  s   
z?test_count_uses_size_on_exception.<locals>.RaisingObject.__eq__)ræ   )rç   N)r©   rª   r«   ré   rï   Ú__classcell__r!   rî   rë   r"   ÚRaisingObjectm  s    rñ   c                    s   g | ]}ˆ ƒ ‘qS r!   r!   )rZ   ru   )rñ   r!   r"   r]   v  s    z5test_count_uses_size_on_exception.<locals>.<listcomp>rX   r¯   )r   rÞ   rÞ   r   r   rß   r™   r4   )	Ú	Exceptionr   rB   r>   r   r_   r   r   rŒ   rÔ   r!   )rñ   rå   r"   Ú!test_count_uses_size_on_exceptioni  s   $	 ró   )Ú	itertoolsr   Ústringr   Únumpyro   r¬   Úpandasr   r   r   r   r   r	   r
   r   Úpandas._testingÚ_testingr   r   r³   rÊ   rÒ   rÕ   rÛ   rä   ró   r!   r!   r!   r"   Ú<module>   s    (
 o	