a
    Of                     @  s`   d dl mZ d dlmZ d dlZd dlmZ er<d dlm	Z	 dddd	Z
d
dd
dddZdS )    )annotations)TYPE_CHECKINGN)is_list_like)NumpyIndexTzlist[np.ndarray])returnc                   s   d}t | st|| D ]}t |st|qt| dkr>g S tjdd | D tjd}t|}t|dk rxtdt	|d d d< |d dkr|d | n
t
| fd	d
t| D S )a  
    Numpy version of itertools.product.
    Sometimes faster (for large inputs)...

    Parameters
    ----------
    X : list-like of list-likes

    Returns
    -------
    product : list of ndarrays

    Examples
    --------
    >>> cartesian_product([list('ABC'), [1, 2]])
    [array(['A', 'A', 'B', 'B', 'C', 'C'], dtype='<U1'), array([1, 2, 1, 2, 1, 2])]

    See Also
    --------
    itertools.product : Cartesian product of input iterables.  Equivalent to
        nested for-loops.
    z'Input must be a list-like of list-likesr   c                 s  s   | ]}t |V  qd S )N)len).0x r
   Q/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pandas/core/reshape/util.py	<genexpr>.       z$cartesian_product.<locals>.<genexpr>)Zdtypez+Product space too large to allocate arrays!   c                   s0   g | ](\}}t t|| t | qS r
   )tile_compatnprepeatprod)r   ir	   abr
   r   
<listcomp>?   s
   z%cartesian_product.<locals>.<listcomp>)r   	TypeErrorr   r   ZfromiterZintpZcumprodany
ValueErrorZrollZ
zeros_like	enumerate)Xmsgr	   ZlenXZcumprodXr
   r   r   cartesian_product   s(    


r   r   int)arrnumr   c                 C  s8   t | tjrt| |S ttt| |}| |S )zf
    Index compat for np.tile.

    Notes
    -----
    Does not support multi-dimensional `num`.
    )
isinstancer   ZndarrayZtileZaranger   Ztake)r!   r"   Ztakerr
   r
   r   r   H   s    r   )
__future__r   typingr   numpyr   Zpandas.core.dtypes.commonr   Zpandas._typingr   r   r   r
   r
   r
   r   <module>   s   ;