a
    �ù»j  ã                   @   sF   d dl Zd dlmZ dd„ Zddœdd„Zdd	d
„Zddœdd„ZdS )é    N)Úget_namespacec              	   C   sh   t | tjƒs| S zd| jjv r$| W S W n ttfy<   Y n0 t | ¡}tj| jd|id�}| j|d�S )zŠAttach unique values of y to y and return the result.

    The result is a view of y, and the metadata (unique) is not attached to y.
    Úunique)Úmetadata)Údtype)	Ú
isinstanceÚnpZndarrayr   r   ÚAttributeErrorÚ	TypeErrorr   Úview)Úyr   Zunique_dtype© r   ú;E:\soccer\ml_env\Lib\site-packages\sklearn/utils/_unique.pyÚ_attach_unique	   s    

r   F)Úreturn_tuplec                 G   s.   t dd„ |D ƒƒ}t|ƒdkr*| s*|d S |S )aë  Attach unique values of ys to ys and return the results.

    The result is a view of y, and the metadata (unique) is not attached to y.

    IMPORTANT: The output of this function should NEVER be returned in functions.
    This is to avoid this pattern:

    .. code:: python

        y = np.array([1, 2, 3])
        y = attach_unique(y)
        y[1] = -1
        # now np.unique(y) will be different from cached_unique(y)

    Parameters
    ----------
    *ys : sequence of array-like
        Input data arrays.

    return_tuple : bool, default=False
        If True, always return a tuple even if there is only one array.

    Returns
    -------
    ys : tuple of array-like or array-like
        Input data with unique values attached.
    c                 s   s   | ]}t |ƒV  qd S )N)r   ©Ú.0r   r   r   r   Ú	<genexpr>8   ó    z attach_unique.<locals>.<genexpr>é   r   ©ÚtupleÚlen)r   ÚysÚresr   r   r   Úattach_unique   s    r   c                 C   sX   z*| j jdur(d| j jv r(| j jd W S W n ty<   Y n0 t| |d�\}}| | ¡S )zçReturn the unique values of y.

    Use the cached values from dtype.metadata if present.

    This function does NOT cache the values in y, i.e. it doesn't change y.

    Call `attach_unique` to attach the unique values to y.
    Nr   ©Úxp)r   r   r   r   Zunique_values)r   r   Ú_r   r   r   Ú_cached_unique>   s    	r   r   c                    s.   t ‡ fdd„|D ƒƒ}t|ƒdkr*|d S |S )a€  Return the unique values of ys.

    Use the cached values from dtype.metadata if present.

    This function does NOT cache the values in y, i.e. it doesn't change y.

    Call `attach_unique` to attach the unique values to y.

    Parameters
    ----------
    *ys : sequence of array-like
        Input data arrays.

    xp : module, default=None
        Precomputed array namespace module. When passed, typically from a caller
        that has already performed inspection of its own inputs, skips array
        namespace inspection.

    Returns
    -------
    res : tuple of array-like or array-like
        Unique values of ys.
    c                 3   s   | ]}t |ˆ d �V  qdS )r   N)r   r   r   r   r   r   i   r   z cached_unique.<locals>.<genexpr>r   r   r   )r   r   r   r   r   r   Úcached_uniqueQ   s    r   )N)Únumpyr   Zsklearn.utils._array_apir   r   r   r   r   r   r   r   r   Ú<module>   s
   "
