
    5[g~I                     l    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	      Zy)
    N)assert_allclose)raises)binned_statisticbinned_statistic_2dbinned_statistic_dd)check_random_state   )check_named_resultsc                   Z   e Zd Zed        Zd Zd Zd Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d  Z#d! Z$d" Z%d# Z&d$ Z'd% Z(d& Z)d' Z*d( Z+d) Z,d* Z-d+ Z.d, Z/e0jb                  je                  d-e3jh                  e3jj                  g      e0jb                  je                  d.e3jl                  e3jn                  e3jp                  e3jr                  e3jt                  e3jv                  d/d0 d1 g	      d2               Z<y3)4TestBinnedStatisticc                 4   t        d      }|j                  d      | _        |j                  d      | _        |j                  d      | _        |j                  d      | _        |j                  d      | _        |j                  d      dz   | _        y )N&  d   size)r      g    .A)r   uniformxyvXwu)clsrngs     b/var/www/html/bid-api/venv/lib/python3.12/site-packages/scipy/stats/tests/test_binned_statistic.pysetup_classzTestBinnedStatistic.setup_class   s}     &%%%*%%+    c                     | j                   }| j                  }t        ||dd      \  }}}t        j                  |d      \  }}t        ||       t        ||       y )Ncount
   binsr   r   r   np	histogramr   )selfr   r   count1edges1bccount2edges2s           r   test_1d_countz!TestBinnedStatistic.test_1d_count   sS    FFFF-aG"Eab1''r   c                 h    | j                   }| j                  }g d}|D ]  }t        |||d        y )N)meanmedianr    sumr!   r"   )r   r   r   )r'   r   r   
statistics	statistics        r   test_gh5927zTestBinnedStatistic.test_gh5927"   s3     FFFF7
#IQ926 $r   c                     | j                   }| j                  }t        ||dd      \  }}}t        ||t        j                  d      \  }}}t        ||       y Nstdr!   r"   )r   r   r   r%   r7   r   r'   r   r   stat1r)   r*   stat2r,   s           r   test_big_number_stdz'TestBinnedStatistic.test_big_number_std+   sR     FFFF,Q5rBvr,Q266Cvru%r   c                     | j                   }| j                  }t        t        ||dd             t        ||dd      \  }}}t        ||t        j
                  d      \  }}}t        ||       y )Nr    i  r"   r7   )r   r   printr   r%   r7   r   r8   s           r   test_empty_bins_stdz'TestBinnedStatistic.test_empty_bins_std5   sd    FFFFq!W489,Q5tDvr,Q266Evru%r   c           
      P   | j                   }| j                  }|d   }t        j                  |d<   t	        t
        t        ||dd       t	        t
        t        ||dt        j                  d             t        j                  |d<   t	        t
        t        ||dd       ||d<   y )Nr   r7   r!   r"   r    )	r   r   r%   infassert_raises
ValueErrorr   int64nan)r'   r   r   origs       r   #test_non_finite_inputs_and_int_binsz7TestBinnedStatistic.test_non_finite_inputs_and_int_bins?   s     FFFFtvv!j"2Aq%bIj"2Aq%88B<	)vv!j"2Aq'K!r   c                 n    | j                   }| j                  }t        ||dd      }d}t        ||       y )Nr    r!   r"   r3   	bin_edges	binnumber)r   r   r   r
   )r'   r   r   res
attributess        r   test_1d_result_attributesz-TestBinnedStatistic.test_1d_result_attributesO   s3    FFFFq!W26<
C,r   c                     | j                   }| j                  }t        ||dd      \  }}}t        j                  |d|      \  }}t        ||       t        ||       y )Nr1   r!   r"   r#   weightsr$   )r'   r   r   sum1r)   r*   sum2r,   s           r   test_1d_sumzTestBinnedStatistic.test_1d_sumW   sU    FFFF+Aq%bAfb||AB:fd#'r   c                     | j                   }| j                  }t        ||dd      \  }}}t        ||t        j                  d      \  }}}t        ||       t        ||       y )Nr/   r!   r"   )r   r   r   r%   r/   r   r'   r   r   r9   r)   r*   r:   r,   s           r   test_1d_meanz TestBinnedStatistic.test_1d_meana   sZ    FFFF,Q6Cvr,Q277Dvru%'r   c                     | j                   }| j                  }t        ||dd      \  }}}t        ||t        j                  d      \  }}}t        ||       t        ||       y r6   )r   r   r   r%   r7   r   rU   s           r   test_1d_stdzTestBinnedStatistic.test_1d_stdk   Z    FFFF,Q5rBvr,Q266Cvru%'r   c                     | j                   }| j                  }t        ||dd      \  }}}t        ||t        j                  d      \  }}}t        ||       t        ||       y )Nminr!   r"   )r   r   r   r%   r[   r   rU   s           r   test_1d_minzTestBinnedStatistic.test_1d_minu   rY   r   c                     | j                   }| j                  }t        ||dd      \  }}}t        ||t        j                  d      \  }}}t        ||       t        ||       y )Nmaxr!   r"   )r   r   r   r%   r^   r   rU   s           r   test_1d_maxzTestBinnedStatistic.test_1d_max   rY   r   c                     | j                   }| j                  }t        ||dd      \  }}}t        ||t        j                  d      \  }}}t        ||       t        ||       y )Nr0   r!   r"   )r   r   r   r%   r0   r   rU   s           r   test_1d_medianz"TestBinnedStatistic.test_1d_median   sZ    FFFF,Q8"Evr,Q2992Fvru%'r   c                 4   | j                   d d }| j                  d d }t        ||dd      \  }}}t        j                  g d      }t        j
                  |      D cg c]  }||k(  j                          }}t        ||       t        ||       y c c}w )N   r    r   r"   )r      r	   r   rd   r   r   r   r   r	   r	   r   r   r	   rd   r   r	   r	   rd   r	   )r   r   r   r%   arrayuniquer1   r   )	r'   r   r   r(   r)   r*   bc2ibcounts	            r   test_1d_bincodez#TestBinnedStatistic.test_1d_bincode   s    FF3BKFF3BK-aG!Dhh ! " ,.99R=9=a27--/=9C ' :s    Bc                    t         j                  j                  d       t        j                  d      }t         j                  j                  d      }t	        |d d |d d       \  }}}t	        ||dg      \  }}}t	        ||d      \  }}	}t        ||       t        ||       t        ||       t        ||	       y )Nr         )r      range)r%   randomseedaranger   r   )
r'   r   datar/   r#   _
mean_range
bins_rangemean_range2bins_range2s
             r   test_1d_range_keywordz)TestBinnedStatistic.test_1d_range_keyword   s    
		tIIbMyy#(3Bcr;dA$4QWI$N!
J&6q$g&N#[!j)j)k*k*r   c                 .   | j                   }| j                  }| j                  }t        ||dd      \  }}}t        ||dd      \  }}}	t        |||gdd      \  }
}}t	        |
d   |       t	        |
d   |       t	        ||       t	        ||       y )Nr/   r!   r"   r   r	   )r   r   r   r   r   )r'   r   r   r   stat1vedges1vbc1vstat1wedges1wbc1wr:   r,   rg   s                r   test_1d_multi_valuesz(TestBinnedStatistic.test_1d_multi_values   s    FFFFFF 0AvB G 0AvB G-a!QbIvsa&)a&)(c"r   c                     | j                   }| j                  }| j                  }t        |||dd      \  }}}}t	        j
                  ||d      \  }}	}
t        ||       t        ||	       t        ||
       y )Nr       r"   r   r   r   r   r%   histogram2dr   )r'   r   r   r   r(   binx1biny1r*   r+   binx2biny2s              r   test_2d_countz!TestBinnedStatistic.test_2d_count   sr    FFFFFF#6q!W1$& ub!~~a;u'u%u%r   c                     | j                   }| j                  }| j                  }t        |||dd      }d}t	        ||       y )Nr    r   r"   )r3   x_edgey_edgerJ   )r   r   r   r   r
   )r'   r   r   r   rK   rL   s         r   test_2d_result_attributesz-TestBinnedStatistic.test_2d_result_attributes   s>    FFFFFF!!Q7;C
C,r   c                     | j                   }| j                  }| j                  }t        |||dd      \  }}}}t	        j
                  ||d|      \  }}	}
t        ||       t        ||	       t        ||
       y )Nr1   r   r"   rO   r   )r'   r   r   r   rQ   r   r   r*   rR   r   r   s              r   test_2d_sumzTestBinnedStatistic.test_2d_sum   sq    FFFFFF!4Q1e!!LeUB^^Aqq!DeUd#u%u%r   c                    | j                   }| j                  }| j                  }t        |||dd      \  }}}}t        |||t        j
                  d      \  }}	}
}t        ||       t        ||	       t        ||
       y Nr/   r   r"   r   r   r   r   r%   r/   r   r'   r   r   r   r9   r   r   r*   r:   r   r   s              r   test_2d_meanz TestBinnedStatistic.test_2d_mean   su    FFFFFF"5aAvA"NueR"5aArwwQ"OueRu%u%u%r   c                    | j                   }| j                  }| j                  }t        |||dd      \  }}}}t        |||t        j
                  d      \  }}	}
}t        ||       t        ||	       t        ||
       y r   r   r   s              r   test_2d_mean_unicodez(TestBinnedStatistic.test_2d_mean_unicode   sx    FFFFFF"5q!V!#%ueR"5aArwwQ"OueRu%u%u%r   c                    | j                   }| j                  }| j                  }t        |||dd      \  }}}}t        |||t        j
                  d      \  }}	}
}t        ||       t        ||	       t        ||
       y )Nr7   r   r"   )r   r   r   r   r%   r7   r   r   s              r   test_2d_stdzTestBinnedStatistic.test_2d_std   u    FFFFFF"5aAu1"MueR"5aArvvA"NueRu%u%u%r   c                    | j                   }| j                  }| j                  }t        |||dd      \  }}}}t        |||t        j
                  d      \  }}	}
}t        ||       t        ||	       t        ||
       y )Nr[   r   r"   )r   r   r   r   r%   r[   r   r   s              r   test_2d_minzTestBinnedStatistic.test_2d_min  r   r   c                    | j                   }| j                  }| j                  }t        |||dd      \  }}}}t        |||t        j
                  d      \  }}	}
}t        ||       t        ||	       t        ||
       y )Nr^   r   r"   )r   r   r   r   r%   r^   r   r   s              r   test_2d_maxzTestBinnedStatistic.test_2d_max  r   r   c                    | j                   }| j                  }| j                  }t        |||dd      \  }}}}t        |||t        j
                  d      \  }}	}
}t        ||       t        ||	       t        ||
       y )Nr0   r   r"   )r   r   r   r   r%   r0   r   r   s              r   test_2d_medianz"TestBinnedStatistic.test_2d_median  s}    FFFFFF"5q!XA#'ueR"5q!RYYQ#(ueR 	u%u%u%r   c                 |   | j                   d d }| j                  d d }| j                  d d }t        |||dd      \  }}}}t	        j
                  g d      }t	        j                  |      D 	cg c]  }	||	k(  j                          }
}	t        ||       ||j                            }t        |
|       y c c}	w )Nrc   r    r   r"   )            r   r      r   r      r   r   r   r   r   r   r   r   r      )
r   r   r   r   r%   re   rf   r1   r   nonzero)r'   r   r   r   r(   r   r   r*   rg   rh   ri   	count1adjs               r   test_2d_bincodez#TestBinnedStatistic.test_2d_bincode(  s    FF3BKFF3BKFF3BK#6q!W1$& ubhh 0 1 ,.99R=9=a27--/=9C 6>>+,		*	 :s   1B9c                 j   | j                   }| j                  }| j                  }| j                  }t	        |||dd      \  }}}}t	        |||dd      \  }	}
}}t	        ||||gdd      \  }}}}t        |d   |       t        |d   |	       t        ||       t        ||       t        ||       y )Nr/   r   r"   r   r	   )r   r   r   r   r   r   )r'   r   r   r   r   r|   binx1vbiny1vr~   r   binx1wbiny1wr   r:   r   r   rg   s                    r   test_2d_multi_valuesz(TestBinnedStatistic.test_2d_multi_values8  s    FFFFFFFF':q!V!(%$':q!V!(%$#6q1a&&q$* ueS 	a&)a&)&&c"r   c                    | j                   }| j                  }| j                  }t        ||dd      \  }}}t        ||dd      \  }}}t	        |||ddd      \  }	}
}}t        j                  ||d	      }t        j                  ||d	      }|||j                         k(  xx   d
z  cc<   |||j                         k(  xx   d
z  cc<   t        ||d          t        ||d
          t        ||d          t        ||d
          y )Nr/   rc   r"   r!   )rc   r!   Tr#   expand_binnumbersright)sider	   r   )	r   r   r   r   r   r%   searchsortedr^   r   )r'   r   r   r   statedgesxbcxedgesybcyr:   edgesx2edgesy2rg   bcx3bcy3s                  r   test_2d_binnumbers_unraveledz0TestBinnedStatistic.test_2d_binnumbers_unraveledK  s    FFFFFF,Q6Cfc,Q6Cfc':q!V(d(D$w vqw7vqw7 	Q!%%'\aQ!%%'\aSV$SV$c!f%c!f%r   c                     | j                   }| j                  }t        ||dd      \  }}}t        j                  |d      \  }}t        ||       t        ||       y )Nr    r   r"   )r   r   r   r%   histogramddr   )r'   r   r   r(   r)   r*   r+   r,   s           r   test_dd_countz!TestBinnedStatistic.test_dd_countb  sS    FFFF0AwQG2''r   c                 n    | j                   }| j                  }t        ||dd      }d}t        ||       y )Nr    r   r"   rH   )r   r   r   r
   )r'   r   r   rK   rL   s        r   test_dd_result_attributesz-TestBinnedStatistic.test_dd_result_attributesl  s3    FFFF!!Qa8<
C,r   c                 2   | j                   }| j                  }t        ||dd      \  }}}t        j                  |d|      \  }}t        ||t        j
                  d      \  }}	}t        ||       t        ||       t        ||       t        ||	       y )Nr1   r   r"   rO   )r   r   r   r%   r   r1   r   )
r'   r   r   rQ   r)   r*   rR   r,   sum3edges3s
             r   test_dd_sumzTestBinnedStatistic.test_dd_sumt  s    FFFF.q!UCfb~~aa;f.q!RVV!Dfbd#'d#'r   c                     | j                   }| j                  }t        ||dd      \  }}}t        ||t        j                  d      \  }}}t        ||       t        ||       y )Nr/   r   r"   )r   r   r   r%   r/   r   r'   r   r   r9   r)   r*   r:   r,   s           r   test_dd_meanz TestBinnedStatistic.test_dd_mean  sZ    FFFF/1f1Evr/1bggAFvru%'r   c                     | j                   }| j                  }t        ||dd      \  }}}t        ||t        j                  d      \  }}}t        ||       t        ||       y )Nr7   r   r"   )r   r   r   r%   r7   r   r   s           r   test_dd_stdzTestBinnedStatistic.test_dd_std  Z    FFFF/1e!Dvr/1bff1Evru%'r   c                     | j                   }| j                  }t        ||dd      \  }}}t        ||t        j                  d      \  }}}t        ||       t        ||       y )Nr[   r   r"   )r   r   r   r%   r[   r   r   s           r   test_dd_minzTestBinnedStatistic.test_dd_min  r   r   c                     | j                   }| j                  }t        ||dd      \  }}}t        ||t        j                  d      \  }}}t        ||       t        ||       y )Nr^   r   r"   )r   r   r   r%   r^   r   r   s           r   test_dd_maxzTestBinnedStatistic.test_dd_max  r   r   c                     | j                   }| j                  }t        ||dd      \  }}}t        ||t        j                  d      \  }}}t        ||       t        ||       y )Nr0   r   r"   )r   r   r   r%   r0   r   r   s           r   test_dd_medianz"TestBinnedStatistic.test_dd_median  sZ    FFFF/1hQGvr/1biiaHvru%'r   c                 Z   | j                   d d }| j                  d d }t        ||dd      \  }}}t        j                  g d      }t        j
                  |      D cg c]  }||k(  j                          }}t        ||       ||j                            }	t        ||	       y c c}w )Nrc   r    r   r"   )?   !   V   S   X   C   9   r   *   )   R   r   \       $   [   +   W   Q   r   )	r   r   r   r%   re   rf   r1   r   r   )
r'   r   r   r(   r)   r*   rg   rh   ri   r   s
             r   test_dd_bincodez#TestBinnedStatistic.test_dd_bincode  s    FF3BKFF3BK0AwQGhh 4 5 ,.99R=9=a27--/=9C 6>>+,		*	 :s    B(c                    | j                   }| j                  }| j                  }dddddddt        j                  fD ]  }t        |||d	      \  }}}t        |||d	      \  }}	}
t        |||g|d	      \  }}}t        |d
   |       t        |d   |       t        ||       t        |	|       t        ||        y )Nr    r1   r/   r7   r[   r^   r0   r   r"   r   r	   )r   r   r   r%   r7   r   r   )r'   r   r   r   r   r|   r}   r~   r   r   r   r:   r,   rg   s                 r   test_dd_multi_valuesz(TestBinnedStatistic.test_dd_multi_values  s    FFFFFFeVUE5(VVD$71d$K!FGT$71d$K!FGT!4QA1!ME63E!Hf-E!Hf-GV,GV,D#&r   c                 R   | j                   }| j                  }t        |d d df   |dd      \  }}}t        |d d df   |dd      \  }}}t        |d d df   |dd      \  }}}	t        ||dd	d
      \  }
}}t	        ||d          t	        ||d          t	        |	|d          y )Nr   r/   rm   r"   r	   rc   rd   r!   )rm   rc   r!   Tr   )r   r   r   r   r   )r'   r   r   r   r   r   r   r   edgeszbczr:   r,   rg   s                r   test_dd_binnumbers_unraveledz0TestBinnedStatistic.test_dd_binnumbers_unraveled  s    FFFF,Qq!tWabIfc,Qq!tWabIfc,Qq!tWabIfc0q&|tEvs 	SV$SV$SV$r   c                 <   t         j                  j                  d      }t         j                  j                  d      }t        j                  ddd      }|||f}t        ||d|      }|j                  }t        ||d|      }|j                  }t        ||       y )	N'  r   r   r   r	   r!   r/   r"   )binned_statistic_result)r%   rq   linspacer   r3   r   )r'   r   r   r#   resultr   r:   s          r   test_dd_binned_statistic_resultz3TestBinnedStatistic.test_dd_binned_statistic_result  s    IIZ(IIU#{{1a$dD!$Q6=$Q6=CE  e$r   c                 N   t         j                  j                  d      }t         j                  j                  d      }t        j                  ddd      }t        j                  |d      }|||f}t	        t
        d      5  t        ||d|	       d d d        y # 1 sw Y   y xY w)
Nr   r   r   r	   r!   zdifference is numerically 0matchr/   r"   )r%   rq   r   appendrA   rB   r   )r'   r   r   r#   s       r   test_dd_zero_dedgesz'TestBinnedStatistic.test_dd_zero_dedges  s~    IIZ(IIU#{{1a$yyq!dD!:-JK1f48 LKKs   BB$c                    t        t        d      5  t        | j                  g| j                  ddgg       d d d        t        t        d      5  t        | j
                  | j                  g| j                  ddgddgg       d d d        t        t        d      5  t        | j
                  | j                  g| j                  ddgddgg       d d d        t        t        d      5  t        | j
                  | j                  g| j                  ddgg       d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   mxY w# 1 sw Y   y xY w)	NzIn range, start must be <= stopr   r	   r   ro   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)rA   rB   r   r   r   r   )r'   s    r   test_dd_range_errorsz(TestBinnedStatistic.test_dd_range_errors  s<    :!BD$&&()1vh0D FH   0$&&()1v1v&68H
 FH   0$&&()1v1v&68H
 @B   0$&&()1vh0B BD DH H
H H
B Bs/   'D)5D5 5E.2E)D25D>E
Ec                     t        j                  ddgt         j                        }t        |d dd      \  }}}t	        |t        j                  g dt         j
                               y )Nr   ghw?)dtyper    r   r"   )r	   r   r   r   r	   )r%   re   float32r   r   float64)r'   r   r   ru   s       r   test_binned_statistic_float32z1TestBinnedStatistic.test_binned_statistic_float32  sI    HHa_BJJ7%awQ?
abhhbjjIJr   c                 <   g }d}t        |      D ]  }|dd|z  z
  gz  } t        j                  ddd      }t        |t        j                  t        |            |gd      \  }}}t        j                  ||      \  }}	t        ||       t        |d   |	       y )	Nrc   r	   g?r   r   r1   )r#   r3   r"   )rp   r%   r   r   oneslenr&   r   )
r'   r   r   rh   r#   rQ   r)   r*   rR   r,   s
             r   test_gh14332z TestBinnedStatistic.test_gh14332  s    tA!CF(OA  {{1Qr".q"''#a&/59FeMfb||AD1fd#q	6*r   r   r3   r    c                 (    | dz  j                         S )Nrd   r1   r   s    r   <lambda>zTestBinnedStatistic.<lambda>'  s    adZZ\r   c                 .    | dz  j                         dz  S )Nrd                 ?r	  r
  s    r   r  zTestBinnedStatistic.<lambda>(  s    adZZ\B5Fr   c                    fd}t         j                  j                  d      }d}|j                  |      }|dk\  }|j                  |      }|t         j                  u r||j                  |      dz  z   }t	        ||d      \  }	}
}
t        j
                   |||           |||         g      }t        |	|       |	j                  t        j                  |j                  t         j                        k(  sJ y )	Nc                 4    dk(  rt        |       S  |       S )Nr    )r  )r   r3   s    r   ref_statisticz6TestBinnedStatistic.test_dd_all.<locals>.ref_statistic*  s    &'13q6Cy|Cr   l   #t%i r!   r   g      ?r  rd   r"   )
r%   rq   default_rng
complex128r   re   r   r   result_typer  )r'   r   r3   r  r   nr   rh   r   r   ru   refs     `         r   test_dd_allzTestBinnedStatistic.test_dd_all$  s    	D ii##$45JJAJHJJAJBMM!CJJAJ&r))A(AyqA
ahhae,mAaD.ABCc"zzR^^CIIrzzBBBBr   N)=__name__
__module____qualname__classmethodr   r-   r4   r;   r>   rF   rM   rS   rV   rX   r\   r_   ra   rj   rz   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/   r0   r1   r7   r[   r^   r   r   r   r   r      so   , ,(7&& -(((((((+#&-
&
&	&
&
&
&&+ #&&.(-((((((+' %% 90.K
+ [[Wrzz2==&AB[[[277BIIrvvrvv+-662667+A+F+H IC	I C
Cr   r   )numpyr%   numpy.testingr   r  r   rA   scipy.statsr   r   r   scipy._lib._utilr   common_testsr
   r   r  r   r   <module>r$     s/     )  *. . / -lC lCr   