
    biB                       d dl mZ d dlZd dlZd dlmZ  ej                  d      Zd dlZ	d dl
mZ d dlmZ d dlmZ  ej$                         r ej&                  dd       g d	Zej*                  j-                  d
ej/                  e	j0                  j3                  ddd            ej/                   e	j4                  e	j0                  j7                  d                  ej9                  e	j0                  j3                  ddd      e	j0                  j3                  ddd       e	j4                  e	j0                  j7                  d            d      ej/                  e	j0                  j3                  ddd       ed            ej/                   e	j4                  e	j0                  j7                  d             ed            ej9                  e	j0                  j3                  ddd      e	j0                  j3                  ddd       e	j4                  e	j0                  j7                  d            d ed            g      ej*                  j-                  de      d               Zej*                  j-                  dg d      d        Zd Z dddddd ejB                  dej*                  jE                  d      g       ejB                  d ej*                  jE                  d      g      d!d"d#d$d%d&d'd(d)d*d+d,d-d"d!d#gZ#ej*                  j-                  de#      ej*                  j-                  d.d/ d0 g      d1               Z$ej*                  j-                  d2ej/                  e	j0                  j3                  ddd            d3d4fej9                  e	j0                  j3                  ddd5      d6d7g8      d9d:fg      d;        Z%ej*                  j-                  de      d<        Z&d= Z'ej*                  j-                  d>ej/                   e	j4                  e	j0                  j7                  d                  ej9                  e	j0                  j3                  ddd      e	j0                  j3                  ddd       e	j4                  e	j0                  j7                  d            d      g      ej*                  j-                  d?d@ ejP                  ej/                  d g      d      jS                         g      ej*                  j-                  de#      dA                      Z*ej*                  jW                  dBC      ej*                  j-                  de#      ej*                  j-                  dDej/                  e	j0                  j3                  dddE             ejX                  e	j0                  j3                  dddE      dFG      fej9                  e	j0                  j3                  ddd5      d6d7g8       ejX                  e	j0                  j3                  ddd5      dHG      fg      dI                      Z-ej*                  j-                  dJg dK      ej*                  j-                  de      ej*                  j-                  dej/                   e	j4                  e	j0                  j7                  d                  ej9                  e	j0                  j3                  ddd      e	j0                  j3                  ddd       e	j4                  e	j0                  j7                  d            d      g      dL                      Z.ej*                  j-                  dej/                  e	j0                  j3                  ddd            ej9                  e	j0                  j3                  ddd      e	j0                  j3                  ddd       e	j4                  e	j0                  j7                  d            d      g      ej*                  j-                  dMdNdO e	j^                  dN       e	j`                  dO      g      dP               Z1y)Q    )annotationsN)NUMPY_GE_200pandas	assert_eqz'parametrize using unsupported functionsT)allow_module_level)*conjexploglog2log10log1pexpm1sqrtsquaresincostanarcsinarccosarctansinhcoshtanharcsinharccosharctanhdeg2radrad2degisfiniteisinfisnansignbitdegreesradiansrintfabssignabsolutefloorceiltrunclogical_notcbrtexp2negative
reciprocalspacingpandas_input   d      sizeABCabcdefghijklmnopqrstindexufuncc                p   t        t        |      }t        t        |      }t        j                  | d      }| j
                  }|j
                  }t        j                         5  t        j                  dt               t         ||      |      sJ t         ||       ||              t        |t        j                        rt         ||      |      sJ t         ||      |      sJ t         ||       ||              t         ||       |      sJ t         ||       ||              d d d        | j                  j                  j                  dv ry |dv ry t        j                         5  t        j                  dt               t         ||j                        t        j                         sJ t         ||j                         || j                        |dk7         t        |t        j                        r,t         ||j                        t        j                         s.J t         ||j                        t"        j                         sJ t         ||j                         ||j                        |dk7         d d d        t        j                         5  t        j                  dt               t         || j                        t"        j                         sJ t         ||        ||              d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)N   ignore)objectstr)r-   r#   r"   r!   r    r2   )check_divisions)getattrdanpddfrom_pandas	__class__warningscatch_warningssimplefilterRuntimeWarning
isinstancer   r@   r?   dtypenameIndexpd)r3   r@   dafuncnpfunc
dask_inputpandas_type	dask_types          Z/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/dask/dataframe/tests/test_ufunc.py
test_ufuncr\   B   s   8 RFRFa0J((K$$I 
	 	 	" <h7&,i888&$f\&:; fbhh'fZ0)<<<fZ0+>>>&$f\&:; &.<<<&$f\&:;<$ $$(99HH		 	 	" 
h7&!1!12BHH===:##$<%%&!Y.	
 fbhh'fZ%5%56AAAfZ%5%56AAA:##$:##$!Y.	

, 
	 	 	" >h7&!3!34bhh???&&|(<=	> >[< <.
 
,> >s'   #CL4DL +AL,L L),L5)	isreal	iscomplexrealimaganglefixi0sinc
nan_to_numc           	        ddl m} | dk(  rt        j                  d       t	        t
        |       }t	        t        |       }t        j                  t        j                  j                  ddd      t        d	      
      }t        j                  |d      }t         ||      t
        j                        sJ  | ||       ||             t         ||      t        j                         sJ t        j"                  j%                   ||       ||             t         ||      t        j                         sJ t        j"                  j'                   ||       ||             t        j)                  t        j                  j                  ddd      t        j                  j                  ddd      t        j*                  t        j                  j-                  d            dt        d	      
      }t        j                  |d      }t         ||      t
        j                        sJ  | ||       ||             t         ||      t        j                         sJ t        j"                  j'                   ||       ||             t         ||      t        j                         sJ t        j"                  j'                   ||       ||             y)a"  
    some np.ufuncs doesn't call __array_wrap__
    (or __array_ufunc__ starting from numpy v.1.13.0), it should work as below

    - da.ufunc(dd.Series) => da.Array
    - da.ufunc(pd.Series) => np.ndarray
    - np.ufunc(dd.Series) => np.ndarray
    - np.ufunc(pd.Series) => np.ndarray
    r   r   rb   z3fix calls floor in a way that we do not yet supportr4   r5   r6   r7   r=   r>   rB   r9   N)dask.array.utilsr   pytestskiprG   rH   rI   rU   SeriesrandomrandintlistrJ   rK   rQ   Arrayndarraytestingassert_equalassert_array_equal	DataFrameabsrandn)r@   da_assert_eqrV   rW   sdsdfddfs           r[   test_ufunc_wrappedr{      s!   0 ;~IJRFRF
		
		!Sr*$7M2N 	 	A 
1	B fRj"((+++VAY'fRj"**---JJF2Jq	2fQi,,,JJ!!&)VAY7	""1c"3""1c"3		+,	

 )* 
 
B ..Q
C fSk288,,,fRj)fSk2::...JJ!!&+vbz:fRj"**---JJ!!&*fRj9    c            	        t         j                  t        j                  j	                  ddd      t        d            } t        j                  | d      }t        j                  t        d	      5  t        j                  |d
       d d d        t         j                  t        j                  j	                  ddd      t        j                  j	                  ddd      t        j                  t        j                  j                  d            dt        d            }t        j                  |d      }t        j                  t        d	      5  t        j                  |d
       d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr4   r5   r6   r7   r=   r>   rB   z`repeat` is not implemented)match
   r9   )rU   rj   rI   rk   rl   rm   rJ   rK   rh   raisesNotImplementedErrorrepeatrs   rt   ru   )rw   rx   ry   rz   s       r[   "test_ufunc_wrapped_not_implementedr      s5   
		
		!Sr*$7M2N 	 	A 
1	B	*2O	P 
		"b 
""1c"3""1c"3		+,	

 )* 
 
B ..Q
C	*2O	P 
		#r   s   2E6F6E?F	logaddexp
logaddexp2arctan2hypotcopysign	nextafterldexpzignore::RuntimeWarning)marksfmodlogical_and
logical_orlogical_xormaximumminimumfmaxfmingreatergreater_equalless
less_equal	not_equalequalmake_pandas_inputc                 l    t         j                  t        j                  j	                  ddd            S )Nr4   r5   r6   r7   )rU   rj   rI   rk   rl    r|   r[   <lambda>r     s%    		"))++As+<= r|   c                 t    t         j                  t        j                  j	                  ddd      ddg      S )Nr4   r5   r6      r7   r:   r;   columns)rU   rs   rI   rk   rl   r   r|   r[   r   r     s3    IIa73c3Z  
 r|   c                F   t        t        |       }t        t        |       } |       } |       }t        j                  |d      }t        j                  |d      }|j
                  }|j
                  }	t         |||      |	      sJ t         |||       |||             t         |||      |	      sJ t         |||       |||             t        |t        j                        r*t         |||      |	      sJ t         |||      |	      s,J t         |||      |      sJ t         |||      |      sJ t         |||       |||             t         |||       |||             t         |||      |      sJ t         |||       |||             y )NrB      )	rG   rH   rI   rJ   rK   rL   rQ   r   r@   )
r@   r   rV   rW   pandas1pandas2dask1dask2rY   rZ   s
             r[   test_ufunc_with_2argsr     s    RFRF!G!GNN7A&ENN7A&E##KI fUE*I666fUE"F7G$<= fUG,i888fUG$fWg&>? &"((#&.	:::&0)<<<&.<<<&0+>>>fUE"F7G$<=fUG$fWg&>? fWg.<<<fWg&w(@Ar|   zpandas,min,max   2   r   r:   r;   r   g      @g     @D@c                v   t        j                  | d      }| j                  }|j                  }t        t	        j
                  |||      |      sJ t        t	        j
                  |||      t        j
                  | ||             t        t        j
                  |||      |      sJ t        t        j
                  |||      t        j
                  | ||             t        t	        j
                  | ||      |      sJ t        t	        j
                  | ||      t        j
                  | ||             y )NrB   )rJ   rK   rL   rQ   rH   clipr   rI   )r   minmaxdaskrY   rZ   s         r[   	test_clipr   ?  s     >>&!$D""KI
 bggdC-y999bggdC%rwwvsC'@A bggdC-y999bggdC%rwwvsC'@A bggfc3/===bggfc3'c)BCr|   c                R   t        t        |       }t        t        |       }t        j                  j	                  ddd      }t
        j                  |ddg      }t        j                  |d      }t
        j                  t        j                  j	                  ddd      d	d
g      }t        j                  |d      }t        j                  |d      }t        j                         5  t        j                  dt                |||        |||       t        ||       d d d        t        j                         5  t        j                  dt               t
        j                   ||      ddg      }	t        ||	       d d d        y # 1 sw Y   lxY w# 1 sw Y   y xY w)Nr4   r5   r   r7   r:   r;   r   rB   YZrC   out)rG   rI   rH   rk   rl   rU   rs   rJ   rK   rM   rN   rO   rP   r   )
r@   rW   rV   input_matrixry   rz   df_out
ddf_out_np
ddf_out_daexpecteds
             r[   test_frame_ufunc_outr   ^  sT   RFRF99$$Q'$:L	lS#J	7B
..Q
C\\"))++As+ACQT:\VF*J*J		 	 	" *h7s
#s
#*j)	* 
	 	 	" (h7<<| 4sCj<I*h'( (* *( (s   +;FAFFF&c                     t         j                  j                  ddd      } t        j	                  | ddg      }t        j                  |d      }t        j	                  t         j                  j                  ddd	      g d
      }t        j                  |d      }t        j                  t              5  t        j                  ||       d d d        t        j                  t        j                  dg      d      }t        j                  t              5  t        j                  ||       d d d        t        j	                  t         j                  j                  ddd      ddg      }t        j                  |d      }t        j                  ||       t        j                  |d|       t        j	                  t        j                  |       dz   ddg      }t        ||       y # 1 sw Y   'xY w# 1 sw Y   xY w)Nr4   r5   r   r7   r:   r;   r   rB   )r6   rB   )Xr   r   r   r   r   r   r   )rI   rk   rl   rU   rs   rJ   rK   rh   r   
ValueErrorr   rj   	TypeErroraddr   )r   ry   rz   r   ddf_outr   s         r[   test_frame_2ufunc_outr   w  s   99$$Q'$:L	lS#J	7B
..Q
C \\
		!Sw/  F nnVQ'G	z	" !
s ! nnRYYs^Q/G	y	! !
s ! \\"))++As+ACQT:\VFnnVQ'GFF3GFF7BG$||BFF<025Sz|JHgx !! !
! !s   :G7H7HHarg1arg2r   c                   t        t        |       }t        t        |       }t        j                  |d      }|j
                  }|j
                  }t         |||      |      sJ t         |||       |||             t         |||      |      sJ t         |||       |||             t         |||      |      sJ t         |||       |||             | dk(  ry t         |||      |      sJ t         |||       |||             t         |||      |      sJ t         |||       |||             t         |||      |      sJ t         |||       |||             y )NrB   r   )rG   rI   rH   rJ   rK   rL   rQ   r   )r@   r   r   rW   rV   r   rY   rZ   s           r[   test_mixed_typesr     sq     RFRF>>$"D..KI fT4()444fT4 &t"45 fT4()444fT4 &t"45 fT4(+666fT4 &t"45
  fT4()444fT4 &t"45 fT4()444fT4 &t"45 fT4(+666fT4 &t"45r|   z6doesn't work at the moment, all return not implemented)reasonzpandas,darray)r5   )r   )chunks)r   r   c                d   t        t        |       }t        t        |       }t        j                  |d      }|j
                  }t         |||      |      sJ t         |||      |      sJ t        j                  j                   |||      j                         j                   ||j                  |      j                                t         |||      |      sJ t         |||      |      sJ t        j                  j                   |||      j                         j                   ||j                  |j                                      t        j                  j                   |||      j                         j                   ||j                         |j                               y )Nr   )rG   rH   rI   rJ   rK   rL   rQ   rp   rr   computevalues)r@   r   darrayrV   rW   r   rZ   s          r[   test_2args_with_arrayr     sV   $ RFRF>>&!$DI fT6*I666fVT*I666JJ!!tV$$&--vfmmV/L/T/T/V
 fT6*I666fVT*I666JJ!!tV$$&--vfmmV^^EU/V JJ!!vt$$&--vfnn6F/Vr|   redfunc)sumprodr   r   meanc           	        t        j                  |d      }t        t        |       }t        t        |      }t        r8| dk(  r3|dv r/t        |t        j                        rt        j                  d       | dk(  r3|dv r/t        |t        j                        rt        j                  d       t        j                         5  t        j                  dt               t        j                  dt               t         ||      t         j                  t         j                   t         j"                  f      sJ t%         | ||             | ||                   d d d        y # 1 sw Y   y xY w)NrB   r   )r*   r+   r,   z7Numpy started overflowing while we are casting to float)r	   r   r0   r)   z7'prod' overflowing with integer columns in pandas 1.2.0rC   )rJ   rK   rG   rI   r   rQ   rU   rs   rh   ri   xfailrM   rN   rO   rP   FutureWarningrj   Scalarr   )r   r@   r   r   
np_redfuncnp_ufuncs         r[   test_ufunc_with_reductionr     s     >>&!$DW%Jr5!H 	v//vr||,MN 	6??vr||, 	NO		 	 	" Lh7h6*T*R\\299bii,PQQQ*Xd^,j&9I.JK	L L Ls   BE$$E-scalar   gffffff0@c                Z    |t        j                  | d      k\  }|| k\  }t        ||       y )NrB   )npartitions)rJ   rK   r   )r   r   dask_comparepandas_compares       r[   "test_ufunc_numpy_scalar_comparisonr   (  s-    " R^^FBBLv%NlN+r|   )2
__future__r   rM   rh   dask.array.numpy_compatr   importorskiprU   numpyrI   
dask.arrayarrayrH   dask.dataframe	dataframerJ   dask.dataframe.utilsr   _array_expr_enabledri   _BASE_UFUNCSmarkparametrizerj   rk   rl   rt   ru   rs   rm   r\   r{   r   paramfilterwarnings_UFUNCS_2ARGr   r   r   r   rK   r   r   r   
from_arrayr   r   int64float64r   r   r|   r[   <module>r      s   "   0V"    *2FKK9dS+\ 
		"))##As#45
		&"&&-./
YY&&q#B&7YY&&q#B&7RVVBIIOOB/0	
 			IIa2.d;Q6R 	 	
 			&"&&,-T:P5Q	R
YY&&q#B&7YY&&q#B&7RVVBIIOOB/0
 -. 	 	
4 ,/:> 056:>z 
3:3:l. FLL!;!;<T!U VWFLL : :;S TUV


18 ,/=	
"B 0"BJ 	299$$Q"$5	62>LL**1c*@3PS*LU	

D
D( ,/( 0(0!> 

		&"&&-./
YY&&q#B&7YY&&q#B&7RVVBIIOOB/0	
	 !^R^^BIIqcNA%F%J%J%L!MN,/%6 0 O%6P C   ,/ IIbii''3V'<=BMM"))++As+@O	

 LL**1c*@3PS*LUBMM"))++As+A'R	
	 0"6 $IJ,/
		&"&&-./
YY&&q#B&7YY&&q#B&7RVVBIIOOB/0	
	L 0 KL@ 
		"))##As#56
YY&&q#B&7YY&&q#B&7RVVBIIOOB/0	
	 BhbhhrlJBJJt<L#MN, O,r|   