
    e                     b   d Z ddlZddlZddlmZmZmZ ddlZ	ddl
mZmZmZmZ ddlZej                            d e	j        d          d 	          d
             Zd Zd Zej                            de          d             Zd Zej                            de          d             ZdS )zTest replace().    N)assert_equalassert_array_equalassert_raises   )arraysarray_orderDTYPES
INT_DTYPESfunc	nonreducec                     | j         S )N)__name__)xs    ?lib/python3.11/site-packages/bottleneck/tests/nonreduce_test.py<lambda>r      s         )idsc                 4   d}|dz  }| j         }t          d|z            }t          j                            g d          }ddt          j        t          j         g}t          t          |                    D ]\  }}t          d          D ]}|j
        dk    rd}	n5|                    t          |j
        d                    }|j        |         }	|D ]}
t          |j        j        t          j                  s*t          j        |	          s<t          j        |
          sQ|                                }t)          j                    5  t)          j        d            | ||	|
           d	d	d	           n# 1 swxY w Y   |                                }t)          j                    5  t)          j        d            |||	|
           d	d	d	           n# 1 swxY w Y   |d
t/          |          z   t/          |j                  t/          |j                  |	|
t3          |          |f}||z  }t5          |||           |dz  }t7          |d          st7          |d          r$|j        }|j        }t9          |||||fz             d	S )z1Test that bn.xxx gives the same output as np.xxx.zA
func %s | input %s (%s) | shape %s | old %f | new %f | order %s
z
Input array:
%s
z
bn.slow.%sr         r   r   r   ignoreNaerr_msgz
 dtype mismatch %s %sdtype)r   evalnprandomRandomStatenaninf	enumerater   rangesizerandintmaxflat
issubclassr   typeinexactisfinitecopywarningscatch_warningssimplefilterstrshaper   r   hasattrr   )r   msgnamefunc0rsnewsiarridxoldnewactualdesiredtupr   dadds                    r   test_nonreducerC      s   
 PC!!C=D$%%E			yyy	)	)Bq"&26'"DF4LL)) '= '=388 &	= &	=Cx1}}jjSXq!1!122hsm  =  =!#)."*== !;s++ ! ;s++ ! ,.. + +)(333Dc***+ + + + + + + + + + + + + + + ((**,.. - -)(333E'3,,,- - - - - - - - - - - - - - - #a&&L	NN	NN$$	 )"67GDDDD4467++ =ww/H/H =B B RB8);<<<A =&	='= '=s$   "E<	<F F ."G	G #G c                     t           } | D ]}t          j        d|          }t          t          t
          j        |                                dd           t          t          t
          j        |                                dd           t          t          t
          j        j        |                                dd           t          t          t
          j        j        |                                dd           dS )zTest replace for unsafe castsr   r   g?r   N)	r
   r   zerosr   
ValueErrorbnreplacer-   slow)dtypesr   r   s      r   test_replace_unsafe_castrL   E   s    F E EHQe$$$j"*affhhQ???j"*affhh3???j"'/16688S!DDDj"'/16688QDDDDE Er   c                      g d} t          t          t          j        | dd           d} t          t          t          j        | dd           dS )z Test that non-array input raisesr   r   r   N)r   	TypeErrorrH   rI   r   s    r   test_non_arrayrP   P   sF    		A)RZAq111A)RZAq11111r   r   c                    t          j        d|                               ddd          }|                                }t	          j        |t           j        d           |                                }d}t          |||           |                                }t          j                            |t           j        d           d	}t          |||           d
S )z'Test replace, int array, old=nan, new=0   rE   r   r      r   z,replace failed on int input looking for nansr   z1slow.replace failed on int input looking for nansN)	r   arangereshaper-   rH   rI   r!   r   rJ   )r   r   r>   r?   r4   s        r   test_replace_nan_intrV   ]   s     		)5)))11!Q::AVVXXFJvrvq!!!ffhhG
8Cvw4444VVXXFGOOFBFA&&&
=Cvw444444r   c                  B   t          j        d          } d ddgdg}|D ]}t          j        t          d          5  t          j        | |d           d d d            n# 1 swxY w Y   t          j        t          d          5  t          j        | d|           d d d            n# 1 swxY w Y   t          j        t          d          5  t          j        | 	           d d d            n# 1 swxY w Y   t          j        t          d
          5  t          j        |            d d d            n# 1 swxY w Y   t          j        t          d          5  t          j        | d           d d d            n# 1 swxY w Y   t          j        t          d          5  t          j        | d           d d d            n# 1 swxY w Y   t          j        t          d          5  t          j        | ddd           d d d            d S # 1 swxY w Y   d S )N)
   rX    r   0z`old` must be a number)matchz`new` must be a numberzCannot find `a` keyword input)foozCannot find `old` keyword inputrO   zCannot find `new` keyword input)r   r<   zwrong number of arguments 4)r   onespytestraisesrN   rH   rI   )arraybad_valsbad_vals      r   test_replace_bad_argsrc   l   s   GHEb1#s#H * *]9,DEEE 	* 	*Jugq)))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* ]9,DEEE 	* 	*Jua)))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 
y(G	H	H	H  

u               
y(I	J	J	J  

U               
y(I	J	J	J # #

U""""# # # # # # # # # # # # # # # 
y(E	F	F	F  

5!               
y(E	F	F	F # #

5!Q"""# # # # # # # # # # # # # # # # # #s}   AA"	%A"	B''B+	.B+	C00C47C4D88D<?D<FFF'G		GG/HHHc                     t          j        d|           dt           j        f         }t          j        |dd          }|dk                                                                    sJ d S )N)r   r   rE   .r   r   )r   r]   newaxisrH   rI   all)r   r`   results      r   test_replace_newaxisrh      sb    GF%(((bj9EZq!$$FaK""$$$$$$$r   )__doc__r.   numpyr   numpy.testingr   r   r   
bottleneckrH   utilr   r   r	   r
   r^   markparametrizeget_functionsrC   rL   rP   rV   rc   rh    r   r   <module>rr      s\          I I I I I I I I I I     9 9 9 9 9 9 9 9 9 9 9 9  
B[))/C/C   /= /= /=lE E E2 2 2 *--5 5 .-5# # #4 &))% % *)% % %r   