
    J/Ph                     .    d gZ  G d d e          Zd ZdS )Originc                   Z    e Zd ZdZd Zed             Zd Zd Zd Z	d Z
dd	Zd
 Zd ZdS )r   aG  This represents the origin of some object in some string.

    For example, if we have an object ``x1_obj`` that was produced by parsing
    the ``x1`` in the formula ``"y ~ x1:x2"``, then we conventionally keep
    track of that relationship by doing::

      x1_obj.origin = Origin("y ~ x1:x2", 4, 6)

    Then later if we run into a problem, we can do::

      raise PatsyError("invalid factor", x1_obj)

    and we'll produce a nice error message like::

      PatsyError: invalid factor
          y ~ x1:x2
              ^^

    Origins are compared by value, and hashable.
    c                 0    || _         || _        || _        d S Ncodestartend)selfr   r   r	   s       L/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/patsy/origin.py__init__zOrigin.__init__$   s    	
    c                    g }|D ]8}|t          |t                    s|j        }|#|                    |           9|sdS t	          d |D                       }t          |          dk    sJ t          d |D                       }t          d |D                       } | |                                ||          S )a  Class method for combining a set of Origins into one large Origin
        that spans them.

        Example usage: if we wanted to represent the origin of the "x1:x2"
        term, we could do ``Origin.combine([x1_obj, x2_obj])``.

        Single argument is an iterable, and each element in the iterable
        should be either:

        * An Origin object
        * ``None``
        * An object that has a ``.origin`` attribute which fulfills the above
          criteria.

        Returns either an Origin object, or None.
        Nc                     g | ]	}|j         
S  )r   .0os     r   
<listcomp>z"Origin.combine.<locals>.<listcomp>D   s    ---QV---r      c                     g | ]	}|j         
S r   )r   r   s     r   r   z"Origin.combine.<locals>.<listcomp>F   s    ...QW...r   c                     g | ]	}|j         
S r   )r	   r   s     r   r   z"Origin.combine.<locals>.<listcomp>G   s    ***Q15***r   )	
isinstancer   originappendsetlenminmaxpop)clsorigin_objsoriginsobjcodesr   r	   s          r   combinezOrigin.combine)   s    $  	  	 Cz#v'>'>j{NN3 	4--W---..5zzQ..g...//**'***++s599;;s+++r   c                 4    | j         | j        | j                 S )zgExtracts and returns the span of the original code represented by
        this Origin. Example: ``x1``.r   r
   s    r   relevant_codezOrigin.relevant_codeJ   s     ydh.//r   c                     t          |t                    o/| j        |j        k    o| j        |j        k    o| j        |j        k    S r   )r   r   r   r   r	   r
   others     r   __eq__zOrigin.__eq__O   sI    uf%% &	UZ'&
ek)& EI%		
r   c                     | |k     S r   r   r*   s     r   __ne__zOrigin.__ne__W   s    5=  r   c                 P    t          t          | j        | j        | j        f          S r   )hashr   r   r   r	   r'   s    r   __hash__zOrigin.__hash__Z   s    VTY
DH=>>>r       c                 b    d|z  | j         dd|z  d| j        z  d| j        | j        z
  z  S )a3  Produces a user-readable two line string indicating the origin of
        some code. Example::

          y ~ x1:x2
              ^^

        If optional argument 'indent' is given, then both lines will be
        indented by this much. The returned string does not have a trailing
        newline.
         
^r   )r
   indents     r   caretizezOrigin.caretize]   sJ     &LLIII&LL$*48dj())
 	
r   c                     d| j         d | j                 d| j         | j        | j                 d| j         | j        d          d| j        d| j        dS )Nz<Origin z->z<-z (-z)>r   r'   s    r   __repr__zOrigin.__repr__p   se     Il
l###Idj48+,,,Idhjj!!!JJJHHH
 	
r   c                     t           r   )NotImplementedErrorr'   s    r   __getstate__zOrigin.__getstate__z   s    !!r   N)r2   )__name__
__module____qualname____doc__r   classmethodr%   r(   r,   r.   r1   r8   r;   r>   r   r   r   r   r      s         *  
 , , [,@0 0 0

 
 
! ! !? ? ?
 
 
 
&
 
 
" " " " "r   c                  &   t          ddd          } t          ddd          }|                                 dk    sJ |                                dk    sJ t                               | |g          }|j        dk    sJ |j        dk    sJ |j        dk    sJ |                    d          dk    sJ |t          ddd          k    sJ  G d	 d
t                    }t                                ||            |            d g          }|| k    sJ t                                ||           |g          }||k    sJ t                                |             |            g          J ddlm}  |t          ddd                     d S )N012345         z012345
  ^^z012345
    ^)r7   z  012345
    ^^^c                       e Zd ZddZdS )"test_Origin.<locals>.ObjWithOriginNc                     || _         d S r   )r   )r
   r   s     r   r   z+test_Origin.<locals>.ObjWithOrigin.__init__   s     DKKKr   r   )r?   r@   rA   r   r   r   r   ObjWithOriginrJ      s(        	! 	! 	! 	! 	! 	!r   rL   r2   )assert_no_pickling )	r   r8   r%   r   r   r	   object
patsy.utilrM   )o1o2o3rL   o4o5rM   s          r   test_OriginrV   ~   s   	!Q		B	!Q		B;;==N****;;==O++++	R	!	!B7h8q====6Q;;;;;;a;  $77777!Q''''''! ! ! ! ! ! ! ! 
r**MMOOTB	C	CB8888	r**B/	0	0B8888>>==??MMOO<==EEE------vb!Q''(((((r   N)__all__rO   r   rV   r   r   r   <module>rX      sZ    *m" m" m" m" m"V m" m" m"`) ) ) ) )r   