
    M/Ph$              
       ,   d Z ddlZddlmZmZmZmZmZmZ ddl	Z
ddlmZ 	 ddee
j        ge
j        f         deeee                           dee
j        gee
j                 f         fdZ	 ddee
j        ge
j        f         deeee                           dee
j        gef         fd	Z	 ddee
j        ge
j        f         deeee                           dee
j        gef         fd
Zdee
j        ge
j        f         dee
j        gef         fdZdee         dee
j        egef         fdZdedee
j        egef         fdZdeee         ef         dee
j        egef         fdZdeee         ef         dee
j        ge
j        f         fdZdS )z/
A selection of testing utilities for visions.
    N)CallableDictListOptionalTypeUnion)array_handle_nullsfnextra_errorsreturnc                      t           t          t          g|r                    |           t	          j                   dt          j        dt          t          j                 f fd            }|S )a3  A coercion test evaluator
    Evaluates a coercion function and optionally returns the coerced array.
    Args:
        fn: A function coercing a array to another array.
        extra_errors: Additional exceptions to catch
    Returns:
        The coerced array if the coercion succeeds otherwise None.
    arrayr   c                 N    	  |           S # t                    $ r Y d S w xY wN)tuple)r   
error_listr
   s    a/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/visions/backends/numpy/test_utils.pyfz$option_coercion_evaluator.<locals>.f   s@    	2e99Z   	 	 	44	s   
 $$)	
ValueError	TypeErrorAttributeErrorextend	functoolswrapsnpndarrayr   )r
   r   r   r   s   `  @r   option_coercion_evaluatorr      s     i8J (,'''_R  4        H    c                     t          | |          t          j        |           dt          j        dt
          ffd            }|S )a  A coercion test generator
    Creates a coercion test based on a provided coercion function.
    Args:
        fn: A function coercing a array to another type.
        extra_errors: Additional exceptions to catch
    Returns:
        Whether the coercion failed or was successful.
    r   r   c                 &     |           }|dndS )NTF r   resulttesters     r   r   zcoercion_test.<locals>.f7   s    )ttu4r   r   r   r   r   r   boolr
   r   r   r$   s      @r   coercion_testr(   (   s^     'r<88F_R5 5 5 5 5 5 5 5 Hr   c                     t          | |          t          j                  dt          j        dt
          ffd            }|S )a  A coercion equality test generator
    Creates a coercion test based on a provided coercion function which also enforces
    equality constraints on the output. This is useful when you want to change the
    data type of a array without necessarily changing the data, for example,
    when converting an integer to a float.
    Args:
        fn: A function coercing a array to another type.
        extra_errors: Additional exceptions to catch
    Returns:
        Whether the coercion failed or was successful.
    r   r   c                 J     |           }|dn|                                  S NF)allr"   s     r   r   zcoercion_true_test.<locals>.fP   s&    uuEIIKK7r   r%   r'   s      @r   coercion_true_testr-   ?   s^     'r<88F_V8 8 8 8 8 8 8 8 Hr   c                     t          |           t          j                  dt          j        dt
          ffd            }|S )a  A coercion equality test generator
    Creates a coercion test based on a provided coercion function which also enforces
    equality constraints on the output. This is useful when you want to change the
    data type of a array without necessarily changing the data, for example,
    when converting an integer to a float.
    Args:
        fn: A function coercing a array to another type.
    Returns:
        Whether the coercion failed or was successful.
    r   r   c                 L     |           }|dnt          j        | |          S r+   )r   array_equalr"   s     r   r   z!coercion_equality_test.<locals>.fg   s*    uuBN5&,I,IIr   r%   )r
   r   r$   s     @r   coercion_equality_testr1   X   sd     'r**F_VJ J J J J J J J Hr   mappingc                 f     t           i fdt          j        dt          dt          f fd            }|S )Nr   stater   c                 <     t           fdD                       S )Nc              3      K   | ]J}t          j        t          |                                                                                    V  Kd S r   r   isinlistkeysr,   ).0
single_mapr   s     r   	<genexpr>z6coercion_single_map_test.<locals>.f.<locals>.<genexpr>r   s^       
 
>HBGE4
 1 122337799
 
 
 
 
 
r   )anyr   r4   r2   s   ` r   r   z#coercion_single_map_test.<locals>.fp   s<     
 
 
 
LS
 
 
 
 
 	
r   r	   r   r   dictr&   r2   r   s   ` r   coercion_single_map_testrC   o   sR    +- 
 
 
D 
$ 
 
 
 
 
 

 Hr   c                 f     t           i fdt          j        dt          dt          f fd            }|S )Nr   r4   r   c                     t          j        | t                                                                                              S r   r7   r?   s     r   r   z"coercion_multi_map_test.<locals>.fz   s1    wud7<<>>223377999r   r@   rB   s   ` r   coercion_multi_map_testrF   y   sR    +- : : :D :$ : : : : : : Hr   c                     t          | t                    rt          |           }n4t          | t                    rt	          |           }nt          d          |S )a  Create a testing function for a single mapping or a list of mappings.
    Args:
        mapping: A dict with a mapping or a list of dicts
    Returns:
        Callable that checks if a array consists of the mappable values
    Examples:
        >>> coercion_map_test({"Yes": True, "No": False})
        >>> coercion_map_test(
        >>>     [
        >>>         {"Yes": True, "No": False},
        >>>         {"Y": True, "N": False},
        >>>     ]
        >>> )
    'Mapping should be dict or list of dicts)
isinstancer9   rC   rA   rF   r   rB   s     r   coercion_map_testrJ      s\    $ '4   D$W--	GT	"	" D#G,,BCCCHr   c                      t           t                    rd  D              n$t           t                    st          d          t	          j         fd          }|S )zMaps a array given a mapping
    Args:
        mapping: a dict to map, or a list of dicts.
    Returns:
        A callable that maps the array.
    c                 H    i | ]}|                                 D ]\  }}||	 S r!   )items)r;   dkvs       r   
<dictcomp>z coercion_map.<locals>.<dictcomp>   s3    ???AQWWYY??TQ1a????r   rH   c                 D                         | t          j                  S r   )getr   nan)valuer2   s    r   <lambda>zcoercion_map.<locals>.<lambda>   s    7;;ubf#=#= r   )rI   r9   rA   r   r   	vectorizerB   s   ` r   coercion_maprX      sm     '4   D?????&& DBCCC
====>>AHr   r   )__doc__r   typingr   r   r   r   r   r   numpyr   "visions.backends.numpy.array_utilsr	   r   	Exceptionr   r&   r(   r-   r1   rC   rF   rJ   rX   r!   r   r   <module>r^      s        > > > > > > > > > > > > > > > >     A A A A A A
 59 "*rz)*4Y01 rzlHRZ001   : 59 "*rz)*4Y01 rzlD !   2 59 "*rz)*4Y01 rzlD !   2"*rz)*rzlD !   .d4j Xrz4>PRV>V5W    T h
D7I47O.P    4:t#$rz4 $&'   64:t#$rzlBJ&'     r   