o
    ҷh$                     @   st   d Z ddlZddlZddlZddlZddlmZmZ ddl	m
Z ddlmZmZmZ G dd dZG dd dZdS )	zP
Tests for statistical reductions of 2nd moment or higher: var, skew, kurt, ...
    N)	DataFrameSeries)DatetimeArrayPeriodArrayTimedeltaArrayc                   @   sx   e Zd Zejdeeje	gdd Z
ejdeejegejdg ddd Zejdeejegdd	 Zd
S )TestDatetimeLikeStatReductionsboxc                 C   s   |}t jdd|d}|g d}|j}||}| t jd|dks%J |jddt jd|dks4J t j|d	< ||}| t jd
|dksJJ |jddt ju sUJ d S )N
2001-01-01   )periodstz         
   	            r         z
2001-01-06)r   Fskipnaz2001-01-06 07:12:00)pd
date_rangetake_datamean	TimestampNaT)selftz_naive_fixturer   r   dtidtarrobj r'   _/var/www/html/venv/lib/python3.10/site-packages/pandas/tests/reductions/test_stat_reductions.pytest_dt64_mean   s   
z-TestDatetimeLikeStatReductions.test_dt64_meanfreq)SHDWBc                 C   sb  t jddd}|g d}|dkrtnd }d}tj||d |j|}W d    n1 s0w   Y  ||}tj	t
dd |  W d    n1 sOw   Y  tj	t
dd |jd	d
 W d    n1 slw   Y  t j|d< tj	t
dd |  W d    n1 sw   Y  tj	t
dd |jd	d
 W d    d S 1 sw   Y  d S )Nr	   r
   r   r   r/   zPeriodDtype\[B\] is deprecatedmatch	ambiguousTr   r   )r   r   r   FutureWarningtmassert_produces_warningr   	to_periodpytestraises	TypeErrorr   r!   )r"   r   r*   r$   warnmsgparrr&   r'   r'   r(   test_period_mean+   s*   


"z/TestDatetimeLikeStatReductions.test_period_meanc                 C   s   t jg ddd}|j}||dd}| }t| }||ks#J t j|d< |jddt ju s3J |jdd}||d	d   ksEJ |d
|d d d
ksUJ d S )N)r   r   r   ir   r   r   r   r   r   r-   )unitF)copyr   r   Tr   usg      &@r   )r   TimedeltaIndexr   r   nparrayr!   round)r"   r   tditdarrr&   resultexpectedresult2r'   r'   r(   test_td64_meanE   s   
$z-TestDatetimeLikeStatReductions.test_td64_meanN)__name__
__module____qualname__r8   markparametrizer   r   Indexr   r)   r   r>   r   rL   r'   r'   r'   r(   r      s    
r   c                   @   sp   e Zd Z	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d Zdd Zdd Zdd ZdS )TestSeriesStatReductionsFc              	   C   s`  t dd tt|}tj|dd< |dvrBtt jddd}d	| d
}tjt	|d || W d    n1 s=w   Y  t 
||sKJ t ||ddsVJ | }	t||	||	j t||||	j |tj }
|rt||
sJ tg d}|| dg}|tdd t|dd}tt||t||j |rtt jddd}||}||}||ksJ |dvrtjt	d d |ttd W d    n1 sw   Y  d}tjt|d ||dd W d    n	1 sw   Y  dt|jv r||dd W d    d S W d    d S 1 s)w   Y  d S )Nuse_bottleneckFr      )maxminr   medianstdz1/1/2001r   r0   zdoes not support reduction ''r1   r   )r   r   r   Nr   r   l        l      int64dtypez1/1/2000)sumrW   rV   abcz&No axis named 1 for object type Seriesr   )axisnumeric_onlyT)ra   )r   option_contextgetattrr   rD   nanr   r8   r9   r:   notnaisnadropnar5   assert_almost_equalvaluesisnanextendrangefloatbdate_rangelist
ValueErrorinspectgetfullargspecargs)r"   name	alternatestring_series_check_objectscheck_allnafdsr<   nonaallnasitemsresexpr'   r'   r(   _check_stat_op_   sR   


6$z'TestSeriesStatReductions._check_stat_opc                 C   &   t  d}| jdtj|dd d S )Nseriesr^   F)rx   )r5   makeStringSeriesrenamer   rD   r^   r"   string_seriesr'   r'   r(   test_sum      z!TestSeriesStatReductions.test_sumc                 C   "   t  d}| dtj| d S )Nr   r   )r5   r   r   r   rD   r   r   r'   r'   r(   	test_mean      z"TestSeriesStatReductions.test_meanc                 C   sR   t  d}| dtj| ttjdtdt	dd}t 
t||  d S )Nr   rX   r   r\   )index)r5   r   r   r   rD   rX   r   onesintrl   rh   )r"   r   int_tsr'   r'   r(   test_median   s   z$TestSeriesStatReductions.test_medianc                 C   r   )Nr   prod)r5   r   r   r   rD   r   r   r'   r'   r(   	test_prod   r   z"TestSeriesStatReductions.test_prodc                 C   r   )Nr   rW   Trw   )r5   r   r   r   rD   rW   r   r'   r'   r(   test_min   r   z!TestSeriesStatReductions.test_minc                 C   r   )Nr   rV   Tr   )r5   r   r   r   rD   rV   r   r'   r'   r(   test_max   r   z!TestSeriesStatReductions.test_maxc                 C   s   t  d}t  d}dd }| d|| dd }| d|| |jdd	}tj|jdd	}t || |j	dd	}tj	|jdd	}t || |j
d
g }|j	dd	}t|s_J |jdd	}t|slJ d S )Nr   tsc                 S      t j| ddS Nr   ddof)rD   rY   xr'   r'   r(   <lambda>       z7TestSeriesStatReductions.test_var_std.<locals>.<lambda>rY   c                 S   r   r   )rD   varr   r'   r'   r(   r      r   r   r   r   r   r   )r5   r   r   makeTimeSeriesr   rY   rD   ri   rh   r   ilocr   rf   r"   r   datetime_seriesaltrI   rJ   r}   r'   r'   r(   test_var_std   s"   z%TestSeriesStatReductions.test_var_stdc                 C   s   t  d}t  d}dd }| d|| |jdd}tj|jddt	t
|j }t || |jdg }|jd	d}t|sHJ d S )
Nr   r   c                 S   s   t j| ddt t|  S r   )rD   rY   sqrtlenr   r'   r'   r(   r      s    z3TestSeriesStatReductions.test_sem.<locals>.<lambda>semr   r   r   r   )r5   r   r   r   r   r   rD   rY   ri   r   r   rh   r   r   rf   r   r'   r'   r(   test_sem   s   z!TestSeriesStatReductions.test_semc                    s   t d t d} fdd}| d|| d}td|d D ]G}tt	|}t
t	||f}||k rMt| sAJ t|  sLJ q"d| ksUJ t| tjs_J | dk siJ q"d S )	Nscipy.statsr   c                        j | ddS NF)bias)skewr   sp_statsr'   r(   r      r   z4TestSeriesStatReductions.test_skew.<locals>.<lambda>r   r   r   r   )r8   importorskipr5   r   r   r   rl   r   rD   r   r   rj   r   all
isinstancefloat64)r"   r   r   min_Nir}   dfr'   r   r(   	test_skew   s   
z"TestSeriesStatReductions.test_skewc                    s6   t d t d} fdd}| d|| d S )Nr   r   c                    r   r   )kurtosisr   r   r'   r(   r      r   z4TestSeriesStatReductions.test_kurt.<locals>.<lambda>kurt)r8   r   r5   r   r   r   )r"   r   r   r'   r   r(   	test_kurt   s   
z"TestSeriesStatReductions.test_kurtc                 C   s   d}t d|d D ]G}tt|}tt||f}||k r4t| s(J t|  s3J q	d| ks<J t| tj	sFJ | dk sPJ q	d S )Nr   r   r   )
rl   r   rD   r   r   rj   r   r   r   r   )r"   r   r   r}   r   r'   r'   r(   test_kurt_corner  s   z)TestSeriesStatReductions.test_kurt_cornerN)FF)rM   rN   rO   r   r   r   r   r   r   r   r   r   r   r   r   r'   r'   r'   r(   rS   Z   s    
=rS   )__doc__rq   numpyrD   r8   pandasr   r   r   pandas._testing_testingr5   pandas.core.arraysr   r   r   r   rS   r'   r'   r'   r(   <module>   s    D