o
    Ti                     @   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 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timedelta_rangeto_timedelta)nanopsc               
      s   t jdddt jdddt jdddt jdddt jdddjddt jdddt jdddg} tj	
dd  fdd| D }| | }|S )	N
   a)namez
US/Easterntz   c                    s   g | ]	}t  |d dqS )r   )indexr   )r   ).0idxarr g/var/www/html/evchargy.com/venv/lib/python3.10/site-packages/pandas/tests/reductions/test_reductions.py
<listcomp>-   s    zget_objs.<locals>.<listcomp>)tmZmakeBoolIndexZmakeIntIndexZmakeFloatIndexZmakeDateIndextz_localizeZmakePeriodIndexZmakeStringIndexnprandomdefault_rngstandard_normal)ZindexesseriesZobjsr!   r   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st |j| }ntt |j| |jd}t |dd d ur8|dd}|j|ks6J d S ||ks>J d S )N)Zordinalfreqr   M8[ns]int64)	getattr
isinstancer   valuesr
   Zasi8r1   astype_value)selfr-   r0   resultexpectedr!   r!   r"   test_ops4   s   
zTestReductions.test_opsz
dtype, val)object       @)float64r>   datetime64[ns]        )Int64r   )booleanTc                    s  |} fdd}|d g d}|t || sJ |t ||dds%J |g  d}|t || s5J |t ||ddsAJ  dkrGd S |d |g d}t || |ksYJ |t ||ddseJ |d |d g d}t || |ksxJ |t ||ddsJ d S )Nc                    s*    dkr| t u S  dv r| tju S t| S )Nr@   )rD   rE   )r	   pdNAr   )resdtyper!   r"   check_missingV   s
   
z4TestReductions.test_nanminmax.<locals>.check_missingrI   Fskipnar=   )r4   )r9   r-   rJ   valindex_or_seriesklassrK   r0   r!   rI   r"   test_nanminmaxG   s    zTestReductions.test_nanminmaxc                 C   sH  |}|t u r
d| nd| }|ttdddg}t|| dks"J d}|tu r*d}tjt|d t||d	d
}W d    n1 sDw   Y  |tu rUt	|sTJ n|dks[J |ttdddtg}t|| dkspJ tjt|d t||d	d
}W d    n1 sw   Y  |tu rt	|sJ d S |dksJ d S )Nargr   rA   rB   rC   zNThe behavior of (DatetimeIndex|Series).argmax/argmin with skipna=False and NAsz2The behavior of Series.(idxmax|idxmin) with all-NAmatchFrL   )
r   r	   r   r4   r   r$   assert_produces_warningFutureWarningr&   isnan)r9   r-   rO   rP   arg_opr0   msgr:   r!   r!   r"   test_nanargminmaxr   s,   z TestReductions.test_nanargminmaxrJ   r2   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 s*J tjtdd t||  W d    n1 sBw   Y  tjtdd t||dd W d    d S 1 sbw   Y  d S )NrR   r   rI   FrL   zempty sequencerS   )r   r4   r	   pytestraises
ValueError)r9   r-   rO   rJ   rP   rY   r0   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sJ t tjdtjdg}| dks+J | dks3J d	}tjt|d
 |jdddksGJ W d    n1 sQw   Y  tjt|d
 |jdddkshJ W d    n1 srw   Y  t tjg}tjt|d
 | dksJ W d    n1 sw   Y  tjt|d
 | dksJ W d    n1 sw   Y  tjt|d
 |jdddksJ W d    n1 sw   Y  tjt|d
 |jdddksJ W d    n1 sw   Y  d}t t	t
dddt
dddt	g}| dksJ | dks!J tjt|d
 |jdddks4J W d    n	1 s?w   Y  tjt|d
 |jdddksWJ W d    n	1 sbw   Y  t t	g}tjt|d
 | dks}J W d    n	1 sw   Y  tjt|d
 | dksJ W d    n	1 sw   Y  tjt|d
 |jdddksJ W d    n	1 sw   Y  tjt|d
 |jdddksJ W d    d S 1 sw   Y  d S )N   r3   rI   r      rC   r      z=The behavior of Index.argmax/argmin with skipna=False and NAsrS   FrL   rU   zEThe behavior of DatetimeIndex.argmax/argmin with skipna=False and NAsrA   rB   )r   r&   arangeargminargmaxnanr$   rV   rW   r	   r   )r9   r0   rZ   r!   r!   r"   test_argminmax   sb    
$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:00rb   UTC)periodsr   r   )columnsi  secondsrh   rC   axis)	r   r   r   subtractr   r4   renamer$   assert_series_equal)r9   opZexpected_coldfr:   r;   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)rF   to_datetimer%   r   r4   r&   r$   rr   )r9   Ztz_aware_fixturerv   r   rR   r;   r:   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 )NrC   r   timedelta64[ns]rI   rD   ABrb   )	r   r   r	   r&   rf   r   sumr$   rr   )r9   rt   r;   r:   r!   r!   r"   test_nan_int_timedelta_sum   s   z)TestReductions.test_nan_int_timedelta_sumN)__name__
__module____qualname__r\   markfilterwarningsparametrizer+   r<   r   rQ   r[   r_   rg   ru   rz   r   r!   r!   r!   r"   r,   3   s:    
 
+


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  rb   )i  r   i)@B ra   )r   r   )r   r      c                 C   s   t |||}|j }| }||ksJ |jdd}||ks!J |j }| }||ks0J |jdd}||ks<J t ||| }t| sKJ t| sSJ d S NFrL   )r   Z_valuesr.   r/   r   )r9   startstopstepr   r;   r:   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rJ ||fD ]&}| tdks)J | tdks3J | dks;J | dksCJ qd S )N)1 days2 days3 daysr   r   r	   r   r   )	r   is_monotonic_increasingr&   rf   r/   r   r.   rd   re   r9   idx1idx2r   r!   r!   r"   test_minmax_timedelta64  s   

z+TestIndexReductions.test_minmax_timedelta64rs   r/   r.   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   r4   r	   r9   rs   r0   r!   r!   r"   !test_minmax_timedelta_empty_or_na$     
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 s8w   Y  tjt|d tj|dd W d    n1 sVw   Y  t|dksdJ t	|d	ksmJ d}tjt|d tj|dd W d    n1 sw   Y  tjt|d tj	|dd W d    d S 1 sw   Y  d S )
Nz
16815 daysz
16820 daysDr1   $the 'out' parameter is not supportedrS   r   outr`   )
r   r&   r/   r   r.   r\   r]   r^   rd   re   )r9   tderrmsgr!   r!   r"   test_numpy_minmax_timedelta640  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sAJ | }td
}||ksOJ |  }|d |ks]J | }td}||kskJ |  }|d |ksyJ | }tt | j }||ksJ |  }|d |ksJ t tdtdg}|  tddksJ t tdtdtdg}|  tddksJ d S )Nc                 S   "   g | ]}t d t|| d qS Z20130101rl   r   r   r   ir!   r!   r"   r#   I     " z:TestIndexReductions.test_timedelta_ops.<locals>.<listcomp>r   	   rl   r   g?i(
  msz00:00:09z00:01:21z
2015-02-03z
2015-02-07ra   )daysz
2015-02-15   )r   rangediffmeanr   r   to_frameZquantiler   r&   Ztimedelta64medianr   stddropnar6   r   )r9   sr   r:   r;   r!   r!   r"   test_timedelta_opsE  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 s;w   Y  tjt|d t| |dd W d    d S 1 s]w   Y  d S )Nc                 S   r   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 ''rS   F)Znumeric_only)	r   r   r   joinr\   r]   	TypeErrorr4   r   )r9   r-   r   r   rZ   r!   r!   r"   test_invalid_td64_reductionsz  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d|dks1J | td|dks=J | dksEJ | dksMJ q#d S )N)
2011-01-01
2011-01-02
2011-01-03r   r   r   r   r   r   )r   r   r	   r/   r   r.   rd   re   )r9   Ztz_naive_fixturer   r   r   r   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   r4   r	   r   r!   r!   r"   test_minmax_nat_datetime64  r   z.TestIndexReductions.test_minmax_nat_datetime64c                 C   s  t g d}|j }t|}||ksJ |j }t|}||ks&J d}tjt|d tj|dd W d    n1 sAw   Y  tjt|d tj|dd W d    n1 s_w   Y  |j }t|}||kstJ |j	 }t	|}||ksJ d}tjt|d tj	|dd W d    n1 sw   Y  tjt|d tj|dd W d    d S 1 sw   Y  d S )NrC   r   rb   r   rS   r   r   )
r   r6   r.   r&   r/   r\   r]   r^   re   rd   )r9   r   r;   r:   r   r!   r!   r"   test_numpy_minmax_integer  s6   







"z-TestIndexReductions.test_numpy_minmax_integerc                 C   s   t ddd}t|}|dksJ t|}|dksJ d}tjt|d tj|dd W d    n1 s7w   Y  tjt|d tj|dd W d    d S 1 sVw   Y  d S )Nr   r   rb   r   r   rS   r   )r   r&   r.   r/   r\   r]   r^   )r9   r   r:   r   r!   r!   r"   test_numpy_minmax_range  s   

"z+TestIndexReductions.test_numpy_minmax_rangec                 C   sZ  t 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 s7w   Y  tjt|d tj|dd	 W d    n1 sUw   Y  t|dkscJ t	|d
kslJ d}tjt|d tj|dd	 W d    n1 sw   Y  tjt|d tj	|dd	 W d    d S 1 sw   Y  d S )N
2016-01-15
2016-01-20r   endz2016-01-15 00:00:00z2016-01-20 00:00:00r   rS   r   r   r`   )
r   r&   r/   r   r.   r\   r]   r^   rd   re   )r9   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sJ t dtddtgdd}|jr(J ||fD ]}| tdddks:J | tdddksFJ q,| dksOJ | dksWJ | dks_J | d	ksgJ d S )
Nr   r   r   r   r   rC   r   rb   r   )r   r	   r   r/   r
   r.   rd   re   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   r4   r	   )r9   rs   r   r0   r:   r!   r!   r"   test_minmax_period_empty_nat  s   z0TestIndexReductions.test_minmax_period_empty_natc                 C   sd  t j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 s<w   Y  tjt|d tj|dd	 W d    n1 sZw   Y  t	|dkshJ t
|d
ksqJ d}tjt|d tj	|dd	 W d    n1 sw   Y  tjt|d tj
|dd	 W d    d S 1 sw   Y  d S )Nr   r   r   r   r   r   rS   r   r   r`   )rF   Zperiod_ranger&   r/   r
   r.   r\   r]   r^   rd   re   )r9   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 s$w   Y  d}tjt|d |  W d    n1 sAw   Y  t jtdtddd}| d	ksZJ | d
ksbJ 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\nrS   zwCategorical is not ordered for operation max\nyou can use .as_ordered\(\) to change the Categorical to an ordered one\nTcrh   )rF   ZCategoricalIndexlistr\   r]   r   r/   r.   )r9   cirZ   r!   r!   r"   test_min_max_categorical(  s   

z,TestIndexReductions.test_min_max_categoricalN)r   r   r   r\   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r	   r   r   r   r!   r!   r!   r"   r      s2    


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|	 s&J tjdd
d}tj|d d df< d}tjt|d( td	d
 t|	 |	  W d    n1 s`w   Y  W d    n1 sow   Y  tj|dd}t| sJ d S )Nr   r   r`      )d   r   Zf4"use_inf_as_na option is deprecatedrS   mode.use_inf_as_naTrC   rn   )r   r&   r'   r(   r)   copyinfrf   isinfr   r7   r$   rV   rW   rF   option_contextassert_almost_equalr   nansumall)r9   r   s2r    rZ   rH   r!   r!   r"   test_sum_infA  s    z!TestSeriesReductions.test_sum_infrJ   )r?   ZFloat32rD   rE   r=   use_bottleneckTFzmethod, unit)r           )r         ?c                 C   sP  t d| tg |d}t|| }||ksJ t||dd}||ks(J t||dd}t|s6J t||dd}||k t||ddd}||ksQJ t||ddd}t|s`J t||d	dd}||ksoJ t||d	dd}t|s~J ttjg|d}t|| }||ksJ t||dd}||ksJ t||dd}t|sJ 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sJ 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	 s@J tdg|d}t||dd}t|sVJ t||d	dd}t|sfJ ttjg|d}t||dd}t|s}J ttjdg|d}t||dd}t|sJ W d    d S 1 sw   Y  d S )Nr   rI   r   )	min_countrC   TrL   )rM   r   Fr   )r   r   r   )
rF   r   r   r4   r   r&   rf   r   emptyr   )r9   methodunitr   rJ   r   r:   rt   r!   r!   r"   
test_emptyU  sp   $zTestSeriesReductions.test_emptyr   r   r   )Float64rD   rE   c                 C   sT   t g |d}t|| }|tju sJ t tjg|d}t|| }|tju s(J d S NrI   )r   r4   rF   rG   r&   rf   )r9   r   rJ   Zeserr:   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    d S 1 s9w   Y  d S t || }|tu sLJ d S )NrI   m8[ns]r   r   )zoperation 'var' not allowedz.cannot perform var with type timedelta64\[ns\]z does not support reduction 'var'rS   )	r4   r   floatr   r   r\   r]   r   r	   )r9   r   r:   ZtdserrZ   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   rC   r   )r   r&   rf   r   r$   r   )r9   serr:   r!   r!   r"   test_nansum_buglet  s   
z'TestSeriesReductions.test_nansum_bugletZint32r3   c                 C   s   t d|D tjd|d}t|}|jdd}t||jddks$J |jdd}t|dks2J |jdd}t||d ksBJ W d    d S 1 sMw   Y  d S )	Nr   @KL rI   FrL   r3   r   rU   )	rF   r   r&   rc   r   r   intr/   r.   r9   r   rJ   vr   r:   r!   r!   r"   test_sum_overflow_int  s   "z*TestSeriesReductions.test_sum_overflow_intZfloat32r?   c                 C   s   t d|F tjd|d}t|}|jdd}||j|dks"J |jdd}tt|ds2J |j	dd}tt||d sDJ W d    d S 1 sOw   Y  d S )Nr   r   rI   FrL   r   rU   )
rF   r   r&   rc   r   r   r/   Zallcloser   r.   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s&J |dks,J d S )Nl     ;r   rD   rI   r   g ؅W4vC)r&   arrayr   r   )r9   rN   Z
n_elementsnar   Zresult_numpyZresult_maskedr!   r!   r"   test_mean_masked_overflow  s   
z.TestSeriesReductions.test_mean_masked_overflowz	ddof, exp)rC         @)r   r>   c                 C   sT   t g ddd}t g ddd}|j|d}|j|d}||ks"J ||ks(J d S )N)rC   r   rb   ra   r`   rD   rI   r3   )ddof)r   r   )r9   r  expr   Zser_numpy_dtyper:   Zresult_numpy_dtyper!   r!   r"   test_var_masked_array  s   z*TestSeriesReductions.test_var_masked_array)r   r   r2   zM8[ns, UTC]rM   c                 C   s<   t g |dj|dtu sJ t g |dj|dtu sJ d S )NrI   rL   )r   r/   r	   r.   )r9   rJ   rM   r!   r!   r"   +test_empty_timeseries_reductions_return_nat  s    z@TestSeriesReductions.test_empty_timeseries_reductions_return_natc                 C      t dd}t||d}t |}t |}||ksJ | }||ks&J d}tjt|d t j||d W d    d S 1 sBw   Y  d S NrC   rB   r   r   rS   r   )r&   rc   r   rd   r\   r]   r^   r9   r   r   r:   r;   rZ   r!   r!   r"   test_numpy_argmin#  s   

"z&TestSeriesReductions.test_numpy_argminc                 C   r  r  )r&   rc   r   re   r\   r]   r^   r  r!   r!   r"   test_numpy_argmax5  s   

"z&TestSeriesReductions.test_numpy_argmaxc                 C   st  t ddtjgtg dd}d}tjt|d |jdd}W d    n1 s(w   Y  |tu s3J d	}tjt|d |j	dd}W d    n1 sMw   Y  |tu sXJ |
 }d
}tjt|d |jdd}W d    n1 svw   Y  |jdksJ |  sJ d}tjt|d |j	dd}W d    n1 sw   Y  |jdksJ |  sJ d S )Nr   r>   )r	   z
2015-02-08r	   r   0The behavior of Series.idxmin with all-NA valuesrS   FrL   0The behavior of Series.idxmax with all-NA valuesz3The behavior of DataFrame.idxmin with all-NA valuesr2   z3The behavior of DataFrame.idxmax with all-NA values)r   r&   rf   r   r$   rV   rW   idxminr	   idxmaxr   rJ   r   r   )r9   r   rZ   rH   rt   r!   r!   r"   test_idxmin_dt64indexF  s4   z*TestSeriesReductions.test_idxmin_dt64indexc                 C   sL  t  d}tj|dd< ||  | ksJ d}t jt|d t	|jdds.J W d    n1 s8w   Y  |
 }||  | ksMJ |jj | |j ks_J |tj }t jt|d t	| stJ W d    n1 s~w   Y  ttdd	d
}| }|dksJ tj|d< | }|dksJ d S )Nr*   r`      zThe behavior of Series.idxminrS   FrL   20130102r   rj   r   rC   )r$   makeStringSeriesrq   r&   rf   r  r/   rV   rW   r   r   r   r6   tolistrd   r   r   r9   Zstring_seriesrZ   ZnonaZallnar   r:   r!   r!   r"   test_idxmin`  s(   $

z TestSeriesReductions.test_idxminc                 C   s  t  d}tj|dd< ||  | ksJ d}t jt|d t	|jdds.J W d    n1 s8w   Y  |
 }||  | ksMJ |jj | |j ks_J |tj }d}t jt|d t	| svJ W d    n1 sw   Y  ttdd	d
}| }|dksJ tj|d< | }|dksJ 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  rS   FrL   r  r   r  ra   r   )皙?g @@r  r  )r$   r  rq   r&   rf   r  r.   rV   rW   r   r   r   r6   r  re   r   r   r  r  r!   r!   r"   test_idxmax  s>   $

z TestSeriesReductions.test_idxmaxc                 C   sD   t  }|dk}| rJ | sJ tddg}| s J d S )Nr   abcT)r$   ZmakeTimeSeriesr   anyr   )r9   tsZ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 |s!J d S )N)r   rC   r   r   )r&   r   r  r   )r9   rO   r   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s&J |jddr.J d S )NTFrL   )r   r&   rf   r   r  )r9   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rJ d S )N)FFTTFT)r   r   rC   rC   r   r   r   T)	bool_only)r   r  r   )r9   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sJ d S )N)r   rh   r   derI   rL   T)r   r=   r4   )r9   r#  rM   r   r:   r;   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sJ d S )NFrL   r  )r   r4   )r9   r   r#  r   r:   r;   r!   r!   r"   !test_any_all_object_dtype_missing  s   z6TestSeriesReductions.test_any_all_object_dtype_missing)rE   rD   ZUInt64r   zdata,expected_data)r   r   r   )rC   rC   rC   r   rC   c           	      C   sT   t ||d}|| |dk }t|||d}|tju r |tju s(||ks&J d S d S )NrI   r   rL   )r   r4   rF   rG   )	r9   r#  rM   r   rJ   Zexpected_datar   r;   r:   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 )NTFrC   r   r|   )ro   r!  )r   r  r   r$   rr   )r9   rt   r:   r;   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0 | sJ | s%J | s+J | s1J |  s9J |  sAJ W d    n1 sKw   Y  |	d}t|}t|}tjt|d0 | skJ | sqJ | swJ | s}J |  sJ |  sJ W d    n1 sw   Y  ||d  }t|}t|}| sJ | rJ | sJ | rJ |  sJ |  rJ d S )Nz
1995-01-02rb   r  z0'(any|all)' with datetime64 dtypes is deprecatedrS   ri   r   )
r   _datar   r   r$   rV   rW   r   r  r%   )r9   Zdtar   rt   rZ   Ztdar!   r!   r"   test_any_all_datetimelike
  s@   
z.TestSeriesReductions.test_any_all_datetimelikec                 C   s   t d tddgdd}| sJ | rJ td dgdd}| s'J | r-J td dgdd}| r;J | rAJ tddgdd}| sOJ | sUJ d S )NZpyarrow r   zstring[pyarrow_numpy]rI   rh   )r\   Zimportorskipr   r  r   r9   r   r!   r!   r"   test_any_all_pyarrow_string9  s   
z0TestSeriesReductions.test_any_all_pyarrow_stringc                 C   s  t dddd}t|td }| }|dksJ | }|dks#J tj|d< | }|dks2J | }|dks<J tt ddd	}tt d
dd	}t|| }t|| }t	|| ||  }t	|| |
 }td}||ksyJ | }td}||ksJ d S )Nz2012-1-1rb   r   rj   r1   Z20120101r   r   rC   r  Z20120102r   r   )r   r   r   r  r  r&   rf   absr$   rr   r.   r   r/   )r9   Zdtir   r:   r  r   r;   r!   r!   r"   test_timedelta64_analyticsL  s0   
z/TestSeriesReductions.test_timedelta64_analyticsztest_input,error_typerI   foobarbazrC   r   r3  r4  r5  c                 C   s   t g dd}d}tjt|d |  W d   n1 sw   Y  tjt|d |jdd W d   n1 s;w   Y  d}tjt|d |  W d   n1 sXw   Y  tjt|d |jdd W d   dS 1 svw   Y  dS )	zU
        Cases where ``Series.argmax`` and related should raise an exception
        r?   rI   z*attempt to get argmin of an empty sequencerS   NFrL   z*attempt to get argmax of an empty sequence)r   r\   r]   r^   r  r  )r9   Z
test_inputZ
error_typerZ   r!   r!   r"   "test_assert_idxminmax_empty_raisesu  s   

"z7TestSeriesReductions.test_assert_idxminmax_empty_raisesc                 C   s  t g d}| dksJ |jdddksJ | dks J |jdddks*J t ddg}| dks8J |jdddksBJ | dksJJ |jdddksTJ t ddd	d	d tjd
g}d}tjt|d |  W d    n1 sxw   Y  tjt|d |jdd W d    n1 sw   Y  d}tjt|d |  W d    n1 sw   Y  tjt|d |jdd W d    d S 1 sw   Y  d S )Nr2  r   FrL   rC   r6  r7  r3  r4  r5  z8'>' not supported between instances of 'float' and 'str'rS   z8'<' not supported between instances of 'float' and 'str')r   r  r  r&   rf   r\   r]   r   )r9   r   Zser2Zser3rZ   r!   r!   r"   test_idxminmax_object_dtype  s2   

"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   r$   rr   )r9   rt   rH   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s*J d S )N))rC   rb   )r   r   )rb   rC   r   r   FrL   )r   r  r  r-  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   rC   z8.68z42.23z7.11z79.61)r   xy)r   r   r  r   r$   rr   r  )r9   rt   rH   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sJ |jdddks"J |jdddks,J d S )Nr   rC   r=   rI   FrL   )r   re   rd   r-  r!   r!   r"   test_argminmax_object_ints  s
   z/TestSeriesReductions.test_argminmax_object_intsc              	   C   s  t dtj tjtjg}| dksJ d}tjt|d t|jdds)J W d    n1 s3w   Y  |	 dks@J d}tjt|d t|j	ddsUJ W d    n1 s_w   Y  d	}tjt|dK t
d
d, | dks}J t|jddsJ |	 dksJ t|j	dd W d    n1 sw   Y  W d    d S W d    d S 1 sw   Y  d S )Nr   rC   r  rS   FrL   r   r  r   r   T)r   r&   r   rf   r  r$   rV   rW   rX   r  rF   r   )r9   r   rZ   r!   r!   r"   test_idxminmax_with_inf  s,   "z,TestSeriesReductions.test_idxminmax_with_infc                 C   s0   t dgdd}| }td}t|| d S )Nl     9V uint64rI   )r   r   r&   rB  r$   r   )r9   r   r:   r;   r!   r!   r"   test_sum_uint64  s   
z$TestSeriesReductions.test_sum_uint64)/r   r   r   r   r\   r   r   r   r   r   r   r   r   r   r  r  r	  r
  r  r  r  r  r  r   r"  r&  r&   rf   r'  rF   rG   r(  r)  r+  r.  r1  r   r^   r   r8  r9  r;  r<  r?  r@  rA  rC  r!   r!   r!   r"   r   <  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 sJ |jddtu s$J d S r   r/   r	   r.   )r9   rE  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 s,J d S )Nr   FrL   rF  )r9   rH  r!   r!   r"   test_minmax_nat_dataframe  s   
z8TestDatetime64SeriesReductions.test_minmax_nat_dataframec                 C   s   t dd}|tjdt|}| }| }t	|t
s"J t	|t
s)J ||d ks1J ||d ks9J | |d ksCJ | |d ksMJ d S )N1/1/2000z
12/31/2000r   r   rU   )r   Ztaker&   r'   r(   Zpermutationlenr/   r.   r5   r   )r9   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	s0J ||ks6J |j }t	|jj
d	 }t|t	sJJ ||ksPJ d S )
NrJ  r   Z4hr/  )
r}   r}   r}   r~   r~   r~   CrN  rN  rN  r   )TSVLrU   r   )r   r   r&   r'   r(   r)   rK  rO  r.   r   Ziatr5   r/   )r9   rL  Zlvlsrt   r:   r  r!   r!   r"   test_min_max_series$  s    

z2TestDatetime64SeriesReductions.test_min_max_seriesN)r   r   r   r\   r   r   r   r	   r   rG  r   rI  rM  rR  r!   r!   r!   r"   rD    s&    



rD  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functionr/   r.   c                 C   s^   t tg ddd}d| }tjt|d t||  W d    d S 1 s(w   Y  d S )N)r   rh   r   r$  F)r   z)Categorical is not ordered for operation rS   )r   r   r\   r]   r   r4   )r9   rT  catrZ   r!   r!   r"   test_min_max_unordered_raises?  s
   
"z=TestCategoricalSeriesReductions.test_min_max_unordered_raiseszvalues, categoriesr  Zcbar   rb   r   rC   rC   r   rb   c                 C   sJ   t t||dd}t||dd}|dkr|d n|d }||ks#J d S )NTr   rL   r/   r   r   )r   r   r4   )r9   r6   r   rT  rU  r:   r;   r!   r!   r"   test_min_max_orderedG  s   z4TestCategoricalSeriesReductions.test_min_max_orderedrM   TFc                 C   s<   t ttjgddgdd}t|||d}|tju sJ d S )NrC   r   Tr   rL   r   r   r&   rf   r4   )r9   rT  rM   rU  r:   r!   r!   r"   "test_min_max_ordered_with_nan_onlyY  s   zBTestCategoricalSeriesReductions.test_min_max_ordered_with_nan_onlyc                 C   sj   t tddtjdgddgdd}t|||d}|du r,|dkr"dnd}||ks*J d S |tju s3J d S )Nr   rh   Tr   rL   r/   rY  )r9   rT  rM   rU  r:   r;   r!   r!   r"   test_min_max_skipnaa  s   z3TestCategoricalSeriesReductions.test_min_max_skipnaN)r   r   r   r\   r   r   rV  r   r&   rf   rX  rZ  r[  r!   r!   r!   r"   rS  :  s(    

rS  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, expectedTrI   Fc                 C   s(   t g tjd}||}t|| d S r   )r   r&   r?   moder$   rr   r9   r   r;   r   r:   r!   r!   r"   test_mode_emptyu  s   
zTestSeriesMode.test_mode_emptyzdropna, data, expected)rC   rC   rC   r   rC   )rC   rC   rC   r   rb   rb   rb   rb   dtZ
AllIntegerFloatc                 C   s2   t ||d}||}t ||d}t|| d S r   r   r]  r$   rr   )r9   r   r   r;   r`  r   r:   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 )NrC   r   )r   r&   rf   r]  r$   rr   r^  r!   r!   r"   test_mode_numerical_nan  s   
z&TestSeriesMode.test_mode_numerical_nanz'dropna, expected1, expected2, expected3rh   r4  rf   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 |td}t|| dddtjtjtjg}t |tdt}||}t |td}t|| d S )	Nr   r   rh   rb   r   rI   r3  r4  )	r   r]  r$   rr   r&   rf   r=   r7   str)r9   r   	expected1	expected2	expected3r   r   r:   r!   r!   r"   test_mode_str_obj  s   


z TestSeriesMode.test_mode_str_objzdropna, expected1, expected2r3  c                 C   sj   t g d}||}t |}t|| t dddtjtjtjg}||}t |td}t|| d S )N)rC   r3  r3  rC   r3  rI   )r   r]  r$   rr   r&   rf   r=   )r9   r   rf  rg  r   r:   r;   r!   r!   r"   test_mode_mixeddtype  s   

z#TestSeriesMode.test_mode_mixeddtype)
1900-05-03r   
2013-01-02r   rl  c                 C   h   t g ddd}||}t |dd}t|| t g ddd}||}t |dd}t|| d S )N)r   rl  rk  rf   rf   r2   rI   )r   rl  rk  r   rl  rf   rf   rb  r9   r   rf  rg  r   r:   r!   r!   r"   test_mode_datetime  s   
	
z!TestSeriesMode.test_mode_datetime)-1 days0 daysr   2 min1 dayc                 C   rm  )N)r   rp  rq  rf   rf   r{   rI   )rs  rs  z-1 dayz-1 day 2 minrr  rr  rf   rf   rb  rn  r!   r!   r"   test_mode_timedelta  s   



z"TestSeriesMode.test_mode_timedeltar   )r   r   rW  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 )
NrC   r   categoryrI   r   rb   rW  Tr   )r   r   r&   rf   r]  r$   rr   )r9   r   rf  rg  rh  r   r:   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)rC   rw  rw  rI   rC   rw  )r   r&   rB  r]  r$   rr   rn  r!   r!   r"   test_mode_intoverflow+  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 s0w   Y  t	|| d S )Nr3  rC   F)r   T)Zdrop)
r   r&   rf   r$   rV   UserWarningr]  Zsort_valuesZreset_indexrr   )r9   r;   r   r:   r!   r!   r"   test_mode_sortwarning;  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 )NTFrE   rI   r   )r   rF   rG   r]  r$   rr   )r9   r   r:   r;   r!   r!   r"   test_mode_boolean_with_naH  s   z(TestSeriesMode.test_mode_boolean_with_nazarray,expected,dtype)r                 ?rC   rC         ?      ?      ?       @)r}                 @r}  r}  c                 C       t ||d }t|| d S r   rb  r9   r   r;   rJ   r:   r!   r!   r"   test_single_mode_value_complexO  s   z-TestSeriesMode.test_single_mode_value_complex)r   r|  rC   r}  r~  )y                r|  y      ?        r}  r~  )r}  r  r}  r  rb   r  c                 C   r  r   rb  r  r!   r!   r"   test_multimode_complexg  s   z%TestSeriesMode.test_multimode_complexN)r   r   r   r\   r   r   r   r&   r?   r_  r   	typecodesrc  rf   rd  ri  rj  ro  rt  r   rv  rx  rz  r{  Z
complex128Z	complex64r  r  r!   r!   r!   r"   r\  p  s    "
	 
$






r\  )%r   r   decimalr   numpyr&   r\   ZpandasrF   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   Zpandas._testingZ_testingr$   Zpandas.corer   r+   r,   r   r   rD  rS  r\  r!   r!   r!   r"   <module>   s.    H <  P     <G6