
    phW,                         S SK rS SKJr  S SKJrJrJrJr  S/r	SS/r
SS/rS	 r " S
 S\5      rS rS rS rS rS rg)    N)
PatsyError)
safe_isnansafe_scalar_isnanno_picklingassert_no_picklingNAActionNoneNaNraisedropc                 b    SR                  U  Vs/ s H  n[        U5      PM     sn5      $ s  snf )Nz, )joinrepr)optionsopts     eC:\Users\julio\OneDrive\Documentos\Trabajo\IdeasFrscas\Cabanna\env\Lib\site-packages\patsy/missing.py_desc_optionsr   2   s'    99737Cd3i73443s   ,c                   L    \ rS rSrSrSSS/4S jrS rS rS	 rS
 r	S r
\rSrg)r   6   ai  An :class:`NAAction` object defines a strategy for handling missing
data.

"NA" is short for "Not Available", and is used to refer to any value which
is somehow unmeasured or unavailable. In the long run, it is devoutly
hoped that numpy will gain first-class missing value support. Until then,
we work around this lack as best we're able.

There are two parts to this: First, we have to determine what counts as
missing data. For numerical data, the default is to treat NaN values
(e.g., ``numpy.nan``) as missing. For categorical data, the default is to
treat NaN values, and also the Python object None, as missing. (This is
consistent with how pandas does things, so if you're already using
None/NaN to mark missing data in your pandas DataFrames, you're good to
go.)

Second, we have to decide what to do with any missing data when we
encounter it. One option is to simply discard any rows which contain
missing data from our design matrices (``drop``). Another option is to
raise an error (``raise``). A third option would be to simply let the
missing values pass through into the returned design matrices. However,
this last option is not yet implemented, because of the lack of any
standard way to represent missing values in arbitrary numpy matrices;
we're hoping numpy will get this sorted out before we standardize on
anything ourselves.

You can control how patsy handles missing data through the ``NA_action=``
argument to functions like :func:`build_design_matrices` and
:func:`dmatrix`. If all you want to do is to choose between ``drop`` and
``raise`` behaviour, you can pass one of those strings as the
``NA_action=`` argument directly. If you want more fine-grained control
over how missing values are detected and handled, then you can create an
instance of this class, or your own object that implements the same
interface, and pass that as the ``NA_action=`` argument instead.
r   r	   r
   c           	      V   Xl         U R                   [        ;  a!  [        SU< S[        [        5      < S35      e[	        U[
        5      (       a  [        S5      e[        U5      U l        U R                   H.  nU[        ;  d  M  [        SU< S[        [        5      < S35      e   g)ao  The :class:`NAAction` constructor takes the following arguments:

:arg on_NA: How to handle missing values. The default is ``"drop"``,
  which removes all rows from all matrices which contain any missing
  values. Also available is ``"raise"``, which raises an exception
  when any missing values are encountered.
:arg NA_types: Which rules are used to identify missing values, as a
  list of strings. Allowed values are:

  * ``"None"``: treat the ``None`` object as missing in categorical
    data.
  * ``"NaN"``: treat floating point NaN values as missing in
    categorical and numerical data.

.. versionadded:: 0.2.0
zinvalid on_NA action z (should be one of )z$NA_types should be a list of stringszinvalid NA_type N)	on_NA_valid_NA_responses
ValueErrorr   
isinstancestrtupleNA_types_valid_NA_types)selfr   r   NA_types       r   __init__NAAction.__init__[   s    " 
::00+0-@S2TV  h$$CDDh}}Go- /6o8VX  %    c                 n    SU R                   ;   a  [        U5      (       a  gSU R                   ;   a  Uc  gg)z_Return True if `obj` is a categorical NA value.

Note that here `obj` is a single scalar value.r
   Tr	   F)r   r   )r    objs     r   is_categorical_NANAAction.is_categorical_NA|   s4     DMM!&7&<&<T]]"s{r$   c                     [         R                  " UR                  [        S9nSU R                  ;   a  U[         R
                  " U5      -  nUR                  S:  a  [         R                  " USS9nU$ )zReturns a 1-d mask array indicating which rows in an array of
numerical values contain at least one NA value.

Note that here `arr` is a numpy array or pandas DataFrame.dtyper
      )axis)npzerosshapeboolr   isnanndimany)r    arrmasks      r   is_numerical_NANAAction.is_numerical_NA   sV    
 xx		.DMM!BHHSM!D99q=66$Q'Dr$   c                 
   [        U5      [        U5      s=:X  a  [        U5      :X  d   e   e[        U5      S:X  a  U$ U R                  S:X  a  U R                  XU5      $ U R                  S:X  a  U R                  XU5      $  e)a8  Takes a set of factor values that may have NAs, and handles them
appropriately.

:arg values: A list of `ndarray` objects representing the data.
  These may be 1- or 2-dimensional, and may be of varying dtype. All
  will have the same number of rows (or entries, for 1-d arrays).
:arg is_NAs: A list with the same number of entries as `values`,
  containing boolean `ndarray` objects that indicate which rows
  contain NAs in the corresponding entry in `values`.
:arg origins: A list with the same number of entries as
  `values`, containing information on the origin of each
  value. If we encounter a problem with some particular value, we use
  the corresponding entry in `origins` as the origin argument when
  raising a :class:`PatsyError`.
:returns: A list of new values (which may have a differing number of
  rows.)
r   r   r   )lenr   _handle_NA_raise_handle_NA_drop)r    valuesis_NAsoriginss       r   	handle_NANAAction.handle_NA   s}    $ 6{c&k9S\99999v;!M:: ((AAZZ6!''@@5r$   c                 |    [        X#5       H,  u  pE[        R                  " U5      (       d  M"  [        SU5      e   U$ )Nzfactor contains missing values)zipr.   r4   r   )r    r=   r>   r?   is_NAorigins         r   r;   NAAction._handle_NA_raise   s5     1MEvve}} !A6JJ 2 r$   c                     [         R                  " US   R                  S   [        S9nU H  nXE-  nM	     U) nU Vs/ s H	  owUS4   PM     sn$ s  snf )Nr   r*   .)r.   r/   r0   r1   )r    r=   r>   r?   
total_maskrD   	good_maskvs           r   r<   NAAction._handle_NA_drop   sW    XXfQiooa0=
EJ K	+126a)S.!6222s   A)r   r   N)__name__
__module____qualname____firstlineno____doc__r"   r'   r7   r@   r;   r<   r   __getstate____static_attributes__ r$   r   r   r   6   s9    "H $vuo B
83 Lr$   c                      SS K n U R                  [        [        SS9  U R                  [        [        SS9  U R                  [        [        SS9  [	        [        5       5        g )Nr   pordr   )r
   asdfr   r
   )pytestraisesr   r   r   )rY   s    r   test_NAAction_basicr[      sE    
MM*hfM5
MM*hMA
MM*hM7xz"r$   c                     / S/S/SS/4 H  n [        U S9nS H  n[        R                  " SU-   [        S9nSS/nUR                  S	:  a*  UR
                  S	   S	:  a  [        R                  X4SS	/4'   O[        R                  X4'   [        R                  " S
[        S9nSU ;   a  SXT'   UR                  U5      n[        R                  " Xe5      (       a  M   e   M     g )Nr
   r	   rX   )rS   )r,   )   )   r*   r   r]   r,   r^   T)r   r.   onesfloatr3   r0   nanr/   r1   r7   array_equal)r   actionextra_shaper5   nan_rowsexp_NA_maskgot_NA_masks          r    test_NAAction_NA_types_numericalrh      s    %6(UFO<8,+K''$,E:C1vHxx!|		!q 0(*q!f$% "((1D1K (,% 005K>>+;;;; , =r$   c                     / S/S/SS/4 H~  n [        U S9nUR                  S5      (       a   eUR                  S5      (       a   eUR                  S 5      SU ;   :X  d   eUR                  [        R                  5      SU ;   :X  a  M~   e   g )Nr
   r	   rX   ar,   )r   r'   r.   ra   )r   rc   s     r   "test_NAAction_NA_types_categoricalrk      s    %6(UFO<8,++C0000++A....''-&H2DEEE''/EX4EFFF =r$   c            
         [        S5      n [        R                  " / SQ5      [        R                  " / SQ5      [        R                  " S[        R                  /SS/SS/S	S
/S[        R                  //5      /n[        R                  " / SQ5      [        R                  " S[
        S9[        R                  " / SQ5      /nU R                  XS /S-  5      n[        U5      S:X  d   e[        R                  " US   SS/5      (       d   e[        R                  " US   SS/5      (       d   e[        R                  " US   SS/S	S
//5      (       d   eg )Nr   )r]   rm   r^      )      $@      4@g      >@      D@g      I@      ?g      @g      @ro   g      @g      @g      @g       @)TFTFFrn   r*   )TFFFT   r   r]   r^   r,   rp   rq   )	r   r.   asarrayra   r/   r1   r@   r:   rb   )rc   	in_valuesr>   
out_valuess       r   test_NAAction_droprw      s#   fF


$%


12


S"&&MC:c{S#JbffVWI 	

45
$


45F
 !!)dVaZ@Jz?a>>*Q-!Q0000>>*Q-$6666>>*Q-3*sCj)ABBBBr$   c                     [        SS9n [        R                  " SS/5      [        R                  " SS/5      /n[        R                  " SS/5      /S-  nU R                  XS S /5      n[        R                  " US   US   5      (       d   e[        R                  " US   US   5      (       d   eSS	KJn  U" S
SS5      nU" S
SS5      n[        R                  " S5      n[        R                  " SS/5      [        R                  " S[        R                  /5      /n[        R                  " SS/5      [        R                  " SS/5      /n U R                  XXV/5         e! [         a  nUR                  UL d   e S nAg S nAff = f)Nr   rV   g?g333333?r,   r]   Fr   )OriginrW   rs   rr   T)r   r.   rt   r@   rb   patsy.originry   arangera   r   rE   )	rc   in_arrsr>   got_arrsry   o1o2in_idxes	            r   test_NAAction_raiser      sV   G$F zz3*%rzz1a&'9:Gjj%()A-F$>H>>(1+wqz2222>>(1+wqz2222#	1	B	1	B YYq\Fzz3*%rzz3-'@AGjj%("**eT]*CDF2(3u xx2~~s   E& &
F0FF)numpyr.   patsyr   
patsy.utilr   r   r   r   __all__r   r   r   objectr   r[   rh   rk   rw   r   rS   r$   r   <module>r      s`   N   U U ,5/' 5Fv FR#<"GC&r$   