B
    SV                 @   s   d dgZ ddlmZmZmZmZmZmZ e dddddd	g7 Z dd
lm	Z	 e dg7 Z ddl
mZmZmZ e dddg7 Z ddlmZ e dg7 Z ddlmZmZmZ e dddg7 Z dd  Zdd Zdd Zdd ZdS )IQ    )ContrastMatrix	TreatmentPolySumHelmertDiffr   r   r   r   r   r	   )Cr
   )centerstandardizescaler   r   r   )bsr   )crccter   r   r   c             C   s   | S )a  The identity function. Simply returns its input unchanged.

    Since Patsy's formula parser ignores anything inside a function call
    syntax, this is useful to 'hide' arithmetic operations from it. For
    instance::

      y ~ x1 + x2

    has ``x1`` and ``x2`` as two separate predictors. But in::

      y ~ I(x1 + x2)

    we instead have a single predictor, defined to be the sum of ``x1`` and
    ``x2``. )xr   r   -lib/python3.7/site-packages/patsy/builtins.pyr      s    c               C   s$   t ddkstt d d ks td S )N   )r   AssertionErrorr   r   r   r   test_I-   s    r   c             C   sH   ddl m} |d}y
|j|  S  tk
rB   td| f Y nX dS )a<  A way to 'quote' variable names, especially ones that do not otherwise
    meet Python's variable name rules.

    If ``x`` is a variable, ``Q("x")`` returns the value of ``x``. (Note that
    ``Q`` takes the *string* ``"x"``, not the value of ``x`` itself.) This
    works even if instead of ``x``, we have a variable name that would not
    otherwise be legal in Python.

    For example, if you have a column of data named ``weight.in.kg``, then you
    can't write::

      y ~ weight.in.kg

    because Python will try to find a variable named ``weight``, that has an
    attribute named ``in``, that has an attribute named ``kg``. (And worse
    yet, ``in`` is a reserved word, which makes this example doubly broken.)
    Instead, write::

      y ~ Q("weight.in.kg")

    and all will be well. Note, though, that this requires embedding a Python
    string inside your formula, which may require some care with your quote
    marks. Some standard options include::

      my_fit_function("y ~ Q('weight.in.kg')", ...)
      my_fit_function('y ~ Q("weight.in.kg")', ...)
      my_fit_function("y ~ Q(\"weight.in.kg\")", ...)

    Note also that ``Q`` is an ordinary Python function, which means that you
    can use it in more complex expressions. For example, this is a legal
    formula::

      y ~ np.sqrt(Q("weight.in.kg"))
    r   )EvalEnvironmentr   zno data named %r foundN)Z
patsy.evalr   Zcapture	namespaceKeyError	NameError)namer   envr   r   r   r   1   s    #

c              C   s@   d} t ddkstt dt ks$tddlm} |tt d d S )Nr   ar   r   )assert_raisesZasdfsadfdsad)r   r   Z
nose.toolsr   r   )r   r   r   r   r   test_Q[   s
    r    N)__all__Zpatsy.contrastsr   r   r   r   r   r	   Zpatsy.categoricalr
   Zpatsy.stater   r   r   Zpatsy.splinesr   Zpatsy.mgcv_cubic_splinesr   r   r   r   r   r   r    r   r   r   r   <module>   s    

*