
    phLB                         S /r SSKrSSKJrJrJr  SSKJr  \(       a  SSK	r	S r
S rS r " S S	\5      r\" \5      rS
 rS\l        S rS rg)bs    N)have_pandasno_picklingassert_no_pickling)stateful_transformc                 ^    SSK Jn  [        R                  " [        R
                  " U[        S95      nUR                  S:X  d   eUR                  5         [        U5      n[        R                  " U 5      n U R                  S:X  a  U R                  S   S:X  a	  U S S 2S4   n U R                  S:X  d   e[        R                  " U 5      [        R                  " U5      :  d.  [        R                  " U 5      [        R                  " U5      :  a  [        S5      e[        U5      US-   -
  n[        R                  " U R                  S   U4[        S9n[!        U5       H/  n[        R"                  " U45      nSXv'   U" XXr45      US S 2U4'   M1     U$ ! [         a    [        S5      ef = f)Nr   )splevz#spline functionality requires scipy)dtype      zksome data points fall outside the outermost knots, and I'm not sure how to handle them. (Patches accepted!))scipy.interpolater	   ImportErrornp
atleast_1dasarrayfloatndimsortintshapeminmaxNotImplementedErrorlenemptyrangezeros)xknotsdegreer	   n_basesbasisicoefss           eC:\Users\julio\OneDrive\Documentos\Trabajo\IdeasFrscas\Cabanna\env\Lib\site-packages\patsy/splines.py_eval_bspline_basisr&      sc   A+ MM"**U%89E::??	JJL[F
aAvv{qwwqzQadG66Q;;
 
vvay266%= BFF1Iu$=!2
 	
" %jFQJ'GHHaggaj'*%8E7^'$Au56ad  LS  A?@@As   F F,c           
         [         R                  " U5      n[         R                  " UR                  SS9 Vs/ s H  n[         R                  " U SU-  5      PM     sn5      nUR	                  UR
                  SS9$ s  snf )NC)orderd   )r   r   ravel
percentilereshaper   )r   probsprob	quantiless       r%   _R_compat_quantiler1   B   sn    JJuE

27++C+2HI2H$q#*	%2HII U[[44 	Js   $A=c                      S n U " SS/SS5        U " SS/SS5        U " SS/SS/SS	/5        U " [        [        S5      5      SS/S
S/5        g )Nc                 R    [         R                  " [        X5      U5      (       d   eg N)r   allcloser1   )r   r/   expecteds      r%   t"test__R_compat_quantile.<locals>.tL   s    {{-a6AAAA    
      g      ?   g333333?   gffffff?   g@g333333@)listr   )r7   s    r%   test__R_compat_quantiler@   K   s^    B r2hRr2hRr2hc
RH%d59oSzC:.r9   c                   T    \ rS rSrSrS r      S	S jrS r      S	S jr\	r
Srg)
BSU   a
  bs(x, df=None, knots=None, degree=3, include_intercept=False, lower_bound=None, upper_bound=None)

Generates a B-spline basis for ``x``, allowing non-linear fits. The usual
usage is something like::

  y ~ 1 + bs(x, 4)

to fit ``y`` as a smooth function of ``x``, with 4 degrees of freedom
given to the smooth.

:arg df: The number of degrees of freedom to use for this spline. The
  return value will have this many columns. You must specify at least one
  of ``df`` and ``knots``.
:arg knots: The interior knots to use for the spline. If unspecified, then
  equally spaced quantiles of the input data are used. You must specify at
  least one of ``df`` and ``knots``.
:arg degree: The degree of the spline to use.
:arg include_intercept: If ``True``, then the resulting
  spline basis will span the intercept term (i.e., the constant
  function). If ``False`` (the default) then this will not be the case,
  which is useful for avoiding overspecification in models that include
  multiple spline terms and/or an intercept term.
:arg lower_bound: The lower exterior knot location.
:arg upper_bound: The upper exterior knot location.

A spline with ``degree=0`` is piecewise constant with breakpoints at each
knot, and the default knot positions are quantiles of the input. So if you
find yourself in the situation of wanting to quantize a continuous
variable into ``num_bins`` equal-sized bins with a constant effect across
each bin, you can use ``bs(x, num_bins - 1, degree=0)``. (The ``- 1`` is
because one degree of freedom will be taken by the intercept;
alternatively, you could leave the intercept term out of your model and
use ``bs(x, num_bins, degree=0, include_intercept=True)``.

A spline with ``degree=1`` is piecewise linear with breakpoints at each
knot.

The default is ``degree=3``, which gives a cubic b-spline.

This is a stateful transform (for details see
:ref:`stateful-transforms`). If ``knots``, ``lower_bound``, or
``upper_bound`` are not specified, they will be calculated from the data
and then the chosen values will be remembered and re-used for prediction
from the fitted model.

Using this function requires scipy be installed.

.. note:: This function is very similar to the R function of the same
  name. In cases where both return output at all (e.g., R's ``bs`` will
  raise an error if ``degree=0``, while patsy's will not), they should
  produce identical output given identical input and parameter settings.

.. warning:: I'm not sure on what the proper handling of points outside
  the lower/upper bounds is, so for now attempting to evaluate a spline
  basis at such points produces an error. Patches gratefully accepted.

.. versionadded:: 0.2.0
c                 .    0 U l         S U l        S U l        g r4   )_tmp_degree
_all_knots)selfs    r%   __init__BS.__init__   s    	r9   Nc                 B   UUUUUUS.nXR                   S'   [        R                  " U5      nUR                  S:X  a  UR                  S   S:X  a	  US S 2S4   nUR                  S:  a  [        S5      eU R                   R                  S/ 5      R                  U5        g )N)dfr   r    include_interceptlower_boundupper_boundargsr   r   r   z1input to 'bs' must be 1-d, or a 2-d column vectorxs)rE   r   r   r   r   
ValueError
setdefaultappend)	rH   r   rL   r   r    rM   rN   rO   rP   s	            r%   memorize_chunkBS.memorize_chunk   s     !2&&
 !		&MM!66Q;1771:?!Q$A66A:STT 			T2&--a0r9   c                 ,   U R                   nUS   nU ? US   S:  a  [        SUS   < S35      e[        US   5      US   :w  a  [        SU R                  < S35      e[        R
                  " US   5      nUS   c  US	   c  [        S
5      eUS   S-   nUS   b  US   U-
  nUS   (       d  US-  nUS:  a*  [        SUS   < SUS   < SUS   < SUS   U-
  < 35      eUS	   bA  [        US	   5      U:w  a.  [        SUS   < SUS   < SU< S[        US	   5      < S3	5      eO)[        R                  " SSUS-   5      SS n[        X65      nUS	   b  US	   nUS   b  US   nO[        R                  " U5      nUS   b  US   n	O[        R                  " U5      n	X:  a  [        SU< SU	< S35      e[        R                  " W5      nUR                  S:  a  [        S5      e[        R                  " Xx:  5      (       a  [        SXwU:     < SU< S35      e[        R                  " Xy:  5      (       a  [        SXwU	:     < SU	< S35      e[        R
                  " X/U-  U45      n
U
R                  5         US   U l        Xl        g )NrP   r    r   z#degree must be greater than 0 (not )zdegree must be an integer (not rQ   rL   r   zmust specify either df or knotsr   rM   zdf=z is too small for degree=z and include_intercept=z; must be >= z with degree=z	 implies z knots, but z knots were providedr   rN   rO   zlower_bound > upper_bound (z > zknots must be 1 dimensionalzsome knot values (z) fall below lower bound (z) fall above upper bound ()rE   rR   r   rF   r   concatenater   linspacer1   r   r   r   r   anyr   rG   )rH   tmprP   r   r)   n_inner_knotsknot_quantilesinner_knotsrN   rO   	all_knotss              r%   memorize_finishBS.memorize_finish   s   ii6{I>A<@NL  tH~$x.0T\\STT NN3t9%:$w-"7>??X":! J.M+,"q   T
X01 T
]2
  G}(tG}%6$ !J N)W.	 	 7 "$Q=13D!Ea!K0C=$w-K*}-K&&)K*}-K&&)K$9DkR  jj-a:;;66++,,%K&?@+O  66++,,%K&?@+O  NN[$>$F#TU	H~#r9   c                 ,   [        XR                  U R                  5      nU(       d  US S 2SS 24   n[        (       aV  [	        U[
        R                  [
        R                  45      (       a'  [
        R                  " U5      nUR                  Ul        U$ )Nr   )	r&   rG   rF   r   
isinstancepandasSeries	DataFrameindex)	rH   r   rL   r   r    rM   rN   rO   r"   s	            r%   	transformBS.transform  sk     $AE !QR%LE;!fmmV-=-=>??((/ggr9   )rG   rF   rE   )NN   FNN)__name__
__module____qualname____firstlineno____doc__rI   rU   rb   rj   r   __getstate____static_attributes__ r9   r%   rB   rB   U   sM    9v 1:R$n & Lr9   rB   c                  n   SSK Jn   SSKJnJnJn  UR                  S5      nSnUR                  S5      n XF   S:X  d  OUS-  nUR                  SU5      nXFU n0 n	U H  n
U
R                  SS5      u  pXU'   M     [        U	S	   5      [        U	S
   5      [        U	S   5      S.nU	S   S:w  a  [        U	S   5      u  pXS'   XS'   U	S   S:H  US'   [        R                  " [        U	S   5      5      nUS
   b  UR                  S   US
   :X  d   eU " [        SUU40 UD6  US-  nUS-   nM  XS:X  d   eg )Nr   )check_stateful)R_bs_test_xR_bs_test_dataR_bs_num_tests
z--BEGIN TEST CASE--r   z--END TEST CASE--=r    rL   r   )r    rL   r   zBoundary.knotsNonerN   rO   	interceptTRUErM   outputF)patsy.test_staterv   patsy.test_splines_bs_datarw   rx   ry   splitri   r   evalr   r   r   rB   )rv   rw   rx   ry   lines	tests_ran	start_idxstop_idxblock	test_datalinekeyvaluekwargslowerupperr   s                    r%   test_bs_compatr      s{   /VV  &EI12I
#88Q	;;2I>)	DC+JC"cN 
 )H-.y')G,-
 %&&0	*: ;<LE$)=!$)=!&/&<&F"#
 D8!456$<#<<?fTl222r5+v@@Q	qL	E F &&&r9   r   c            	          [         R                  " SSS5      n [        U SS/SSS9nUR                  S   S:X  d   e[         R                  " S5      nSX S:  '   [         R
                  " US S 2S4   U5      (       d   e[         R                  " S5      nSX0S:  U S:  -  '   [         R
                  " US S 2S4   U5      (       d   e[         R                  " S5      nSX@S:  '   [         R
                  " US S 2S	4   U5      (       d   e[         R
                  " [        / S
QSS/SS9SS/SS/SS//5      (       d   e[        U SS/SSS9n[        U SS/SSS9n[         R
                  " US S 2SS 24   U5      (       d   eg )NrY   r   r:      r   T)r   r    rM   rl   r   )r   r   r   )r    r   rM   F)r   logspacer   r   r   array_equal)r   result
expected_0
expected_1
expected_2
result_intresult_no_ints          r%   test_bs_0degreer   R  s~   
B2A!QTBF<<?a"JJ1u>>&A,
3333"J%&JQ1q5!">>&A,
3333"JJAv>>&A,
3333
 >>
9QqcTB
Q!Q!Q    
 AaVAFJqAqEJM>>*QU+];;;;r9   c            
      `   SS K n [        R                  " SSS5      nU R                  [        [
        USSS9  U R                  [        [
        USSS9  U R                  [        [
        U5        [        USSS/S	-  S
9  [        USSS/S-  S
9  [        USSS/S-  SS9  [        USSS/S-  SS9  U R                  [        [
        USSS/S-  S
9  U R                  [        [
        USSS/S	-  S
9  U R                  [        [
        USSS/S-  SS9  U R                  [        [
        USSS/S-  SS9  U R                  [        [
        USSS/S-  S
9  U R                  [        [
        USSS/S-  S
9  U R                  [        [
        USSS/S-  SS9  U R                  [        [
        USSS/S	-  SS9  U R                  [        [
        USSS9  U R                  [        [
        USSS9  U R                  [        [
        USSS9  U R                  [        [
        USSS9  U R                  [        [
        USSSS9  U R                  [        [
        [        R                  " X45      S5        [        R                  " [        USS/S9[        USS/S95      (       d   eU R                  [        [
        US/S//S9  U R                  [        [
        USS/S9  U R                  [        [
        USS/SS9  U R                  [        [
        USS/S9  U R                  [        [
        USS/SS9  g )Nr   ir:   r;   rl   )rN   )rO   F   )rL   rM   r   T   	   r   )rL   rM   r   r          )rL   r    rY   g      ?)rN   rO   r   )r   )r   rO   i)r   rN   )	pytestr   r[   raisesr   r   rR   column_stackr   )r   r   s     r%   test_bs_errorsr   m  s   
CR A MM%r1aQM?
MM%r1aQM?
MM*b!$ qR5a8qR4sQw7qR5aBqR4sQwqA
MM*b!eA3QR7MS
MM*b!d1#PQ'MR
MMBbE!rRS   MMBbDaPQ   MM*b!eA3QR7MS
MM*b!d1#PQ'MR
MMBbE!qQR   MMBbDaPQ   MM*b!!M4
MM*b!!M4
MM*b!2M6
MM*b!3M7
MM*b!QA2MF
MM*b"//1&"91=>>"Qq!f-r!Aq6/BCCCC
MM*b!QC";M7
MM*b!Ar7M3
MM*b!Aq6qMA
MM*b!C8M4
MM*b!B7MCr9   )__all__numpyr   
patsy.utilr   r   r   patsy.stater   rf   r&   r1   r@   objectrB   r   r   slowr   r   rt   r9   r%   <module>r      sf    &  C C *,^5/E EP *'Z  
<65Dr9   