o
    tBh#E                     @   s^   d dl Zd dlmZ d dlmZ d dlmZm	Z	m
Z
 d dlmZ ddlmZ G dd	 d	ZdS )
    N)assert_allclose)raises)binned_statisticbinned_statistic_2dbinned_statistic_dd)check_random_state   )check_named_resultsc                   @   sp  e Zd Ze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d#d$ Zd%d& Zd'd( Z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!d=d> Z"d?d@ Z#dAdB Z$dCdD Z%dEdF Z&dGdH Z'dIdJ Z(dKdL Z)dMdN Z*dOdP Z+dQdR Z,dSdT Z-dUdV Z.dWdX Z/dYS )ZTestBinnedStatisticc                 C   sd   t d}|jdd| _|jdd| _|jdd| _|jdd| _|jdd| _|jddd | _d S )N&  d   )size)r      g    .A)r   uniformxyvXwu)clsrng r   ~/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/scipy/stats/tests/test_binned_statistic.pysetup_class   s   zTestBinnedStatistic.setup_classc                 C   L   | j }| j}t||ddd\}}}tj|dd\}}t|| t|| d S )Ncount
   binsr   r   r   np	histogramr   )selfr   r   count1edges1bccount2edges2r   r   r   test_1d_count      
z!TestBinnedStatistic.test_1d_countc                 C   s2   | j }| j}g d}|D ]
}t|||dd qd S )N)meanmedianr   sumr   r   )r   r   r   )r#   r   r   
statistics	statisticr   r   r   test_gh5927!   s   zTestBinnedStatistic.test_gh5927c                 C   sH   | j }| j}t||ddd\}}}t||tjdd\}}}t|| d S Nstdr   r   )r   r   r   r!   r2   r   r#   r   r   stat1r%   r&   stat2r(   r   r   r   test_big_number_std*   s
   z'TestBinnedStatistic.test_big_number_stdc                 C   s\   | j }| j}tt||ddd t||ddd\}}}t||tjdd\}}}t|| d S )Nr   i  r   r2   )r   r   printr   r!   r2   r   r3   r   r   r   test_empty_bins_std4   s   z'TestBinnedStatistic.test_empty_bins_stdc              	   C   sv   | j }| j}|d }tj|d< ttt||ddd ttt||dtdd tj|d< ttt||ddd ||d< d S )Nr   r2   r   r   r   )	r   r   r!   infassert_raises
ValueErrorr   int64nan)r#   r   r   origr   r   r   #test_non_finite_inputs_and_int_bins>   s   

z7TestBinnedStatistic.test_non_finite_inputs_and_int_binsc                 C   .   | j }| j}t||ddd}d}t|| d S )Nr   r   r   r/   	bin_edges	binnumber)r   r   r   r	   )r#   r   r   res
attributesr   r   r   test_1d_result_attributesN   
   z-TestBinnedStatistic.test_1d_result_attributesc                 C   N   | j }| j}t||ddd\}}}tj|d|d\}}t|| t|| d S )Nr-   r   r   r   weightsr    )r#   r   r   sum1r%   r&   sum2r(   r   r   r   test_1d_sumV      
zTestBinnedStatistic.test_1d_sumc                 C   R   | j }| j}t||ddd\}}}t||tjdd\}}}t|| t|| d S )Nr+   r   r   )r   r   r   r!   r+   r   r#   r   r   r4   r%   r&   r5   r(   r   r   r   test_1d_mean`      
z TestBinnedStatistic.test_1d_meanc                 C   rO   r1   )r   r   r   r!   r2   r   rP   r   r   r   test_1d_stdj   rR   zTestBinnedStatistic.test_1d_stdc                 C   rO   )Nminr   r   )r   r   r   r!   rT   r   rP   r   r   r   test_1d_mint   rR   zTestBinnedStatistic.test_1d_minc                 C   rO   )Nmaxr   r   )r   r   r   r!   rV   r   rP   r   r   r   test_1d_max~   rR   zTestBinnedStatistic.test_1d_maxc                 C   rO   )Nr,   r   r   )r   r   r   r!   r,   r   rP   r   r   r   test_1d_median   rR   z"TestBinnedStatistic.test_1d_medianc                    sp   | j d d }| jd d }t||ddd\}} tg d} fddt D }t | t|| d S )N   r   r   r   )r      r   r   rZ   r   r   r   r   r   r   r   r   r   rZ   r   r   r   rZ   r   c                       g | ]} |k  qS r   r-   .0ir&   r   r   
<listcomp>       z7TestBinnedStatistic.test_1d_bincode.<locals>.<listcomp>)r   r   r   r!   arrayuniquer   )r#   r   r   r$   r%   bc2bcountr   r`   r   test_1d_bincode   s   
z#TestBinnedStatistic.test_1d_bincodec           
      C   s   t jd t d}t jd}t|d d |d d \}}}t||dgd\}}}t||dd\}}	}t|| t|| t|| t||	 d S )Nr         )r      range)r!   randomseedaranger   r   )
r#   r   datar+   r   _
mean_range
bins_rangemean_range2bins_range2r   r   r   test_1d_range_keyword   s   
 


z)TestBinnedStatistic.test_1d_range_keywordc                 C   s   | j }| j}| j}t||ddd\}}}t||ddd\}}}	t|||gddd\}
}}t|
d | t|
d | t|| t|| d S )Nr+   r   r   r   r   )r   r   r   r   r   )r#   r   r   r   stat1vedges1vbc1vstat1wedges1wbc1wr5   r(   re   r   r   r   test_1d_multi_values   s   
z(TestBinnedStatistic.test_1d_multi_valuesc                 C   sd   | j }| j}| j}t|||ddd\}}}}tj||dd\}}	}
t|| t||	 t||
 d S )Nr      r   r   r   r   r   r!   histogram2dr   )r#   r   r   r   r$   binx1biny1r&   r'   binx2biny2r   r   r   test_2d_count   s   


z!TestBinnedStatistic.test_2d_countc                 C   s6   | j }| j}| j}t|||ddd}d}t|| d S )Nr   r~   r   )r/   x_edgey_edgerC   )r   r   r   r   r	   )r#   r   r   r   rD   rE   r   r   r   test_2d_result_attributes   s   z-TestBinnedStatistic.test_2d_result_attributesc                 C   sf   | j }| j}| j}t|||ddd\}}}}tj||d|d\}}	}
t|| t||	 t||
 d S )Nr-   r~   r   rI   r   )r#   r   r   r   rK   r   r   r&   rL   r   r   r   r   r   test_2d_sum   s   

zTestBinnedStatistic.test_2d_sumc                 C   j   | j }| j}| j}t|||ddd\}}}}t|||tjdd\}}	}
}t|| t||	 t||
 d S Nr+   r~   r   r   r   r   r   r!   r+   r   r#   r   r   r   r4   r   r   r&   r5   r   r   r   r   r   test_2d_mean      

z TestBinnedStatistic.test_2d_meanc                 C   r   r   r   r   r   r   r   test_2d_mean_unicode   s   


z(TestBinnedStatistic.test_2d_mean_unicodec                 C   r   )Nr2   r~   r   )r   r   r   r   r!   r2   r   r   r   r   r   test_2d_std   r   zTestBinnedStatistic.test_2d_stdc                 C   r   )NrT   r~   r   )r   r   r   r   r!   rT   r   r   r   r   r   test_2d_min  r   zTestBinnedStatistic.test_2d_minc                 C   r   )NrV   r~   r   )r   r   r   r   r!   rV   r   r   r   r   r   test_2d_max  r   zTestBinnedStatistic.test_2d_maxc                 C   r   )Nr,   r~   r   )r   r   r   r   r!   r,   r   r   r   r   r   test_2d_median  s   


z"TestBinnedStatistic.test_2d_medianc           
         s   | j d d }| jd d }| jd d }t|||ddd\}}} tg d} fddt D }t | ||  }	t||	 d S )NrY   r   r   r   )            r   r      r   r      r   r   r   r   r   r   r   r   r      c                    r[   r   r\   r]   r`   r   r   ra   1  rb   z7TestBinnedStatistic.test_2d_bincode.<locals>.<listcomp>)	r   r   r   r   r!   rc   rd   r   nonzero)
r#   r   r   r   r$   r   r   re   rf   	count1adjr   r`   r   test_2d_bincode'  s   

z#TestBinnedStatistic.test_2d_bincodec                 C   s   | j }| j}| j}| j}t|||ddd\}}}}t|||ddd\}	}
}}t||||gddd\}}}}t|d | t|d |	 t|| t|| t|| d S )Nr+   r   r   r   r   )r   r   r   r   r   r   )r#   r   r   r   r   rw   binx1vbiny1vry   rz   binx1wbiny1wr|   r5   r   r   re   r   r   r   test_2d_multi_values7  s$   



z(TestBinnedStatistic.test_2d_multi_valuesc                 C   s   | j }| j}| j}t||ddd\}}}t||ddd\}}}t|||dddd\}	}
}}tj||dd	}tj||dd	}||| k  d
8  < ||| k  d
8  < t||d  t||d
  t||d  t||d
  d S )Nr+   rY   r   r   )rY   r   Tr   expand_binnumbersright)sider   r   )	r   r   r   r   r   r!   searchsortedrV   r   )r#   r   r   r   statedgesxbcxedgesybcyr5   edgesx2edgesy2re   bcx3bcy3r   r   r   test_2d_binnumbers_unraveledJ  s    z0TestBinnedStatistic.test_2d_binnumbers_unraveledc                 C   r   )Nr   r   r   r   r   r   r!   histogramddr   )r#   r   r   r$   r%   r&   r'   r(   r   r   r   test_dd_counta  r*   z!TestBinnedStatistic.test_dd_countc                 C   r@   )Nr   r   r   rA   )r   r   r   r	   )r#   r   r   rD   rE   r   r   r   test_dd_result_attributesk  rG   z-TestBinnedStatistic.test_dd_result_attributesc                 C   rH   )Nr-   r   r   rI   r   )r#   r   r   rK   r%   r&   rL   r(   r   r   r   test_dd_sums  rN   zTestBinnedStatistic.test_dd_sumc                 C   rO   )Nr+   r   r   )r   r   r   r!   r+   r   r#   r   r   r4   r%   r&   r5   r(   r   r   r   test_dd_mean}  rR   z TestBinnedStatistic.test_dd_meanc                 C   rO   )Nr2   r   r   )r   r   r   r!   r2   r   r   r   r   r   test_dd_std  rR   zTestBinnedStatistic.test_dd_stdc                 C   rO   )NrT   r   r   )r   r   r   r!   rT   r   r   r   r   r   test_dd_min  rR   zTestBinnedStatistic.test_dd_minc                 C   rO   )NrV   r   r   )r   r   r   r!   rV   r   r   r   r   r   test_dd_max  rR   zTestBinnedStatistic.test_dd_maxc                 C   rO   )Nr,   r   r   )r   r   r   r!   r,   r   r   r   r   r   test_dd_median  rR   z"TestBinnedStatistic.test_dd_medianc                    s|   | j d d }| jd d }t||ddd\}} tg d} fddt D }t | ||  }t|| d S )NrY   r   r   r   )?   !   V   S   X   C   9   r   *   )   R   r   \       $   [   +   W   Q   r   c                    r[   r   r\   r]   r`   r   r   ra     rb   z7TestBinnedStatistic.test_dd_bincode.<locals>.<listcomp>)r   r   r   r!   rc   rd   r   r   )r#   r   r   r$   r%   re   rf   r   r   r`   r   test_dd_bincode  s   
z#TestBinnedStatistic.test_dd_bincodec                 C   s   | j }| j}| j}dddddddtjfD ]B}t|||dd	\}}}t|||dd	\}}	}
t|||g|dd	\}}}t|d
 | t|d | t|| t|	| t|| qd S )Nr   r-   r+   r2   rT   rV   r,   r   r   r   r   )r   r   r   r!   r2   r   r   )r#   r   r   r   r   rw   rx   ry   rz   r{   r|   r5   r(   re   r   r   r   test_dd_multi_values  s   

z(TestBinnedStatistic.test_dd_multi_valuesc                 C   s   | j }| j}t|d d df |ddd\}}}t|d d df |ddd\}}}t|d d df |ddd\}}}	t||dd	d
d\}
}}t||d  t||d  t|	|d  d S )Nr   r+   ri   r   r   rY   rZ   r   )ri   rY   r   Tr   )r   r   r   r   r   )r#   r   r   r   r   r   r   r   edgeszbczr5   r(   re   r   r   r   test_dd_binnumbers_unraveled  s   """
z0TestBinnedStatistic.test_dd_binnumbers_unraveledc                 C   sj   t jd}t jd}t ddd}|||f}t||d|d}|j}t||d|d}|j}t|| d S )	N'  r   r   r   r   r   r+   r   )binned_statistic_result)r!   rm   linspacer   r/   r   )r#   r   r   r   resultr   r5   r   r   r   test_dd_binned_statistic_result  s   
z3TestBinnedStatistic.test_dd_binned_statistic_resultc                 C   s~   t jd}t jd}t ddd}t |d}|||f}ttdd t||d|d	 W d    d S 1 s8w   Y  d S )
Nr   r   r   r   r   zdifference is numerically 0matchr+   r   )r!   rm   r   appendr:   r;   r   )r#   r   r   r   r   r   r   test_dd_zero_dedges  s   
"z'TestBinnedStatistic.test_dd_zero_dedgesc                 C   s6  t tdd t| jg| jddggd W d    n1 sw   Y  t tdd t| j| jg| jddgddggd W d    n1 sFw   Y  t tdd t| j| jg| jddgddggd W d    n1 snw   Y  t tdd t| j| jg| jddggd W d    d S 1 sw   Y  d S )	NzIn range, start must be <= stopr   r   r   rk   z.In dimension 1 of range, start must be <= stopz.In dimension 2 of range, start must be <= stopz(range given for 1 dimensions; 2 required)r:   r;   r   r   r   r   )r#   r   r   r   test_dd_range_errors  s>   "z(TestBinnedStatistic.test_dd_range_errorsc                 C   sH   t jddgt jd}t|d ddd\}}}t|t jg dt jd d S )Nr   ghw?)dtyper   r~   r   )r   r   r   r   r   )r!   rc   float32r   r   float64)r#   r   r   rq   r   r   r   test_binned_statistic_float32  s   z1TestBinnedStatistic.test_binned_statistic_float32c           
      C   s   g }d}t |D ]}|dd|  g7 }qtddd}t|tt||gdd\}}}tj||d\}}	t|| t|d |	 d S )	NrY   r   g?r   r   r-   )r   r/   r   )rl   r!   r   r   oneslenr"   r   )
r#   r   r   r_   r   rK   r%   r&   rL   r(   r   r   r   test_gh14332  s   
z TestBinnedStatistic.test_gh14332N)0__name__
__module____qualname__classmethodr   r)   r0   r6   r8   r?   rF   rM   rQ   rS   rU   rW   rX   rg   rv   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   r   r   r   r   r   r   r
      s\    
	
	







	






	r
   )numpyr!   numpy.testingr   pytestr   r:   scipy.statsr   r   r   scipy._lib._utilr   common_testsr	   r
   r   r   r   r   <module>   s    