
    ,hC5                         / S Qr SSKrSSKJr  SSKJrJr  SSKJ	r	  SSK
Jr  SSKJrJr  SSKJrJrJr  \(       a  SSKrS	 rSS jrSS jrS r0 SS
S4S jr0 SS
S4S jrg))dmatrix	dmatricesincr_dbuilderincr_dbuilders    N)
PatsyError)DesignMatrix
DesignInfo)EvalEnvironment)	ModelDesc)design_matrix_buildersbuild_design_matrices)have_pandasasarray_or_pandasatleast_2d_column_defaultc                    [        U [        5      (       a  [        / /XU5      S   U 4$ [        U [        5      (       aA  [	        U 5      S:X  a2  [        U S   [        5      (       a  [        U S   [        5      (       a  U $ [        U S5      (       a6  U R                  U5      n [        U [        5      (       d  [        SU < S35      e[        U [        5      (       a  [        R                  " U 5      n [        U [        5      (       a;  [        U[        5      (       d   e[        U R                  U R                  /UUU5      $ g )Nr         __patsy_get_model_desc__zbad value from z.__patsy_get_model_desc__)
isinstancer	   r   tuplelenhasattrr   r   r   strfrom_formular
   lhs_termlistrhs_termlist)formula_likedata_iter_makereval_env	NA_actions       bC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\patsy/highlevel.py_try_incr_buildersr"      s   ,
++"B4INqQ
 	

 	<''"|A
33|A
33|788#<<XF,	22@LN  ,$$ --l;,	**(O4444%&&(A(AB	
 	
     dropc                     [         R                  " USS9n[        XX#5      nUc  [        S5      e[	        US   R
                  5      S:  a  [        S5      eUS   $ )a  Construct a design matrix builder incrementally from a large data set.

:arg formula_like: Similar to :func:`dmatrix`, except that explicit
  matrices are not allowed. Must be a formula string, a
  :class:`ModelDesc`, a :class:`DesignInfo`, or an object with a
  ``__patsy_get_model_desc__`` method.
:arg data_iter_maker: A zero-argument callable which returns an iterator
  over dict-like data objects. This must be a callable rather than a
  simple iterator because sufficiently complex formulas may require
  multiple passes over the data (e.g. if there are nested stateful
  transforms).
:arg eval_env: Either a :class:`EvalEnvironment` which will be used to
  look up any variables referenced in `formula_like` that cannot be
  found in `data`, or else a depth represented as an
  integer which will be passed to :meth:`EvalEnvironment.capture`.
  ``eval_env=0`` means to use the context of the function calling
  :func:`incr_dbuilder` for lookups. If calling this function from a
  library, you probably want ``eval_env=1``, which means that variables
  should be resolved in *your* caller's namespace.
:arg NA_action: An :class:`NAAction` object or string, used to determine
  what values count as 'missing' for purposes of determining the levels of
  categorical factors.
:returns: A :class:`DesignInfo`

Tip: for `data_iter_maker`, write a generator like::

  def iter_maker():
      for data_chunk in my_data_store:
          yield data_chunk

and pass `iter_maker` (*not* `iter_maker()`).

.. versionadded:: 0.2.0
   The ``NA_action`` argument.
r   	referencebad formula-like objectr   Cencountered outcome variables for a model that does not expect themr
   capturer"   r   r   column_namesr   r   r   r    design_infoss        r!   r   r   B   sm    H &&x1=H%xL 233
<?''(1,T
 	
 ?r#   c                     [         R                  " USS9n[        XX#5      nUc  [        S5      e[	        US   R
                  5      S:X  a  [        S5      eU$ )zConstruct two design matrix builders incrementally from a large data
set.

:func:`incr_dbuilders` is to :func:`incr_dbuilder` as :func:`dmatrices` is
to :func:`dmatrix`. See :func:`incr_dbuilder` for details.
r   r&   r(   r   +model is missing required outcome variablesr*   r-   s        r!   r   r   s   sb     &&x1=H%xL 233
<?''(A-FGGr#   c                   ^^ TS:X  a  [         (       d  [        S5      eTS;  a  [        ST< S35      eU4S jn[        XX#5      nUb  [        UTUTS9$ [	        U [
        5      (       a-  [        U 5      S:w  a  [        S	[        U 5      < S
35      eU u  pxOS [        U SS9pU4S jn	U	" US5      u  pUc(  [        R                  " UR                  S   S4[        S9nU	" US5      u  p{[	        [        USS 5      [        5      (       d   e[	        [        USS 5      [        5      (       d   eUR                  S   UR                  S   :w  a.  [        SUR                  S   < SUR                  S   < S35      eU
b$  Ub!  U
R                  U5      (       d  [        S5      eTS:X  a.  U
b  Uc  UR                  Ul        U
c  Ub  UR                  Ul        Xx4$ )N	dataframez;pandas.DataFrame was requested, but pandas is not installed)matrixr2   zunrecognized output type z#, should be 'matrix' or 'dataframe'c                     > [        T /5      $ )N)iter)datas   r!   r   -_do_highlevel_design.<locals>.data_iter_maker   s    TF|r#   )r    return_typer   z$don't know what to do with a length z matrices tupleT)subokc                 \  > [         R                  " X5      n[        (       a<  [        U [        R
                  [        R                  45      (       a  U R                  nOS nTS:X  a:  [        U SS9n [        R                  " U 5      n UR                  U l
        X l        X4$ [        X5      U4$ )Nr2   T)preserve_pandas)r	   
from_arrayr   r   pandasSeries	DataFrameindexr   r,   columnsdesign_infor   )mdefault_column_prefixdi
orig_indexr8   s       r!   _regularize_matrix0_do_highlevel_design.<locals>._regularize_matrix   s    &&q@B{z!fmmV=M=M-NOOWW
!
k)-aF$$Q'OO	 "&$Q+Z88r#   xr   )dtypeyrB   z#shape mismatch: outcome matrix has z rows, predictor matrix has z rowsz?index mismatch: outcome and predictor have incompatible indexes)r   r   r"   r   r   r   r   r   npzerosshapefloatgetattrr	   equalsr@   )r   r6   r   r    r8   r   r.   lhsrhsrG   rhs_orig_indexlhs_orig_indexs    `  `       r!   _do_highlevel_designrV      s   k!++L
 	
 11)47
 	

 &xL $$)
 	

 lE**< A% (+L(9<  &JS#  1,d K#	9 1c:;((CIIaL!,E:C0c:'#}d;ZHHHH'#}d;ZHHHH99Q<399Q<'25))A,		!N  %.*D!((88 X  +%)n.DII	%.*DII	zr#   r3   c                     [         R                  " USS9n[        XX#U5      u  pVUR                  S   S:w  a  [	        S5      eU$ )a  Construct a single design matrix given a formula_like and data.

:arg formula_like: An object that can be used to construct a design
  matrix. See below.
:arg data: A dict-like object that can be used to look up variables
  referenced in `formula_like`.
:arg eval_env: Either a :class:`EvalEnvironment` which will be used to
  look up any variables referenced in `formula_like` that cannot be
  found in `data`, or else a depth represented as an
  integer which will be passed to :meth:`EvalEnvironment.capture`.
  ``eval_env=0`` means to use the context of the function calling
  :func:`dmatrix` for lookups. If calling this function from a library,
  you probably want ``eval_env=1``, which means that variables should be
  resolved in *your* caller's namespace.
:arg NA_action: What to do with rows that contain missing values. You can
  ``"drop"`` them, ``"raise"`` an error, or for customization, pass an
  :class:`NAAction` object. See :class:`NAAction` for details on what
  values count as 'missing' (and how to alter this).
:arg return_type: Either ``"matrix"`` or ``"dataframe"``. See below.

The `formula_like` can take a variety of forms. You can use any of the
following:

* (The most common option) A formula string like ``"x1 + x2"`` (for
  :func:`dmatrix`) or ``"y ~ x1 + x2"`` (for :func:`dmatrices`). For
  details see :ref:`formulas`.
* A :class:`ModelDesc`, which is a Python object representation of a
  formula. See :ref:`formulas` and :ref:`expert-model-specification` for
  details.
* A :class:`DesignInfo`.
* An object that has a method called :meth:`__patsy_get_model_desc__`.
  For details see :ref:`expert-model-specification`.
* A numpy array_like (for :func:`dmatrix`) or a tuple
  (array_like, array_like) (for :func:`dmatrices`). These will have
  metadata added, representation normalized, and then be returned
  directly. In this case `data` and `eval_env` are
  ignored. There is special handling for two cases:

  * :class:`DesignMatrix` objects will have their :class:`DesignInfo`
    preserved. This allows you to set up custom column names and term
    information even if you aren't using the rest of the patsy
    machinery.
  * :class:`pandas.DataFrame` or :class:`pandas.Series` objects will have
    their (row) indexes checked. If two are passed in, their indexes must
    be aligned. If ``return_type="dataframe"``, then their indexes will be
    preserved on the output.

Regardless of the input, the return type is always either:

* A :class:`DesignMatrix`, if ``return_type="matrix"`` (the default)
* A :class:`pandas.DataFrame`, if ``return_type="dataframe"``.

The actual contents of the design matrix is identical in both cases, and
in both cases a :class:`DesignInfo` object will be available in a
``.design_info`` attribute on the return value. However, for
``return_type="dataframe"``, any pandas indexes on the input (either in
`data` or directly passed through `formula_like`) will be preserved, which
may be useful for e.g. time-series models.

.. versionadded:: 0.2.0
   The ``NA_action`` argument.
r   r&   r   r)   r
   r+   rV   rN   r   r   r6   r   r    r8   rR   rS   s          r!   r   r      sS    ~ &&x1=H%HJS yy|qT
 	
 Jr#   c                     [         R                  " USS9n[        XX#U5      u  pVUR                  S   S:X  a  [	        S5      eXV4$ )a?  Construct two design matrices given a formula_like and data.

This function is identical to :func:`dmatrix`, except that it requires
(and returns) two matrices instead of one. By convention, the first matrix
is the "outcome" or "y" data, and the second is the "predictor" or "x"
data.

See :func:`dmatrix` for details.
r   r&   r   r0   rX   rY   s          r!   r   r   2  sO     &&x1=H%HJS yy|qFGG:r#   )r   r$   )__all__numpyrL   patsyr   patsy.design_infor   r	   
patsy.evalr
   
patsy.descr   patsy.buildr   r   
patsy.utilr   r   r   r=   r"   r   r   rV   r   r    r#   r!   <module>rd      sh    F   6 &   E P P F.bFOd  "AX GV AXr#   