o
    Ö­j~I  ã                   @   sf   d dl Zd dlmZ d dl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                   @   sÂ  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/e0j1 2dYe3j4e3j5g¡e0j1 2dZe3j6e3j7e3j8e3j9e3j:e3j;d[d\d]„ d^d]„ g	¡d_d`„ ƒƒZ<daS )bÚ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   úd/var/www/html/CropPilot/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"   r3   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   r3   )r   r   Úprintr   r"   r3   r   r4   r   r   r   Útest_empty_bins_std5   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   r3   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   ©r0   Ú	bin_edgesÚ	binnumber)r   r   r   r	   )r$   r   r   ÚresÚ
attributesr   r   r   Útest_1d_result_attributesO   ó
   z-TestBinnedStatistic.test_1d_result_attributesc                 C   sN   | 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_sumW   s   
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   r5   r&   r'   r6   r)   r   r   r   Útest_1d_meana   ó   
z TestBinnedStatistic.test_1d_meanc                 C   rN   r2   )r   r   r   r"   r3   r   rO   r   r   r   Útest_1d_stdk   rQ   zTestBinnedStatistic.test_1d_stdc                 C   rN   )NÚminr   r   )r   r   r   r"   rS   r   rO   r   r   r   Útest_1d_minu   rQ   zTestBinnedStatistic.test_1d_minc                 C   rN   )NÚmaxr   r   )r   r   r   r"   rU   r   rO   r   r   r   Útest_1d_max   rQ   zTestBinnedStatistic.test_1d_maxc                 C   rN   )Nr-   r   r   )r   r   r   r"   r-   r   rO   r   r   r   Útest_1d_median‰   rQ   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   rY   r   r   r   r   r   r   r   r   r   rY   r   r   r   rY   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Úbc1wr6   r)   rd   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   )r0   Úx_edgeÚy_edgerD   )r   r   r   r   r	   )r$   r   r   r   rE   rF   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   r5   r€   r�   r'   r6   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‰   )Nr3   r}   r   )r   r   r   r   r"   r3   r   rŒ   r   r   r   Útest_2d_stdö   rŽ   zTestBinnedStatistic.test_2d_stdc                 C   r‰   )NrS   r}   r   )r   r   r   r   r"   rS   r   rŒ   r   r   r   Útest_2d_min  rŽ   zTestBinnedStatistic.test_2d_minc                 C   r‰   )NrU   r}   r   )r   r   r   r   r"   rU   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 )NrX   r   r   r   )é   é   é   é   r•   r”   é   r”   r”   é   r–   r˜   r—   r–   r•   r—   r–   r–   r•   é   c                    rZ   r   r[   r\   r_   r   r   r`   2  ra   z7TestBinnedStatistic.test_2d_bincode.<locals>.<listcomp>)	r   r   r   r   r"   rb   rc   r   Únonzero)
r$   r   r   r   r%   r€   r�   rd   re   Ú	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   rv   Úbinx1vÚbiny1vrx   ry   Úbinx1wÚbiny1wr{   r6   r‚   rƒ   rd   r   r   r   Útest_2d_multi_values8  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,   rX   r   r   )rX   r   T©r    Úexpand_binnumbersÚright)Úsider   r   )	r   r   r   r   r   r"   ÚsearchsortedrU   r   )r$   r   r   r   ÚstatÚedgesxÚbcxÚedgesyÚbcyr6   Úedgesx2Úedgesy2rd   Úbcx3Úbcy3r   r   r   Útest_2d_binnumbers_unraveledK  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_countb  r+   z!TestBinnedStatistic.test_dd_countc                 C   rA   )Nr   r   r   rB   )r   r   r   r	   )r$   r   r   rE   rF   r   r   r   Útest_dd_result_attributesl  rH   z-TestBinnedStatistic.test_dd_result_attributesc           
      C   sz   | j }| j}t||ddd�\}}}tj|d|d�\}}t||tjdd�\}}	}t||ƒ t||ƒ t||ƒ t||	ƒ d S )Nr.   r   r   rI   )r   r   r   r"   r²   r.   r   )
r$   r   r   rK   r&   r'   rL   r)   Úsum3Úedges3r   r   r   Útest_dd_sumt  s   


zTestBinnedStatistic.test_dd_sumc                 C   rN   )Nr,   r   r   )r   r   r   r"   r,   r   ©r$   r   r   r5   r&   r'   r6   r)   r   r   r   Útest_dd_mean�  rQ   z TestBinnedStatistic.test_dd_meanc                 C   rN   )Nr3   r   r   )r   r   r   r"   r3   r   r¸   r   r   r   Útest_dd_std‹  rQ   zTestBinnedStatistic.test_dd_stdc                 C   rN   )NrS   r   r   )r   r   r   r"   rS   r   r¸   r   r   r   Útest_dd_min•  rQ   zTestBinnedStatistic.test_dd_minc                 C   rN   )NrU   r   r   )r   r   r   r"   rU   r   r¸   r   r   r   Útest_dd_maxŸ  rQ   zTestBinnedStatistic.test_dd_maxc                 C   rN   )Nr-   r   r   )r   r   r   r"   r-   r   r¸   r   r   r   Útest_dd_median©  rQ   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 )NrX   r   r   r   )é?   é!   éV   éS   éX   éC   é9   r¿   é*   é)   éR   rÁ   é\   é    é$   é[   é+   éW   éQ   rÎ   c                    rZ   r   r[   r\   r_   r   r   r`   »  ra   z7TestBinnedStatistic.test_dd_bincode.<locals>.<listcomp>)r   r   r   r"   rb   rc   r   r›   )r$   r   r   r%   r&   rd   re   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,   r3   rS   rU   r-   rš   r   r   r   )r   r   r   r"   r3   r   r   )r$   r   r   r   r¨   rv   rw   rx   ry   rz   r{   r6   r)   rd   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,   rh   r   r   rX   rY   r   )rh   rX   r   Tr£   )r   r   r   r   r   )r$   r   r   r¨   r©   rª   r«   r¬   ÚedgeszÚbczr6   r)   rd   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"   rl   Úlinspacer   r0   r   )r$   r   r   r    Úresultr¨   r6   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"   rl   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 s”w   Y  d S )	NzIn range, start must be <= stoprÚ   r   r   rj   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   gÂhwÄøÛ?)Údtyper   r}   r   )r   r   r   r   r   )r"   rb   Úfloat32r   r   Úfloat64)r$   r   r¨   rp   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 )	NrX   r   gš™™™™™¹?r   r•   r.   )r    r0   r   )rk   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_gh14332rß   r0   r   c                 C   s   | d   ¡ S )NrY   r[   ©r   r   r   r   Ú<lambda>'  s    zTestBinnedStatistic.<lambda>c                 C   s   | d   ¡ d S )NrY   ù              ð?r[   ræ   r   r   r   rç   (  s    c                    s¸   ‡ fdd„}t j d¡}d}|j|d�}|dk}|j|d�}|t ju r-||j|d�d  }t||ˆ dd	�\}	}
}
t  |||  ƒ||| ƒg¡}t|	|ƒ |	jt  |jt j	¡ksZJ ‚d S )
Nc                    s   ˆ dkrt | ƒS ˆ | ƒS )Nr   )rä   ræ   ©r0   r   r   Úref_statistic*  s   z6TestBinnedStatistic.test_dd_all.<locals>.ref_statisticl   #tÆ%i r   r   g      à?rè   rY   r   )
r"   rl   Údefault_rngÚ
complex128r   rb   r   rß   Úresult_typerá   )r$   rß   r0   rê   r   Únr   r^   r   r¨   rp   Úrefr   ré   r   Útest_dd_all$  s   
 
zTestBinnedStatistic.test_dd_allN)=Ú__name__Ú
__module__Ú__qualname__Úclassmethodr   r*   r1   r7   r9   r@   rG   rM   rP   rR   rT   rV   rW   rf   ru   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å   ÚpytestÚmarkÚparametrizer"   rá   rì   r,   r-   r.   r3   rS   rU   rð   r   r   r   r   r
      sj    
	
	







	





	
ýr
   )Únumpyr"   Únumpy.testingr   rõ   r   r;   Úscipy.statsr   r   r   Úscipy._lib._utilr   Úcommon_testsr	   r
   r   r   r   r   Ú<module>   s    