a
    Pff                     @   s  d dl m Z mZ d dlmZ d dl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mZmZmZmZmZmZmZmZmZ d dlmZ d dlmZ d dlm Z  dd Z!G d	d
 d
Z"G dd dZ#G dd dZ$G dd dZ%G dd dZ&G dd dZ'dS )    )datetime	timedelta)DecimalN)Categorical	DataFrameDatetimeIndexIndexNaTPeriodPeriodIndex
RangeIndexSeries	TimedeltaTimedeltaIndex	Timestamp
date_rangeisnaperiod_rangetimedelta_rangeto_timedelta)nanops)ArrowStringArrayNumpySemanticsc                     s   t ddgd ddt tdtjddt tdtjddttddd	ddttddd	ddjd
dtt	ddddddt dd t
dD ddg} tjdd  fdd| D }| | }|S )NTF   a)name
   dtyper   
2020-01-01periodsz
US/EasterntzDr    freqc                 S   s   g | ]}t |qS  )str.0ir&   r&   `/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pandas/tests/reductions/test_reductions.py
<listcomp>-       zget_objs.<locals>.<listcomp>   c                    s   g | ]}t  |d dqS )r   indexr   )r   )r)   idxarrr&   r+   r,   1   r-   )r   nparangeint64float64r   r   tz_localizer   r   rangerandomdefault_rngstandard_normal)ZindexesseriesZobjsr&   r2   r+   get_objs#   s    r>   c                   @   s  e Zd Zejdejdddgejde dd Zejdddgejdd	d
de	dddfddgdd Z
ejdddgdd Zejdddgejdddgdd Zdd Zejdddgddggdd  Zejd!d"d#gd$d% Zd&d' Zd(S ))TestReductionsz8ignore:Period with BDay freq is deprecated:FutureWarningopnamemaxminobjc                 C   s   t || }t|tsHt|jtr8t t|j| }q`t |j| }ntt |j| |j	d}t |dd d ur|
d
d}|j|ksJ n||ksJ d S )N)Zordinalr%   r"   M8[ns]r6   )getattr
isinstancer   valuesr   r4   arrayr
   Zasi8r%   astype_value)selfr@   rC   resultexpectedr&   r&   r+   test_ops8   s    
zTestReductions.test_opsz
dtype, val)object       @)r7   rP   datetime64[ns]        )Int64r.   )booleanTc                    s  |} fdd}|d g d}|t || s2J |t ||ddsJJ |g  d}|t || sjJ |t ||ddsJ  dkrd S |d |g d}t || |ksJ |t ||ddsJ |d |d g d}t || |ksJ |t ||dds
J d S )Nc                    s.    dkr| t u S  dv r"| tju S t| S d S )NrQ   )rU   rV   )r	   pdNAr   )resr   r&   r+   check_missing^   s
    
z4TestReductions.test_nanminmax.<locals>.check_missingrZ   FskipnarO   )rE   )rK   r@   r   valindex_or_seriesklassr[   rC   r&   rZ   r+   test_nanminmaxO   s     zTestReductions.test_nanminmaxc                 C   sN  |}|t u rd| nd| }|ttdddg}t|| dksDJ d}|tu rTd}tjt|d  t||d	d
}W d    n1 s0    Y  |tu rt	|sJ n|dksJ |ttdddtg}t|| dksJ tjt|d  t||d	d
}W d    n1 s0    Y  |tu r<t	|sJJ n|dksJJ d S )Nargr1   rR   rS   rT   zNThe behavior of (DatetimeIndex|Series).argmax/argmin with skipna=False and NAsz2The behavior of Series.(idxmax|idxmin) with all-NAmatchFr\   )
r   r	   r   rE   r   tmassert_produces_warningFutureWarningr4   isnan)rK   r@   r_   r`   arg_oprC   msgrL   r&   r&   r+   test_nanargminmaxz   s(    .0
z TestReductions.test_nanargminmaxr   rD   zdatetime64[ns, UTC]c                 C   s   |}|t u rd| nd| }|g |d}t|| tu s<J t||ddtu sTJ tjtdd t||  W d    n1 s0    Y  tjtdd  t||dd W d    n1 s0    Y  d S )Nrb   r1   rZ   Fr\   zempty sequencerc   )r   rE   r	   pytestraises
ValueError)rK   r@   r_   r   r`   rj   rC   r&   r&   r+   test_nanops_empty_object   s    *z'TestReductions.test_nanops_empty_objectc                 C   s  t tjddd}| dks"J | dks2J t tjdtjdg}| dksVJ | dksfJ d	}tjt|d
$ |jdddksJ W d    n1 s0    Y  tjt|d
$ |jdddksJ W d    n1 s0    Y  t tjg}tjt|d
" | dksJ W d    n1 s20    Y  tjt|d
" | dks^J W d    n1 st0    Y  tjt|d
& |jdddksJ W d    n1 s0    Y  tjt|d
& |jdddksJ W d    n1 s 0    Y  d}t t	t
dddt
dddt	g}| dks@J | dksRJ tjt|d
& |jdddksxJ W d    n1 s0    Y  tjt|d
& |jdddksJ W d    n1 s0    Y  t t	g}tjt|d
" | dks
J W d    n1 s 0    Y  tjt|d
" | dksLJ W d    n1 sb0    Y  tjt|d
& |jdddksJ W d    n1 s0    Y  tjt|d
& |jdddksJ W d    n1 s0    Y  d S )Nr   r6   rZ   r      rT   r.      z=The behavior of Index.argmax/argmin with skipna=False and NAsrc   Fr\   re   zEThe behavior of DatetimeIndex.argmax/argmin with skipna=False and NAsrR   rS   )r   r4   r5   argminargmaxnanrf   rg   rh   r	   r   )rK   rC   rk   r&   r&   r+   test_argminmax   sJ    222266 66
226zTestReductions.test_argminmaxzop, expected_colr   bc                 C   s\   t tdddddgd}|jtdd|d	< t||d
d}|| d }t|| d S )Nz2016-01-01 00:00:00rr   UTC)r    r"   r   )columnsi  secondsrw   rT   axis)	r   r   r   subtractr   rE   renamerf   assert_series_equal)rK   opZexpected_coldfrL   rM   r&   r&   r+   test_same_tz_min_max_axis_1   s    z*TestReductions.test_same_tz_min_max_axis_1funcmaximumminimumc                 C   s>   |}t dg|}t|}tt|||}t|| d S )NZ2019)rW   to_datetimer8   r   rE   r4   rf   r   )rK   Ztz_aware_fixturer   r"   rb   rM   rL   r&   r&   r+   (test_numpy_reduction_with_tz_aware_dtype   s
    z7TestReductions.test_numpy_reduction_with_tz_aware_dtypec                 C   sV   t tddtgddtddtjgddd}ttddd}| }t|| d S )NrT   r.   timedelta64[ns]rZ   rU   ABrr   )	r   r   r	   r4   ru   r   sumrf   r   )rK   r   rM   rL   r&   r&   r+   test_nan_int_timedelta_sum   s    z)TestReductions.test_nan_int_timedelta_sumN)__name__
__module____qualname__rm   markfilterwarningsparametrizer>   rN   r   ra   rl   rp   rv   r   r   r   r&   r&   r&   r+   r?   7   s8   
 
+


r?   c                	   @   s   e Zd Zejdg ddd Zdd Zejddd	gd
d Zdd Z	dd Z
ejdg ddd Zdd Zejddd	gdd Zdd Zdd Zdd Zdd Zejddd	gejd g egeeeggd!d" Zd#d$ Zd%d& Zd'S )(TestIndexReductionszstart,stop,step))r   i  rr   )i  r   i)@B rq   )r   r   )r   r      c                 C   s   t |||}|j }| }||ks*J |jdd}||ksBJ |j }| }||ks`J |jdd}||ksxJ t ||| }t| sJ t| sJ d S NFr\   )r   Z_valuesrA   rB   r   )rK   startstopstepr1   rM   rL   Zresult2r&   r&   r+   test_max_min_range   s    

z&TestIndexReductions.test_max_min_rangec                 C   s   t g d}|jsJ t dtjddg}|jr2J ||fD ]L}| tdksRJ | tdksfJ | dksvJ | dks:J q:d S )N)1 days2 days3 daysr   r   r	   r   r.   )	r   is_monotonic_increasingr4   ru   rB   r   rA   rs   rt   rK   idx1idx2r1   r&   r&   r+   test_minmax_timedelta64  s    

z+TestIndexReductions.test_minmax_timedelta64r   rB   rA   c                 C   s`   t g }t|| tu sJ t tg}t|| tu s:J t tttg}t|| tu s\J d S N)r   rE   r	   rK   r   rC   r&   r&   r+   !test_minmax_timedelta_empty_or_na,  s    
z5TestIndexReductions.test_minmax_timedelta_empty_or_nac                 C   s^  t dddd}t|tdks$J t|tdks:J d}tjt|d tj|dd W d    n1 sp0    Y  tjt|d tj|dd W d    n1 s0    Y  t|dksJ t	|d	ksJ d}tjt|d tj|dd W d    n1 s0    Y  tjt|d tj	|dd W d    n1 sP0    Y  d S )
Nz
16815 daysz
16820 daysr#   r%   $the 'out' parameter is not supportedrc   r   outr   )
r   r4   rB   r   rA   rm   rn   ro   rs   rt   )rK   tderrmsgr&   r&   r+   test_numpy_minmax_timedelta648  s    ,,.z1TestIndexReductions.test_numpy_minmax_timedelta64c                 C   s  t dd tdD }| }| }ttdd}||ks@J |  }|d |ks\J |d}tt	
dd	}||ksJ | }td
}||ksJ |  }|d |ksJ | }td}||ksJ |  }|d |ksJ | }tt | j }||ksJ |  }|d |ks<J t tdtdg}|  tddkslJ t tdtdtdg}|  tddksJ d S )Nc                 S   s"   g | ]}t d t|| d qS Z20130101rz   r   r   r(   r&   r&   r+   r,   Q  r-   z:TestIndexReductions.test_timedelta_ops.<locals>.<listcomp>r   	   rz   r   g?i(
  msz00:00:09z00:01:21z
2015-02-03z
2015-02-07rq   )daysz
2015-02-15   )r   r9   diffmeanr   r   to_frameZquantiler   r4   Ztimedelta64medianr   stddropnarG   r   )rK   sr   rL   rM   r&   r&   r+   test_timedelta_opsM  sB    
z&TestIndexReductions.test_timedelta_opsr@   )ZskewZkurtZsemprodvarc                 C   s   t dd tdD }| }dd| dd| dd	| d
g}tjt|d t||  W d    n1 sv0    Y  tjt|d$ t| |dd W d    n1 s0    Y  d S )Nc                 S   s"   g | ]}t d t|| d qS r   r   r(   r&   r&   r+   r,     r-   zDTestIndexReductions.test_invalid_td64_reductions.<locals>.<listcomp>r   |zreduction operation 'z' not allowed for this dtypezcannot perform z with type timedelta64\[ns\]zdoes not support reduction ''rc   F)Znumeric_only)	r   r9   r   joinrm   rn   	TypeErrorrE   r   )rK   r@   r   r   rk   r&   r&   r+   test_invalid_td64_reductions  s    


*z0TestIndexReductions.test_invalid_td64_reductionsc                 C   s   |}t g d|d}|jsJ t dtddtg|d}|jr>J ||fD ]T}| td|dksbJ | td|dkszJ | dksJ | dksFJ qFd S )N)
2011-01-01
2011-01-02
2011-01-03r!   r   r   r   r   r.   )r   r   r	   rB   r   rA   rs   rt   )rK   Ztz_naive_fixturer"   r   r   r1   r&   r&   r+   test_minmax_tz  s    

z"TestIndexReductions.test_minmax_tzc                 C   s`   t g }tt|| sJ t tg}tt|| s:J t tttg}tt|| s\J d S r   )r   r   rE   r	   r   r&   r&   r+   test_minmax_nat_datetime64  s    
z.TestIndexReductions.test_minmax_nat_datetime64c                 C   s  t g d}|j }t|}||ks,J |j }t|}||ksLJ d}tjt|d tj|dd W d    n1 s0    Y  tjt|d tj|dd W d    n1 s0    Y  |j }t|}||ksJ |j	 }t	|}||ks
J d}tjt|d tj	|dd W d    n1 sB0    Y  tjt|d tj|dd W d    n1 s0    Y  d S )NrT   r.   rr   r   rc   r   r   )
r   rG   rA   r4   rB   rm   rn   ro   rt   rs   )rK   r1   rM   rL   r   r&   r&   r+   test_numpy_minmax_integer  s.    



,,



.z-TestIndexReductions.test_numpy_minmax_integerc                 C   s   t ddd}t|}|dks"J t|}|dks8J d}tjt|d tj|dd W d    n1 sn0    Y  tjt|d tj|dd W d    n1 s0    Y  d S )Nr   r   rr   r   r   rc   r   )r   r4   rA   rB   rm   rn   ro   )rK   r1   rL   r   r&   r&   r+   test_numpy_minmax_range  s    

,z+TestIndexReductions.test_numpy_minmax_rangec                 C   s\  t ddd}t|tdks"J t|tdks8J d}tjt|d tj|dd	 W d    n1 sn0    Y  tjt|d tj|dd	 W d    n1 s0    Y  t|dksJ t	|d
ksJ d}tjt|d tj|dd	 W d    n1 s0    Y  tjt|d tj	|dd	 W d    n1 sN0    Y  d S )N
2016-01-15
2016-01-20r   endz2016-01-15 00:00:00z2016-01-20 00:00:00r   rc   r   r   r   )
r   r4   rB   r   rA   rm   rn   ro   rs   rt   )rK   Zdrr   r&   r&   r+   test_numpy_minmax_datetime64  s    ,,.z0TestIndexReductions.test_numpy_minmax_datetime64c                 C   s   t tdddgdd}|jrJ |dd  js0J t dtddtgdd}|jrPJ ||fD ]4}| tdddkstJ | tdddksXJ qX| dksJ | dksJ | dksJ | d	ksJ d S )
Nr   r   r   r#   r   rT   r   rr   r.   )r   r	   r   rB   r
   rA   rs   rt   r   r&   r&   r+   test_minmax_period  s    

z&TestIndexReductions.test_minmax_perioddatac                 C   s(   t |dd}t|| }|tu s$J d S )NMr   )r   rE   r	   )rK   r   r   rC   rL   r&   r&   r+   test_minmax_period_empty_nat  s    z0TestIndexReductions.test_minmax_period_empty_natc                 C   sd  t ddd}t|tdddks&J t|tdddks@J d}tjt|d tj|dd	 W d    n1 sv0    Y  tjt|d tj|dd	 W d    n1 s0    Y  t|dksJ t	|d
ksJ d}tjt|d tj|dd	 W d    n1 s0    Y  tjt|d tj	|dd	 W d    n1 sV0    Y  d S )Nr   r   r   r#   r   r   rc   r   r   r   )
r   r4   rB   r
   rA   rm   rn   ro   rs   rt   )rK   prr   r&   r&   r+   test_numpy_minmax_period  s    ,,.z,TestIndexReductions.test_numpy_minmax_periodc                 C   s   t jtdtddd}d}tjt|d |  W d    n1 sH0    Y  d}tjt|d |  W d    n1 s0    Y  t jtdtddd}| d	ksJ | d
ksJ d S )NZaabbcaZcabF
categoriesorderedzwCategorical is not ordered for operation min\nyou can use .as_ordered\(\) to change the Categorical to an ordered one\nrc   zwCategorical is not ordered for operation max\nyou can use .as_ordered\(\) to change the Categorical to an ordered one\nTcrw   )rW   ZCategoricalIndexlistrm   rn   r   rB   rA   )rK   cirk   r&   r&   r+   test_min_max_categorical0  s    &&z,TestIndexReductions.test_min_max_categoricalN)r   r   r   rm   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r	   r   r   r   r&   r&   r&   r+   r      s0   


5

 r   c                   @   s  e Zd Zdd Zejdg dejdddgejdd	d
gdd Zejdddgejdg ddd Zejdg ddd Z	dd Z
ejdddgejdddgdd Zejdddgejdddgdd Zd d! Zejd"d#d$gd%d& Zejdd'ejd(ddgd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Zejd=d>d?gejd(ddgd@dA Zejd=d>d?gejdBddCgdCdgdejgejdggdDdE Zejdg dFejd=d>d?gejd(ddgejdGg dHddgddggfg dIddgddggfejejejgejejgddggfdJejdJgejdgddggfdKejdKgdejgddggfdKejdJgddgddggfgdLdM ZdNdO Z dPdQ Z!dRdS Z"dTdU Z#ejdVe$g ddWe%fe$g dXe&fe$dYdZge&fe$d[d[d\d\dCejd]ge&fgd^d_ Z'd`da Z(dbdc Z)ddde Z*dfdg Z+dhdi Z,djdk Z-dldm Z.dCS )nTestSeriesReductionsc              	   C   s  t tjdd}| }tj|dd< tj|dd< t|	 sLJ tjdd
d}tj|d d df< d}tjt|dP td	d
$ t|	 |	  W d    n1 s0    Y  W d    n1 s0    Y  tj|dd}t| s
J d S )Nr.   r   r      )d   r   Zf4"use_inf_as_na option is deprecatedrc   mode.use_inf_as_naTrT   r|   )r   r4   r:   r;   r<   copyinfru   isinfr   rI   rf   rg   rh   rW   option_contextassert_almost_equalr   nansumall)rK   r   s2r3   rk   rY   r&   r&   r+   test_sum_infI  s    Pz!TestSeriesReductions.test_sum_infr   )r7   ZFloat32rU   rV   rO   use_bottleneckTFzmethod, unit)r           )r         ?c                 C   s\  t d|8 tg |d}t|| }||ks4J t||dd}||ksPJ t||dd}t|slJ t||dd}||k t||ddd}||ksJ t||ddd}t|sJ t||d	dd}||ksJ t||d	dd}t|sJ ttjg|d}t|| }||ks&J t||dd}||ksDJ t||dd}t|sbJ t||dd}||k t||ddd}||ksJ t||ddd}t|sJ ttjdg|d}t|| }|d
ksJ t||dd}|d
ksJ t||dd}|d
ks"J t||dd}|d
ks@J t||ddd}|d
ks`J ttd|d}t||d|k	 sJ tdg|d}t||dd}t|sJ t||d	dd}t|sJ ttjg|d}t||dd}t|sJ ttjdg|d}t||dd}t|s8J W d    n1 sN0    Y  d S )Nr   rZ   r   )	min_countrT   Tr\   )r]   r   Fr   )r   r   r.   )
rW   r   r   rE   r   r4   ru   r   emptyr   )rK   methodunitr   r   r   rL   r   r&   r&   r+   
test_empty]  sn    zTestSeriesReductions.test_emptyr   r   r   )Float64rU   rV   c                 C   sT   t g |d}t|| }|tju s&J t tjg|d}t|| }|tju sPJ d S NrZ   )r   rE   rW   rX   r4   ru   )rK   r   r   ZeserrL   Znserr&   r&   r+   &test_ops_consistency_on_empty_nullable  s    z;TestSeriesReductions.test_ops_consistency_on_empty_nullable)r   r   r   r   c                 C   s   t ttd| }t|sJ tg dd}|dkr|dg d}tjt|d t ||  W d    q1 sp0    Y  nt || }|tu sJ d S )NrZ   m8[ns]r   r   )zoperation 'var' not allowedz.cannot perform var with type timedelta64\[ns\]z does not support reduction 'var'rc   )	rE   r   floatr   r   rm   rn   r   r	   )rK   r   rL   Ztdserrk   r&   r&   r+   test_ops_consistency_on_empty  s    ,z2TestSeriesReductions.test_ops_consistency_on_emptyc                 C   s0   t dtjgddgd}t|}t|d d S )Nr   r   rT   r0   )r   r4   ru   r   rf   r   )rK   serrL   r&   r&   r+   test_nansum_buglet  s    
z'TestSeriesReductions.test_nansum_bugletZint32r6   c                 C   s   t d| tjd|d}t|}|jdd}t||jddksHJ |jdd}t|dksdJ |jdd}t||d ksJ W d    n1 s0    Y  d S )	Nr   @KL rZ   Fr\   r6   r   re   )	rW   r   r4   r5   r   r   intrB   rA   rK   r   r   vr   rL   r&   r&   r+   test_sum_overflow_int  s    z*TestSeriesReductions.test_sum_overflow_intZfloat32r7   c                 C   s   t d| tjd|d}t|}|jdd}||j|dksDJ |jdd}tt|dsdJ |j	dd}tt||d sJ W d    n1 s0    Y  d S )Nr   r   rZ   Fr\   r   re   )
rW   r   r4   r5   r   r   rB   Zallcloser   rA   r  r&   r&   r+   test_sum_overflow_float   s    z,TestSeriesReductions.test_sum_overflow_floatc                 C   s\   d}d}t |g| }t|g| dd}t |}| }|| dksLJ |dksXJ d S )Nl     ;r   rU   rZ   r   g ؅W4vC)r4   rH   r   r   )rK   r^   Z
n_elementsnar   Zresult_numpyZresult_maskedr&   r&   r+   test_mean_masked_overflow  s    
z.TestSeriesReductions.test_mean_masked_overflowz	ddof, exp)rT         @)r   rP   c                 C   sT   t g ddd}t g ddd}|j|d}|j|d}||ksDJ ||ksPJ d S )N)rT   r.   rr   rq   r   rU   rZ   r6   )ddof)r   r   )rK   r  expr   Zser_numpy_dtyperL   Zresult_numpy_dtyper&   r&   r+   test_var_masked_array  s    z*TestSeriesReductions.test_var_masked_array)r   r   rD   zM8[ns, UTC]r]   c                 C   s<   t g |dj|dtu sJ t g |dj|dtu s8J d S )NrZ   r\   )r   rB   r	   rA   )rK   r   r]   r&   r&   r+   +test_empty_timeseries_reductions_return_nat$  s    z@TestSeriesReductions.test_empty_timeseries_reductions_return_natc                 C   s   t dd}t||d}t |}t |}||ks8J | }||ksLJ d}tjt|d t j||d W d    n1 s0    Y  d S NrT   rS   r   r   rc   r   )r4   r5   r   rs   rm   rn   ro   )rK   r   r   rL   rM   rk   r&   r&   r+   test_numpy_argmin+  s    

z&TestSeriesReductions.test_numpy_argminc                 C   s   t dd}t||d}t |}t |}||ks8J | }||ksLJ d}tjt|d t j||d W d    n1 s0    Y  d S r  )r4   r5   r   rt   rm   rn   ro   )rK   r   r   rL   rM   rk   r&   r&   r+   test_numpy_argmax=  s    

z&TestSeriesReductions.test_numpy_argmaxc                 C   s  t g d|}tddtjg|d}d}tjt|d |jdd}W d    n1 sZ0    Y  |t	u spJ d	}tjt|d |j
dd}W d    n1 s0    Y  |t	u sJ | }d
}tjt|d |jdd}W d    n1 s0    Y  |jd| dksJ |  s*J d}tjt|d |j
dd}W d    n1 s`0    Y  |jd| dksJ |  sJ d S )N)r	   z
2015-02-08r	   r   rP   r   0The behavior of Series.idxmin with all-NA valuesrc   Fr\   0The behavior of Series.idxmax with all-NA valuesz3The behavior of DataFrame.idxmin with all-NA valueszM8[]z3The behavior of DataFrame.idxmax with all-NA values)r   Zas_unitr   r4   ru   rf   rg   rh   idxminr	   idxmaxr   r   r   r   )rK   r   dtir   rk   rY   r   r&   r&   r+   test_idxmin_dt64indexN  s*    ***,z*TestSeriesReductions.test_idxmin_dt64indexc                 C   sX  t tdtjdd}tj|dd< ||  | ks:J d}tjt	|d$ t
|jdd	sbJ W d    n1 sv0    Y  | }||  | ksJ |jj | |j ksJ |tj }tjt	|d  t
| sJ W d    n1 s0    Y  t td
dd}| }|dks4J tj|d< | }|dksTJ d S )Nr   r=   r   r      zThe behavior of Series.idxminrc   Fr\   20130102r   r   r   rT   )r   r9   r4   r7   ru   r  rB   rf   rg   rh   r   r   r0   rG   tolistrs   r   rK   Zstring_seriesrk   ZnonaZallnar   rL   r&   r&   r+   test_idxming  s$    2$
0
z TestSeriesReductions.test_idxminc                 C   s  t tdtjdd}tj|dd< ||  | ks:J d}tjt	|d$ t
|jdd	sbJ W d    n1 sv0    Y  | }||  | ksJ |jj | |j ksJ |tj }d}tjt	|d  t
| sJ W d    n1 s0    Y  t td
dd}| }|dks8J tj|d< | }|dksXJ t g dg d}| }|dksJ | }|dksJ t |j|j}| }|dksJ | }|dksJ d S )Nr   r=   r   r   r  r  rc   Fr\   r  r   r   rq   r   )皙?g @@r  r  )r   r9   r4   r7   ru   r  rA   rf   rg   rh   r   r   r0   rG   r  rt   r   r  r  r&   r&   r+   test_idxmax  s:    2$
0
z TestSeriesReductions.test_idxmaxc                 C   s^   t tjdtjdtddddd}|dk}| r6J | sBJ t dd	g}| sZJ d S )
Nr   rZ   r   r   tsr/   r   abcT)r   r4   r5   r7   r   r   any)rK   r  Zbool_seriesr   r&   r&   r+   test_all_any  s    
z!TestSeriesReductions.test_all_anyc                 C   sF   |g d}t |rJ t |s(J tg d}t |sBJ d S )N)r   rT   r.   r   )r4   r   r   r   )rK   r_   r1   r&   r&   r+   test_numpy_all_any  s
    z'TestSeriesReductions.test_numpy_all_anyc                 C   s`   t tjdg}t tjdg}|jdds,J |jdds<J |jddsLJ |jddr\J d S )NTFr\   )r   r4   ru   r   r   )rK   s1r   r&   r&   r+   test_all_any_skipna  s    z(TestSeriesReductions.test_all_any_skipnac                 C   s8   t g dg dd}|jdds$J |jddr4J d S )N)FFTTFT)r   r   rT   rT   r.   r.   r   T)	bool_only)r   r   r   )rK   r   r&   r&   r+   test_all_any_bool_only  s    z+TestSeriesReductions.test_all_any_bool_onlybool_agg_funcr   r   c                 C   s4   t g dtd}t|||d}d}||ks0J d S )N)r   rw   r   derZ   r\   T)r   rO   rE   )rK   r'  r]   r   rL   rM   r&   r&   r+   test_any_all_object_dtype  s    z.TestSeriesReductions.test_any_all_object_dtyper   Nc                 C   s8   t |}t||dd}|dko&d |v}||ks4J d S )NFr\   r   )r   rE   )rK   r   r'  r   rL   rM   r&   r&   r+   !test_any_all_object_dtype_missing  s    z6TestSeriesReductions.test_any_all_object_dtype_missing)rV   rU   ZUInt64r   zdata,expected_data)r   r   r   )rT   rT   rT   r   rT   c           	      C   sP   t ||d}|| |dk }t|||d}|tju r@|tju sL||ksLJ d S )NrZ   r   r\   )r   rE   rW   rX   )	rK   r'  r]   r   r   Zexpected_datar   rM   rL   r&   r&   r+   "test_any_all_nullable_kleene_logic  s    z7TestSeriesReductions.test_any_all_nullable_kleene_logicc                 C   s@   t ddgddgd}|jddd}tddg}t|| d S )NTFrT   r.   r   )r}   r%  )r   r   r   rf   r   )rK   r   rL   rM   r&   r&   r+   test_any_axis1_bool_only  s    z-TestSeriesReductions.test_any_axis1_bool_onlyc                 C   s  t dddj}t|}t|}d}tjt|d` | s>J | sJJ | sVJ | sbJ |  srJ |  sJ W d    n1 s0    Y  |	d}t|}t|}tjt|dd | sJ | sJ | sJ | sJ |  sJ |  sJ W d    n1 s40    Y  ||d  }t|}t|}| shJ | rvJ | sJ | rJ |  sJ |  rJ d S )Nz
1995-01-02rr   r   z0'(any|all)' with datetime64 dtypes is deprecatedrc   rx   r   )
r   _datar   r   rf   rg   rh   r   r   r8   )rK   Zdtar   r   rk   Ztdar&   r&   r+   test_any_all_datetimelike  s<    .
2z.TestSeriesReductions.test_any_all_datetimelikec                 C   s   t d tddgdd}| s&J | r2J td dgdd}| sNJ | sZJ |jddrjJ td dgdd}| rJ | rJ tddgdd}| sJ | sJ d S )	NZpyarrow r   zstring[pyarrow_numpy]rZ   Fr\   rw   )rm   Zimportorskipr   r   r   rK   r   r&   r&   r+   test_any_all_pyarrow_stringD  s    
z0TestSeriesReductions.test_any_all_pyarrow_stringc                 C   s  t dddd}t|td }| }|dks2J | }|dksFJ tj|d< | }|dksdJ | }|dksxJ tt ddd	}tt d
dd	}t|| }t|| }t	|| ||  }t	|| |
 }td}||ksJ | }td}||ksJ d S )Nz2012-1-1rr   r#   r$   Z20120101r   r.   rT   r   Z20120102r   r   )r   r   r   r  r  r4   ru   absrf   r   rA   r   rB   )rK   r  r   rL   r#  r   rM   r&   r&   r+   test_timedelta64_analyticsX  s0    
z/TestSeriesReductions.test_timedelta64_analyticsztest_input,error_typerZ   foobarbazrT   r.   r6  r7  r8  c                 C   s   t g dd}d}tjt|d |  W d   n1 s<0    Y  tjt|d |jdd W d   n1 sv0    Y  d}tjt|d |  W d   n1 s0    Y  tjt|d |jdd W d   n1 s0    Y  dS )	zU
        Cases where ``Series.argmax`` and related should raise an exception
        r7   rZ   z*attempt to get argmin of an empty sequencerc   NFr\   z*attempt to get argmax of an empty sequence)r   rm   rn   ro   r  r  )rK   Z
test_inputZ
error_typerk   r&   r&   r+   "test_assert_idxminmax_empty_raises  s    &*&z7TestSeriesReductions.test_assert_idxminmax_empty_raisesc                 C   s  t g d}| dksJ |jdddks0J | dks@J |jdddksTJ t ddg}| dkspJ |jdddksJ | dksJ |jdddksJ |st ddd	d	d tjd
g}d}tjt|d |  W d    n1 s0    Y  tjt|d |jdd W d    n1 s20    Y  d}tjt|d |  W d    n1 sn0    Y  tjt|d |jdd W d    n1 s0    Y  d S )Nr5  r   Fr\   rT   r9  r:  r6  r7  r8  z8'>' not supported between instances of 'float' and 'str'rc   z8'<' not supported between instances of 'float' and 'str')r   r  r  r4   ru   rm   rn   r   )rK   Zusing_infer_stringr   Zser2Zser3rk   r&   r&   r+   test_idxminmax_object_dtype  s,    &,(z0TestSeriesReductions.test_idxminmax_object_dtypec                 C   s>   t ddgddgddgg}| }tddg}t|| d S )	NZzimmr  Zbiffr   bidg      (@r   r.   )r   r  r   rf   r   )rK   r   rY   r	  r&   r&   r+   test_idxminmax_object_frame  s    z0TestSeriesReductions.test_idxminmax_object_framec                 C   sX   t g d}| dksJ | dks,J |jdddks@J |jdddksTJ d S )N))rT   rr   )r.   r.   )rr   rT   r.   r   Fr\   )r   r  r  r1  r&   r&   r+   test_idxminmax_object_tuples  s
    z1TestSeriesReductions.test_idxminmax_object_tuplesc                 C   sp   t ddgtdtdgtdtdgd}| }tdddd}t|| | }|d }t|| d S )Nr   rT   z8.68z42.23z7.11z79.61)r1   xy)r   r   r  r   rf   r   r  )rK   r   rY   r	  Zres2Zexp2r&   r&   r+   test_idxminmax_object_decimals  s    z3TestSeriesReductions.test_idxminmax_object_decimalsc                 C   s\   t ddgdd}| dks J | dks0J |jdddksDJ |jdddksXJ d S )Nr   rT   rO   rZ   Fr\   )r   rt   rs   r1  r&   r&   r+   test_argminmax_object_ints  s
    z/TestSeriesReductions.test_argminmax_object_intsc              	   C   sz  t dtj tjtjg}| dks(J d}tjt|d& t|jddsRJ W d    n1 sf0    Y  |	 dksJ d}tjt|d& t|j	ddsJ W d    n1 s0    Y  d	}tjt|d t
d
d\ | dksJ t|jddsJ |	 dks$J t|j	dd W d    n1 sL0    Y  W d    n1 sl0    Y  d S )Nr   rT   r  rc   Fr\   r.   r  r   r   T)r   r4   r   ru   r  rf   rg   rh   ri   r  rW   r   )rK   r   rk   r&   r&   r+   test_idxminmax_with_inf  s     44z,TestSeriesReductions.test_idxminmax_with_infc                 C   s0   t dgdd}| }td}t|| d S )Nl     9V uint64rZ   )r   r   r4   rE  rf   r   )rK   r   rL   rM   r&   r&   r+   test_sum_uint64  s    
z$TestSeriesReductions.test_sum_uint64)/r   r   r   r   rm   r   r   r   r   r   r   r  r  r  r
  r  r  r  r  r  r  r!  r"  r$  r&  r*  r4   ru   r+  rW   rX   r,  r-  r/  r2  r4  r   ro   r   r;  r<  r>  r?  rB  rC  rD  rF  r&   r&   r&   r+   r   D  s   `

	!/	 	"
/)
r   c                	   @   s   e Zd Zejdeeegeeedgeededggdd Z	ejde
eege
eedge
ededggdd Zdd	 Zd
d ZdS )TestDatetime64SeriesReductionsnat_serZnatc                 C   sL   |  tu sJ | tu s J |j ddtu s4J |jddtu sHJ d S r   rB   r	   rA   )rK   rH  r&   r&   r+   test_minmax_nat_series  s    
z5TestDatetime64SeriesReductions.test_minmax_nat_seriesnat_dfc                 C   s\   |  d tu sJ | d tu s(J |j ddd tu s@J |jddd tu sXJ d S )Nr   Fr\   rI  )rK   rK  r&   r&   r+   test_minmax_nat_dataframe  s    
z8TestDatetime64SeriesReductions.test_minmax_nat_dataframec                 C   s   t dd}|tjdt|}| }| }t	|t
sDJ t	|t
sRJ ||d ksbJ ||d ksrJ | |d ksJ | |d ksJ d S )N1/1/2000z
12/31/2000r.   r   re   )r   Ztaker4   r:   r;   ZpermutationlenrB   rA   rF   r   )rK   rngZrng2Zthe_minZthe_maxr&   r&   r+   test_min_max#  s    
z+TestDatetime64SeriesReductions.test_min_maxc                 C   s   t dddd}g d}t|tjdt||d}|j }t	|jj
d }t|t	s`J ||kslJ |j }t	|jj
d	 }t|t	sJ ||ksJ d S )
NrM  r   Z4hr$   )
r   r   r   r   r   r   CrQ  rQ  rQ  r.   )TSVLre   r   )r   r   r4   r:   r;   r<   rN  rR  rA   r   ZiatrF   rB   )rK   rO  Zlvlsr   rL   r	  r&   r&   r+   test_min_max_series1  s     

z2TestDatetime64SeriesReductions.test_min_max_seriesN)r   r   r   rm   r   r   r   r	   r   rJ  r   rL  rP  rU  r&   r&   r&   r+   rG     s$   



rG  c                   @   s   e Zd Zejdddgdd Zejdededfededfedej	g edfg d	g d
fdddej	gg d
fgejdddgdd Z
ejdddgejdddgdd Zejdddgejdddgdd ZdS )TestCategoricalSeriesReductionsfunctionrB   rA   c                 C   s\   t tg ddd}d| }tjt|d t||  W d    n1 sN0    Y  d S )N)r   rw   r   r(  F)r   z)Categorical is not ordered for operation rc   )r   r   rm   rn   r   rE   )rK   rW  catrk   r&   r&   r+   test_min_max_unordered_raisesL  s    
z=TestCategoricalSeriesReductions.test_min_max_unordered_raiseszvalues, categoriesr  Zcbar   rr   r.   rT   rT   r.   rr   c                 C   sJ   t t||dd}t||dd}|dkr2|d n|d }||ksFJ d S )NTr   r\   rB   r   r.   )r   r   rE   )rK   rG   r   rW  rX  rL   rM   r&   r&   r+   test_min_max_orderedT  s    z4TestCategoricalSeriesReductions.test_min_max_orderedr]   TFc                 C   s<   t ttjgddgdd}t|||d}|tju s8J d S )NrT   r.   Tr   r\   r   r   r4   ru   rE   )rK   rW  r]   rX  rL   r&   r&   r+   "test_min_max_ordered_with_nan_onlyf  s    zBTestCategoricalSeriesReductions.test_min_max_ordered_with_nan_onlyc                 C   sh   t tddtjdgddgdd}t|||d}|du rV|dkrDdnd}||ksdJ n|tju sdJ d S )Nr   rw   Tr   r\   rB   r\  )rK   rW  r]   rX  rL   rM   r&   r&   r+   test_min_max_skipnan  s    z3TestCategoricalSeriesReductions.test_min_max_skipnaN)r   r   r   rm   r   r   rY  r   r4   ru   r[  r]  r^  r&   r&   r&   r+   rV  G  s&   

rV  c                   @   sB  e Zd Zejddeg ejdfdeg ejdfgdd Z	ejddg dd	gfdg d
d	dgfdg dd	gfdg d
d	dgfgejde
ejd ejd  dd Zejdddgfdd	ejgfgdd Zejdddgdgdgfddgejgdgfgdd Zejdddgdgfddgejgfgdd Zejddg ddd gfdejgejdd gfgd!d" Zejddg d#d$d%gfdejgejd$d%gfgd&d' Zejdded	d(gd	d(gd)ed*gd	d*gd)edd	gg d+dd,fdeejgd	d(gd)eejd*gd	d*gd)eejdd	gg d+dd,fgd-d. Zejddd/gd	d/gfdd/gd	d/gfgd0d1 Zd2d3 Zd4d5 Zejd6g d7ed	gejdejfg d7ed	gejdejfg d8ed9gejdejfgd:d; Zejd6g d<eg d=ejdejfg d>ed?d9gejdejfgd@dA ZdBS )CTestSeriesModezdropna, expectedTrZ   Fc                 C   s(   t g tjd}||}t|| d S r   )r   r4   r7   moderf   r   rK   r   rM   r   rL   r&   r&   r+   test_mode_empty  s    
zTestSeriesMode.test_mode_emptyzdropna, data, expected)rT   rT   rT   r.   rT   )rT   rT   rT   r.   rr   rr   rr   rr   dtZ
AllIntegerFloatc                 C   s2   t ||d}||}t ||d}t|| d S r   r   r`  rf   r   )rK   r   r   rM   rc  r   rL   r&   r&   r+   test_mode_numerical  s    
z"TestSeriesMode.test_mode_numericalr   c                 C   s8   t dddtjtjg}||}t |}t|| d S )NrT   r.   )r   r4   ru   r`  rf   r   ra  r&   r&   r+   test_mode_numerical_nan  s    
z&TestSeriesMode.test_mode_numerical_nanz'dropna, expected1, expected2, expected3rw   r7  ru   c                 C   s   dgd dgd  }t |dd}||}t |dd}t|| dddtjtjtjg}t |td}||}t ||dgkrd ntd}t|| dddtjtjtjg}t |tdt}||}t |}t|| d S )	Nr   r.   rw   rr   r   rZ   r6  r7  )	r   r`  rf   r   r4   ru   rO   rI   r'   )rK   r   	expected1	expected2	expected3r   r   rL   r&   r&   r+   test_mode_str_obj  s    


z TestSeriesMode.test_mode_str_objzdropna, expected1, expected2r6  c                 C   sx   t g d}||}t |}t|| t dddtjtjtjg}||}t ||dgkr`d ntd}t|| d S )N)rT   r6  r6  rT   r6  rZ   )r   r`  rf   r   r4   ru   rO   )rK   r   rh  ri  r   rL   rM   r&   r&   r+   test_mode_mixeddtype  s    

z#TestSeriesMode.test_mode_mixeddtype)
1900-05-03r   
2013-01-02r   rn  c                 C   sh   t g ddd}||}t |dd}t|| t g ddd}||}t |dd}t|| d S )N)r   rn  rm  ru   ru   rD   rZ   )r   rn  rm  r   rn  ru   ru   re  rK   r   rh  ri  r   rL   r&   r&   r+   test_mode_datetime  s    
	
z!TestSeriesMode.test_mode_datetime)-1 days0 daysr   2 min1 dayc                 C   sh   t g ddd}||}t |dd}t|| t g ddd}||}t |dd}t|| d S )N)r   rq  rr  ru   ru   r   rZ   )rt  rt  z-1 dayz-1 day 2 minrs  rs  ru   ru   re  ro  r&   r&   r+   test_mode_timedelta  s    



z"TestSeriesMode.test_mode_timedeltar.   )r   r   rZ  r   c              	   C   s   t tddtjtjg}||}t |dd}t|| t tdddtjtjg}||}t |dd}t|| t tdddddtjtjgg ddd	}||}t |dd}t|| d S )
NrT   r.   categoryrZ   r   rr   rZ  Tr   )r   r   r4   ru   r`  rf   r   )rK   r   rh  ri  rj  r   rL   r&   r&   r+   test_mode_category  s     


z!TestSeriesMode.test_mode_category            c                 C   sp   t g dtjd}||}t |tjd}t|| t ddgtjd}||}t |tjd}t|| d S )N)rT   rx  rx  rZ   rT   rx  )r   r4   rE  r`  rf   r   ro  r&   r&   r+   test_mode_intoverflow8  s    

z$TestSeriesMode.test_mode_intoverflowc                 C   sz   t dtjg}t dddtjtjg}tt, |jdd}| jdd}W d    n1 s`0    Y  t	|| d S )Nr6  rT   F)r   T)Zdrop)
r   r4   ru   rf   rg   UserWarningr`  Zsort_valuesZreset_indexr   )rK   rM   r   rL   r&   r&   r+   test_mode_sortwarningH  s    .z$TestSeriesMode.test_mode_sortwarningc                 C   s>   t dddtjgdd}| }t ddidd}t|| d S )NTFrV   rZ   r   )r   rW   rX   r`  rf   r   )rK   r   rL   rM   r&   r&   r+   test_mode_boolean_with_naU  s    z(TestSeriesMode.test_mode_boolean_with_nazarray,expected,dtype)r                 ?rT   rT         ?      ?      ?       @)r~                 @r~  r~  c                 C   s    t ||d }t|| d S r   re  rK   rH   rM   r   rL   r&   r&   r+   test_single_mode_value_complex\  s    z-TestSeriesMode.test_single_mode_value_complex)r   r}  rT   r~  r  )y                r}  y      ?        r~  r  )r~  r  r~  r  rr   r  c                 C   s    t ||d }t|| d S r   re  r  r&   r&   r+   test_multimode_complext  s    z%TestSeriesMode.test_multimode_complexN)r   r   r   rm   r   r   r   r4   r7   rb  r   	typecodesrf  ru   rg  rk  rl  rp  ru  r   rw  ry  r{  r|  Z
complex128Z	complex64r  r  r&   r&   r&   r+   r_  }  s   "
	 
$






r_  )(r   r   decimalr   numpyr4   rm   ZpandasrW   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   Zpandas._testingZ_testingrf   Zpandas.corer   Zpandas.core.arrays.string_arrowr   r>   r?   r   r   rG  rV  r_  r&   r&   r&   r+   <module>   s.   L @  P     AG6