
    	gEA                    T   d Z ddlmZ ddlmZmZmZ ddlZddlm	Z	 ddl
mZmZ ddlmZmZ ddlmZmZmZmZmZmZmZmZmZ d	Z ed
e      Z ede      Z ed      Z ed      Z	 	 	 	 	 	 ddZddZ  G d deeef         Z!edd       Z"edd       Z"edd       Z"d Z"ddZ#y)a  
Cycler
======

Cycling through combinations of values, producing dictionaries.

You can add cyclers::

    from cycler import cycler
    cc = (cycler(color=list('rgb')) +
          cycler(linestyle=['-', '--', '-.']))
    for d in cc:
        print(d)

Results in::

    {'color': 'r', 'linestyle': '-'}
    {'color': 'g', 'linestyle': '--'}
    {'color': 'b', 'linestyle': '-.'}


You can multiply cyclers::

    from cycler import cycler
    cc = (cycler(color=list('rgb')) *
          cycler(linestyle=['-', '--', '-.']))
    for d in cc:
        print(d)

Results in::

    {'color': 'r', 'linestyle': '-'}
    {'color': 'r', 'linestyle': '--'}
    {'color': 'r', 'linestyle': '-.'}
    {'color': 'g', 'linestyle': '-'}
    {'color': 'g', 'linestyle': '--'}
    {'color': 'g', 'linestyle': '-.'}
    {'color': 'b', 'linestyle': '-'}
    {'color': 'b', 'linestyle': '--'}
    {'color': 'b', 'linestyle': '-.'}
    )annotations)HashableIterable	GeneratorN)reduce)productcycle)muladd)	TypeVarGenericCallableUnionDictListAnyoverloadcastz0.12.1K)boundLVUc                    | g k7  rt        t        |             ni }|t        t        |            ni }t        |j                               }t        |j                               }||z  rt	        d      ||z  S )a  
    Helper function to compose cycler keys.

    Parameters
    ----------
    left, right : iterable of dictionaries or None
        The cyclers to be composed.

    Returns
    -------
    keys : set
        The keys in the composition of the two cyclers.
    z"Can not compose overlapping cycles)nextitersetkeys
ValueError)leftrightl_peekr_peekl_keyr_keys         L/var/www/dash_apps/app1/venv/lib/python3.12/site-packages/cycler/__init__.py_process_keysr'   >   sl    " .2RZd4j)RF.3.?d5k*RF&E&Eu}=>>5=    c                   | j                   |j                   k7  rJt        dj                  | j                   |j                   z  | j                   |j                   z              t        t        t
        t        t        t        t        f      f   | j                               t        t        t
        t        t        t        t        f      f   |j                               t        t        fd| j                   D              S )aS  
    Concatenate `Cycler`\s, as if chained using `itertools.chain`.

    The keys must match exactly.

    Examples
    --------
    >>> num = cycler('a', range(3))
    >>> let = cycler('a', 'abc')
    >>> num.concat(let)
    cycler('a', [0, 1, 2, 'a', 'b', 'c'])

    Returns
    -------
    `Cycler`
        The concatenated cycler.
    zBKeys do not match:
	Intersection: {both!r}
	Disjoint: {just_one!r})bothjust_onec              3  H   K   | ]  }t        ||   |   z           y wN_cycler).0k_l_rs     r&   	<genexpr>zconcat.<locals>.<genexpr>t   s$     Ea2a52a5=1Es   ")r   r   formatr   r   r   r   r   r   r   by_keyr   r   )r    r!   r2   r3   s     @@r&   concatr7   X   s    $ yyEJJ''-vYY+dii%**6L (. (
 	
 
d1d5A;''($++-	8B	d1d5A;''(%,,.	9B#E499EFFr(   c                     e Zd ZdZd Z	 	 d	 	 	 	 	 ddZd Zedd       ZddZ	e
dd       Zdd	Zd d
Zd!dZed!d       Zed"d       Zd Zed!d       Zed"d       Zd Zd#dZd$dZd%dZd&dZdZd'dZd'dZd(dZeZd)dZeZy)*Cyclera  
    Composable cycles.

    This class has compositions methods:

    ``+``
      for 'inner' products (zip)

    ``+=``
      in-place ``+``

    ``*``
      for outer products (`itertools.product`) and integer multiplication

    ``*=``
      in-place ``*``

    and supports basic slicing via ``[]``.

    Parameters
    ----------
    left, right : Cycler or None
        The 'left' and 'right' cyclers.
    op : func or None
        Function which composes the 'left' and 'right' cyclers.
    c                    t        |       S r-   )r	   selfs    r&   __call__zCycler.__call__   s    T{r(   Nc                   t        |t              r1t        |j                  |j                  |j                        | _        n2|)|D cg c]  }t        j
                  |       c}| _        ng | _        t        |t              r1t        |j                  |j                  |j                        | _        nd| _        t        | j                  | j                        | _        || _        yc c}w )zf
        Semi-private init.

        Do not use this directly, use `cycler` function instead.
        N)
isinstancer9   _left_right_opcopyr'   _keys)r<   r    r!   opvs        r&   __init__zCycler.__init__   s     dF#:@

DKK;DJ  1551$))A,5DJDJeV$/5U\\5990DK DK*4::t{{C
 6s   C)c                    || j                   v S r-   )rD   )r<   r1   s     r&   __contains__zCycler.__contains__   s    DJJr(   c                ,    t        | j                        S )z!The keys this Cycler knows about.)r   rD   r;   s    r&   r   zCycler.keys   s     4::r(   c           	     J   ||k(  ry|| j                   v rt        d| d| d| d      || j                   vrt        d| d| d| d      | j                   j                  |       | j                   j	                  |       | j
                  5|| j
                  j                  v r| j
                  j                  ||       yt        | j                  t              r| j                  j                  ||       y| j                  D cg c]	  }|||   i c}| _	        yc c}w )a  
        Change a key in this cycler to a new name.
        Modification is performed in-place.

        Does nothing if the old key is the same as the new key.
        Raises a ValueError if the new key is already a key.
        Raises a KeyError if the old key isn't a key.
        NzCan't replace z with , z is already a keyz is not a key)rD   r   KeyErrorremover   rA   r   
change_keyr?   r@   r9   )r<   oldnewentrys       r&   rO   zCycler.change_key   s    #:$** VC53%7HI  djj  VC53%}E  	

#

s;;"sdkk.>.>'>KK""3, 

F+JJ!!#s+
 :>D3c
+DDJDs   	D c                Z     | d      }t        fd|D              |_        h|_        |S )a  
        Class method to create 'base' Cycler objects
        that do not have a 'right' or 'op' and for which
        the 'left' object is not another Cycler.

        Parameters
        ----------
        label : hashable
            The property key.

        itr : iterable
            Finite length iterable of the property values.

        Returns
        -------
        `Cycler`
            New 'base' cycler.
        Nc              3  &   K   | ]  }|i 
 y wr-    )r0   rF   labels     r&   r4   z$Cycler._from_iter.<locals>.<genexpr>   s     1%1s   )listr@   rD   )clsrV   itrrets    `  r&   
_from_iterzCycler._from_iter   s.    (  I1S11	G	
r(   c                    t        t              r7| j                         }t        t        fd|j                         D              S t        d      )Nc              3  B   K   | ]  \  }}t        ||           y wr-   r.   )r0   r1   rF   keys      r&   r4   z%Cycler.__getitem__.<locals>.<genexpr>   s      Mtq!1S6 2M   z+Can only use slices with Cycler.__getitem__)r?   slicer6   r   r   itemsr   )r<   r^   transs    ` r&   __getitem__zCycler.__getitem__   s=    c5!KKME#Mu{{}MNNJKKr(   c              #  <  K   | j                   | j                  D ]  }t        |        y | j                  t	        d      | j                  | j                  | j                         D ]-  \  }}i }|j                  |       |j                  |       | / y w)Nz=Operation cannot be None when both left and right are defined)rA   r@   dictrB   	TypeErrorupdate)r<   r    abouts        r&   __iter__zCycler.__iter__  s     ;;

 !4j ! xxS  T[[9 1

1

1		s   BBc           
     l   t        |       t        |      k7  r#t        dt        |        dt        |             t        t        t        t        t
        t        f   t        t        t        f   f   |       t        t        t        t
        t        f   t        t        t        f   f   |      t              S )z
        Pair-wise combine two equal length cyclers (zip).

        Parameters
        ----------
        other : Cycler
        z&Can only add equal length cycles, not z and )
lenr   r9   r   r   r   r   r   r   zipr<   others     r&   __add__zCycler.__add__  s     t9E
"8T5UU  adU1a4[0148adU1a4[0159
 	
r(   c                     y r-   rU   ro   s     r&   __mul__zCycler.__mul__$      r(   c                     y r-   rU   ro   s     r&   rs   zCycler.__mul__(  rt   r(   c           
        t        t              r{t        t        t        t        t        t
        f   t        t        t        f   f   |       t        t        t        t        t
        f   t        t        t        f   f         t              S t        t              r7| j                         }t        t        fd|j                         D              S t        S )z
        Outer product of two cyclers (`itertools.product`) or integer
        multiplication.

        Parameters
        ----------
        other : Cycler or int
        c              3  B   K   | ]  \  }}t        ||z          y wr-   r.   )r0   r1   rF   rp   s      r&   r4   z!Cycler.__mul__.<locals>.<genexpr>>  s      F1gaU+Fr_   )r?   r9   r   r   r   r   r   r   r   intr6   r   r   ra   NotImplemented)r<   rp   rb   s    ` r&   rs   zCycler.__mul__,  s     eV$VE!Q$Kq!t45t<VE!Q$Kq!t45u= 
 s#KKMEFF  "!r(   c                     y r-   rU   ro   s     r&   __rmul__zCycler.__rmul__C  rt   r(   c                     y r-   rU   ro   s     r&   r{   zCycler.__rmul__G  rt   r(   c                    | |z  S r-   rU   ro   s     r&   r{   zCycler.__rmul__K  s    e|r(   c                    t         t        t        t        i}| j                  t        | j                        S t        | j                        }t        | j                        } || j                     ||      S r-   )rn   minr   r
   rA   rm   r@   rB   )r<   op_dictl_lenr_lens       r&   __len__zCycler.__len__N  s\    >A3QT=U;;tzz?"DJJDKK  wtxx ..r(   c                   t        |t              st        d      t        j                  |       }t	        ||      | _        || _        t        | _        t        |j                  |j                  |j                        | _	        | S )z
        In-place pair-wise combine two equal length cyclers (zip).

        Parameters
        ----------
        other : Cycler
        z"Cannot += with a non-Cycler object)
r?   r9   rf   rC   r'   rD   r@   rn   rB   rA   r<   rp   old_selfs      r&   __iadd__zCycler.__iadd__X  sd     %(@AA99T?"8U3

U[[%,,		Br(   c                   t        |t              st        d      t        j                  |       }t	        ||      | _        || _        t        | _        t        |j                  |j                  |j                        | _	        | S )z
        In-place outer product of two cyclers (`itertools.product`).

        Parameters
        ----------
        other : Cycler
        z"Cannot *= with a non-Cycler object)
r?   r9   rf   rC   r'   rD   r@   r   rB   rA   r   s      r&   __imul__zCycler.__imul__j  sd     %(@AA99T?"8U3

U[[%,,		Br(   c                    t        |t              syt        |       t        |      k7  ry| j                  |j                  z  ryt	        d t        | |      D              S )NFc              3  ,   K   | ]  \  }}||k(    y wr-   rU   )r0   rh   ri   s      r&   r4   z Cycler.__eq__.<locals>.<genexpr>  s     7da167s   )r?   r9   rm   r   allrn   ro   s     r&   __eq__zCycler.__eq__|  sM    %(t9E
"99uzz!7c$&6777r(   c                2   t         dt        di}| j                  7| j                  j	                         t        fd| D              }dd|dS |j                  | j                  d      }d}|j                  | j                  || j                  	      S )
N+*c              3  (   K   | ]	  }|     y wr-   rU   r0   rF   labs     r&   r4   z"Cycler.__repr__.<locals>.<genexpr>  s     ,!qv,   zcycler(rL   )?z({left!r} {op} {right!r}))r    rE   r!   )
rn   r   rA   r   poprW   getrB   r5   r@   )r<   op_maprY   rE   msgr   s        @r&   __repr__zCycler.__repr__  s    sGS);;))--/C,t,,CSG2cWA..DHHc*B-C::4::"DKK:HHr(   c                    d}t        | j                  t              }|D ]  }|d|dz  } t        |       D ]  }|dz  }|D ]  }|d||   dz  } |dz  }! |d	z  }|S )
Nz<table>)r^   z<th>z</th>z<tr>z<td>z</td>z</tr>z</table>)sortedr   reprr   )r<   outputsorted_keysr^   dr1   s         r&   _repr_html_zCycler._repr_html_  s    TYYD1 	*CSG5))F	*d 	AfF  /D1../gF		
 	*r(   c                    | j                   }|D ci c]  }|t                }}| D ]   }|D ]  }||   j                  ||           " |S c c}w )a  
        Values by key.

        This returns the transposed values of the cycler.  Iterating
        over a `Cycler` yields dicts with a single value for each key,
        this method returns a `dict` of `list` which are the values
        for the given key.

        The returned value can be used to create an equivalent `Cycler`
        using only `+`.

        Returns
        -------
        transpose : dict
            dict of lists of the values for each key.
        )r   rW   append)r<   r   r1   rj   r   s        r&   r6   zCycler.by_key  sd    * yy48 9qDF 9 9 	$A $Aad#$	$ 
 !:s   Ac                l    | j                         }t        t        d |j                         D              S )z
        Simplify the cycler into a sum (but no products) of cyclers.

        Returns
        -------
        simple : Cycler
        c              3  :   K   | ]  \  }}t        ||        y wr-   r.   r0   r1   rF   s      r&   r4   z"Cycler.simplify.<locals>.<genexpr>  s     DdaGAqMD   )r6   r   r   ra   )r<   rb   s     r&   simplifyzCycler.simplify  s(     cDekkmDEEr(   )NN)r    *Cycler[K, V] | Iterable[dict[K, V]] | Noner!   zCycler[K, V] | NonerE   r   )returnset[K])rP   r   rQ   r   r   NonerV   r   rY   Iterable[V]r   Cycler[K, V])r^   r`   r   r   )r   z!Generator[dict[K, V], None, None])rp   zCycler[L, U]r   zCycler[K | L, V | U])rp   rx   r   r   )r   rx   )rp   r   r   r   )rp   zCycler[K, V] | intr   r   )rp   objectr   bool)r   str)r   zdict[K, list[V]])r   r   )__name__
__module____qualname____doc__r=   rG   rI   propertyr   rO   classmethodr[   rc   rk   rq   r   rs   r{   r   r   r   r   __hash__r   r   r6   
_transposer   r7   rU   r(   r&   r9   r9   w   s   6 &*	8 # 	@  "EH  0L
$    ".    /$$8 H	I< JF  Fr(   r9   c                     y r-   rU   )args    r&   cyclerr         r(   c                      y r-   rU   )kwargss    r&   r   r     r   r(   c                     y r-   rU   )rV   rY   s     r&   r   r     r   r(   c                 V   | r|rt        d      t        |       dk(  r,t        | d   t              st        d      t        | d         S t        |       dk(  rt	        |  S t        |       dkD  rt        d      |r%t        t        d |j                         D              S t        d      )	a  
    Create a new `Cycler` object from a single positional argument,
    a pair of positional arguments, or the combination of keyword arguments.

    cycler(arg)
    cycler(label1=itr1[, label2=iter2[, ...]])
    cycler(label, itr)

    Form 1 simply copies a given `Cycler` object.

    Form 2 composes a `Cycler` as an inner product of the
    pairs of keyword arguments. In other words, all of the
    iterables are cycled simultaneously, as if through zip().

    Form 3 creates a `Cycler` from a label and an iterable.
    This is useful for when the label cannot be a keyword argument
    (e.g., an integer or a name that has a space in it).

    Parameters
    ----------
    arg : Cycler
        Copy constructor for Cycler (does a shallow copy of iterables).
    label : name
        The property key. In the 2-arg form of the function,
        the label can be any hashable object. In the keyword argument
        form of the function, it must be a valid python identifier.
    itr : iterable
        Finite length iterable of the property values.
        Can be a single-property `Cycler` that would
        be like a key change, but as a shallow copy.

    Returns
    -------
    cycler : Cycler
        New `Cycler` for the given property

    zEcycler() can only accept positional OR keyword arguments -- not both.   r   zDIf only one positional argument given, it must be a Cycler instance.   zdOnly a single Cycler can be accepted as the lone positional argument. Use keyword arguments instead.c              3  :   K   | ]  \  }}t        ||        y wr-   r.   r   s      r&   r4   zcycler.<locals>.<genexpr>  s     EdaGAqMEr   z4Must have at least a positional OR keyword arguments)rf   rm   r?   r9   r/   r   r   ra   )argsr   s     r&   r   r     s    L S
 	
 4yA~$q'6*(  d1g	Ta~	TQB
 	

 cEfllnEFF
J
KKr(   c                    t        |t              rB|j                  }t        |      dk7  rd}t	        |      |j                         fd|D        }t        j                  | |      S )aD  
    Create a new `Cycler` object from a property name and iterable of values.

    Parameters
    ----------
    label : hashable
        The property key.
    itr : iterable
        Finite length iterable of the property values.

    Returns
    -------
    cycler : Cycler
        New `Cycler` for the given property
    r   z2Can not create Cycler from a multi-property Cyclerc              3  (   K   | ]	  }|     y wr-   rU   r   s     r&   r4   z_cycler.<locals>.<genexpr>;  s     #!qv#r   )r?   r9   r   rm   r   r   r[   )rV   rY   r   r   r   s       @r&   r/   r/   "  s\      #vxxt9>FCS/!hhj $s#UC((r(   )r    z#Cycler[K, V] | Iterable[dict[K, V]]r!   r   r   r   )r    r   r!   zCycler[K, U]r   zCycler[K, V | U])r   r   r   r   )r   r   r   zCycler[str, V]r   )$r   
__future__r   collections.abcr   r   r   rC   	functoolsr   	itertoolsr   r	   operatorr
   r   typingr   r   r   r   r   r   r   r   r   __version__r   r   r   r   r'   r7   r9   r   r/   rU   r(   r&   <module>r      s   (V # 9 9   $  U U UCx Cx CLCL
-5 4G>YWQT] Yx
 
 
 
 
 
 
=L@)r(   