
    >h\                        S r SSKJr  SSKrSSKrSSKrSSKrSSKJr  SSK	r
SSKJr  SSKJrJrJrJr  SS/rS	q " S
 S5      r\" 5       rSSS.rSSSS.rS rS*S jrS+S jrS rS,S jrS rS rS rS rS r S r!S r" " S S 5      r# " S! S"\#5      r$S# r%\" S$S%5            S-S& j5       r&\" S$S%5           S.S' j5       r' " S( S)5      r(g)/z
Run x12/x13-arima specs in a subprocess from Python and curry results back
into python.

Notes
-----
Many of the functions are called x12. However, they are also intended to work
for x13. If this is not the case, it's a bug.
    )deprecate_kwargN)warn)Bunch)X13NotFoundError	IOWarningX13Error
X13Warningx13_arima_select_orderx13_arima_analysis)z	x13as.exex13aszx12a.exex12ax13as_ascii
x13as_htmlc                       \ rS rSrS rSrg)_freq_to_period   c                     UR                  S5      (       a  gUR                  S5      (       a  gUR                  S5      (       a  gg )NM   Q   W4   )
startswith)selfkeys     fC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\statsmodels/tsa/x13.py__getitem___freq_to_period.__getitem__    s=    >>#^^C  ^^C   !     N)__name__
__module____qualname____firstlineno__r   __static_attributes__r!   r    r   r   r      s    r    r   r   r   )r   r   lognoneauto)TFNc                     U (       a  S$ S$ )Nyesnor!   xs    r   <lambda>r/   -   s    QE0D0r    c                    U b]  U R                  [        5      (       aC  [        R                  R	                  U 5      (       d  [        R                  R                  U 5      n U(       dE  [        SSS2   qU c  [        R                  " SS5      n U (       d  [        R                  " SS5      n O8U c5  [        R                  " SS5      n U (       d  [        R                  " SS5      n [         HW  n[        R                  R                  X5      n [        R                  " U[        R                  [        R                  S9  Us  $    g! [         a     Mi  f = f)a  
If x12path is not given, then either x13as[.exe] or x12a[.exe] must
be found on the PATH. Otherwise, the environmental variable X12PATH or
X13PATH must be defined. If prefer_x13 is True, only X13PATH is searched
for. If it is false, only X12PATH is searched for.
NX12PATH X13PATHstdoutstderrF)endswith_binary_namesospathisdirdirnamegetenvjoin
subprocess
check_callPIPEOSError)x12path
prefer_x13binaryx12s       r   	_find_x12rH   0   s     w//>>ww}}W%%ggoog.G%dd+?ii	2.Gii	2.G	))Ir*ii	2.Gggll7+	!!#joo)3:J   	  		s   3E
EEc                 @    [        U 5      n U (       d  [        S5      eU $ )Nzxx12a and x13as not found on path. Give the path, put them on PATH, or set the X12PATH or X13PATH environmental variable.)rH   r   )rD   s    r   
_check_x12rJ   U   s+     G  L M 	M Nr    c                     [         R                  " SU 5      n S n[        U 5      S:  a  [        X5      u  pX4$ U" U S   5      n SnX4$ )z
Takes something like (1 1 0)(0 1 1) and returns a arma order, sarma
order tuple. Also accepts (1 1 0) and return arma order and (0, 0, 0)
z\([0-9 ]*?\)c           
      ~    [        [        [        [        R                  " SSU 5      R                  S5      5      5      $ )Nz[()]r3    )tuplemapintresubsplitr-   s    r   clean_clean_order.<locals>.cleane   s,    SbffVR399#>?@@r       r   )r   r   r   )rQ   findalllenrO   )orderrT   sorders      r   _clean_orderr[   ^   sY    
 JJ.EA 5zA~E)
 = eAh=r    c                     U(       a  U(       a  [        S5      eU(       a  U SU-   /nOU(       a  U SU-   /nOX/nU(       a  XR/-  n[        R                  " U[        R                  [        R                  S9$ )Nz&Cannot specify both meta and datameta.z-m z-d r5   )
ValueErrorr@   PopenrB   STDOUT)rD   specpathoutnamemetadatametaargss         r   run_specre   q   sp    ABB)*	)*"	D#-#4#46 6r    c                     SnUSU S    SU S    S3-  nUb  USUS    SUS    S3-  nU$ USUS    SUS    S3-  nU$ )	N
zmaxorder = (r   rM   rV   )
zmaxdiff = (zdiff = (r!   )maxordermaxdiffdiffoptionss       r   _make_automdl_optionsrm      s~    Ghqk]!HQK=<<G[Agaj\== N 	Xd1gYaQy44Nr    c                 @   [        U S5      (       a  U R                  /nO)[        U S5      (       a  U R                  nO[        S5      e SR	                  U5      nU$ ! [
         a6    SSKJn  U R                  S:X  a  Sn U$ SR	                  U" U 5      5      n U$ f = f)	Nnamecolumnsz0exog is not a Series or DataFrame or is unnamed.rM   r   )_make_exog_namesrV   x1)	hasattrro   rp   r]   r?   	TypeErrorstatsmodels.base.datarq   ndim)exog	var_namesrq   s      r   _make_var_namesry      s    tVYYK		y	!	!LL	KLL9HHY'	   9:99>I  !1$!78I9s   
A "BBBc           
         U (       d  Uc  gSnU (       a  US-  nUbk  [        U5      nUSU S3-  nUSR                  SR                  [        [        UR
                  R                  5       R                  5       5      5      5      -  nUS-  nU$ )	Nr3   zregression{
z    variables = (td)
z    user = (rh   z    data = ({})
rg   }
)ry   formatr?   rO   strvaluesraveltolist)tradingrw   reg_specrx   s       r   _make_regression_optionsr      s    t|H,,#D)	l9+S11'..IIC**,3356
 	
 HOr    c                 $    U c  gSnUSU  S3-  nU$ )Nr3   z
forecast{
zmaxlead = (z)
}
r!   )forecast_periodsforecast_specs     r   _make_forecast_optionsr      s+    !M{#3"4G<<Mr    c                     X R                  S5      S-   S  R                  5       n U (       a  SU ;   a  [        U 5      eU (       a  SU ;   a  [        U [        5        g g g )Nzspc:r   ERRORWARNING)findstripr   r   r	   )errorss    r   _check_errorsr      sT    KK')*+113F'V#v	I'VZ  (r    c                     SSK Jn  SSKJn  U" U" U 5      SSSSS9nUR	                  U5      R                  S	U0S
9U   $ )z]
Convert x to a DataFrame where x is a string in the format given by
x-13arima-seats output.
r   )StringIO)read_csv   N	python)skiprowsheadersepenginerV   )rp   )ior   pandasr   	set_indexrename)r.   datesro   r   r   outs         r   _convert_out_to_seriesr      sI    
 
8A;D;C==&&4y&9$??r    c                 p    [        U SS9 nUR                  5       nS S S 5        U$ ! , (       d  f       W$ = f)Nzutf-8)encoding)openread)fnamefinfouts      r   _open_and_readr      s1    	eg	&#xxz 
'K 
'	&Ks   &
5c                   0    \ rS rSr\S 5       rS rS rSrg)Spec   c                 N    U R                   R                  R                  SS5      $ )Nr   r3   )	__class__r"   replace)r   s    r   	spec_nameSpec.spec_name   s    ~~&&..vr::r    c                 N    SnUR                  U R                  U R                  S9$ )Nz/{name} {{
        {options}
        }}
        )ro   rl   )r|   r   rl   )r   kwargsspecs      r   create_specSpec.create_spec   s.     {{#'<<  1 	1r    c                     SnUR                  5        H+  u  p4X# SU S3-  nU R                  R                  X405        M-     X l        g )Nr3   =rg   )items__dict__updaterl   )r   r   rl   r   values        r   set_optionsSpec.set_options   sI     ,,.JCawb))GMM  #. ) r    )rl   N)	r"   r#   r$   r%   propertyr   r   r   r&   r!   r    r   r   r      s    ; ;1r    r   c                   F    \ rS rSrSrSSSSSSSS	S/ / SS
SSSSS4S jrSrg)
SeriesSpec   z
Parameters
----------
data
appendbcst : bool
appendfcst : bool
comptype
compwt
decimals
modelspan
name
period
precision
to_print
to_save
span
start
title
type

Notes
-----
Rarely used arguments

divpower
missingcode
missingval
saveprecision
trimzero
Unnamed SeriesFNrV   r   r!   r   )rV   rV   r3   iayi ʚ;c           
      v    [        [        UU/5      u  p4SUS S  S3nSUS S  S3nU R                  XXIUUUS9  g )N"@   O   )data
appendbcst
appendfcstperiodstarttitlero   )rO   _bool_to_yes_nor   )r   r   ro   r   r   comptypecompwtdecimals	modelspanr   	precisionto_printto_savespanr   r   series_typedivpowermissingcode
missingvalseries_names                        r   __init__SeriesSpec.__init__
  sf     "%_z7A79 ":
 49+R(U3BZL#d$.U$; 	 	r    )r"   r#   r$   r%   __doc__r   r&   r!   r    r   r   r      s8    < #3u!q1a"brRTD#
r    r   c           	         [        U S5      (       a5  [        U R                  5      S:  a  [        S5      eX R                  S      n SR	                  SR                  [        [        U R                  R                  5       5      5      5      n [        U R                  R                     nU R                  S   nUS:X  a  UR                   UR"                  peO)US	:X  a  UR                   UR$                  peO[        S
5      e[        U S5      (       a  U R&                  =(       d    SnOSn[)        UUUUU SU 3S9nU$ ! [        [        4 a"    SSKJn  [        U" U R                  5         n Nf = f)Nrp   rV   z3Does not handle DataFrame with more than one columnr   z({})rg   )
infer_freqr   r   zqOnly monthly and quarterly periods are supported. Please report or send a pull request if you want this extended.ro   r   .)r   ro   r   r   r   )rs   rX   rp   r]   r|   r?   rO   r}   r~   r   r   indexfreqstrAttributeErrorpandas.tseries.apir   yearmonthquarterro   r   )	r.   r   r   r   
start_dater   stperiodro   series_specs	            r   pandas_to_series_specr     sN    q)qyy>A & ' 'iilO==3sAHHOO,=#>?@D
6 1 J|#**:*:h	1#**<*<h * + 	+ q&vv))az"K 1 J' 61 AGG!456s   D> >/E0/E0forecast_yearsr   c           
      <	   [        U5      n[        U [        R                  [        R                  45      (       dC  Ub  Uc  [        S5      e[        R                  " U [        R                  " U[        U 5      US9S9n [        U 5      nUR                  5       nUS[        U    S3-  nU(       a  US-  n[        XU5      nUSU S3-  nU[        Xt5      -  nU[        U5      -  nUS	-  nU
(       a  U$ [        R                  " S
SUS9n[        R                  " S
US9n UR!                  UR#                  S5      5        UR%                  5         UR%                  5         ['        UUR(                  SS UR(                  5      nUR+                  5         UR,                  R/                  5       nU(       a#  [1        UR,                  R/                  5       5        [3        UR(                  S-   5      n[5        U5        [3        UR(                  S-   5      n[3        UR(                  S-   5      n[3        UR(                  S-   5      n[3        UR(                  S-   5      n [6        R8                  " UR(                  5        [6        R8                  " UR(                  5        [E        UU RF                  S5      n[E        UU RF                  S5      n[E        UU RF                  S5      nU	(       d  [I        U UUUUUS9nU$ [I        U UUUUUUS9nU$ ! [:         a    [6        R<                  R?                  UR(                  5      (       a  [A        SUR(                   3[B        5        [6        R<                  R?                  UR(                  5      (       a  [A        SUR(                   3[B        5         GNf = f!  [6        R8                  " UR(                  5        [6        R8                  " UR(                  5        f ! [:         a    [6        R<                  R?                  UR(                  5      (       a  [A        SUR(                   3[B        5        [6        R<                  R?                  UR(                  5      (       a  [A        SUR(                   3[B        5         f  f f = f= f)a  
Perform x13-arima analysis for monthly or quarterly data.

Parameters
----------
endog : array_like, pandas.Series
    The series to model. It is best to use a pandas object with a
    DatetimeIndex or PeriodIndex. However, you can pass an array-like
    object. If your object does not have a dates index then ``start`` and
    ``freq`` are not optional.
maxorder : tuple
    The maximum order of the regular and seasonal ARMA polynomials to
    examine during the model identification. The order for the regular
    polynomial must be greater than zero and no larger than 4. The
    order for the seasonal polynomial may be 1 or 2.
maxdiff : tuple
    The maximum orders for regular and seasonal differencing in the
    automatic differencing procedure. Acceptable inputs for regular
    differencing are 1 and 2. The maximum order for seasonal differencing
    is 1. If ``diff`` is specified then ``maxdiff`` should be None.
    Otherwise, ``diff`` will be ignored. See also ``diff``.
diff : tuple
    Fixes the orders of differencing for the regular and seasonal
    differencing. Regular differencing may be 0, 1, or 2. Seasonal
    differencing may be 0 or 1. ``maxdiff`` must be None, otherwise
    ``diff`` is ignored.
exog : array_like
    Exogenous variables.
log : bool or None
    If None, it is automatically determined whether to log the series or
    not. If False, logs are not taken. If True, logs are taken.
outlier : bool
    Whether or not outliers are tested for and corrected, if detected.
trading : bool
    Whether or not trading day effects are tested for.
forecast_periods : int
    Number of forecasts produced. The default is None.
retspec : bool
    Whether to return the created specification file. Can be useful for
    debugging.
speconly : bool
    Whether to create the specification file and then return it without
    performing the analysis. Can be useful for debugging.
start : str, datetime
    Must be given if ``endog`` does not have date information in its index.
    Anything accepted by pandas.DatetimeIndex for the start value.
freq : str
    Must be givein if ``endog`` does not have date information in its
    index. Anything accepted by pandas.DatetimeIndex for the freq value.
print_stdout : bool
    The stdout from X12/X13 is suppressed. To print it out, set this
    to True. Default is False.
x12path : str or None
    The path to x12 or x13 binary. If None, the program will attempt
    to find x13as or x12a on the PATH or by looking at X13PATH or
    X12PATH depending on the value of prefer_x13.
prefer_x13 : bool
    If True, will look for x13as first and will fallback to the X13PATH
    environmental variable. If False, will look for x12a first and will
    fallback to the X12PATH environmental variable. If x12path points
    to the path for the X12/X13 binary, it does nothing.
tempdir : str
    The path to where temporary files are created by the function.
    If None, files are created in the default temporary file location.

Returns
-------
Bunch
    A bunch object containing the listed attributes.

    - results : str
      The full output from the X12/X13 run.
    - seasadj : pandas.Series
      The final seasonally adjusted ``endog``.
    - trend : pandas.Series
      The trend-cycle component of ``endog``.
    - irregular : pandas.Series
      The final irregular component of ``endog``.
    - stdout : str
      The captured stdout produced by x12/x13.
    - spec : str, optional
      Returned if ``retspec`` is True. The only thing returned if
      ``speconly`` is True.

Notes
-----
This works by creating a specification file, writing it to a temporary
directory, invoking X12/X13 in a subprocess, and reading the output
directory, invoking exog12/X13 in a subprocess, and reading the output
back in.
Nz=start and freq cannot be none if endog is not a pandas object)r   periodsfreq)r   ztransform{function=r{   z
outlier{}
zautomdl{zx11{ save=(d11 d12 d13) }Fz.spc)deletesuffixdir)r   r   utf8z.errz.outz.d11z.d12z.d13zFailed to delete resource seasadjtrend	irregular)observedresultsr   r   r   r6   )r   r   r   r   r   r6   r   )%rJ   
isinstancepd	DataFrameSeriesr]   DatetimeIndexrX   r   r   _log_to_x12rm   r   r   tempfileNamedTemporaryFilewriteencodeclosere   ro   waitr6   r   printr   r   r:   removerC   r;   existsr   r   r   r   X13ArimaAnalysisResult)endogri   rj   rk   rw   r'   outlierr   r   retspecspeconlyr   r   print_stdoutrD   rE   tempdirspec_objr   rl   ftempinftempoutpr6   r   r   r   r   r   ress                                 r   r   r   H  s   D !GebllBII677=DL / 0 0		%r'7'7e@CE
=A(C D %U+H!D";s#3"4D99D#Ht<Giy%%D$W33D"#344D''D ))17.57G **%WEH dkk&)*Wgll3B/?	!((--/" 67f !!78 !78x}}v56"8==6#9:	
	 IIgll#IIhmm$ %Wekk9EG"5%++w?E&y%++{KI $eW-4E/8I J	 %eW-4E/8*.0 J/  	 ww~~gll++1',,@ ww~~hmm,,1(--A 	 	
	 IIgll#IIhmm$ 	 ww~~gll++1',,@ ww~~hmm,,1(--A  -		 sG    D;N0 A L	 	B N-,N-0R2A O32R3B RRRRc                    [        XXEXgUXUXUUS9n[        R                  " SUR                  5      nUR	                  5       n[        R                  " SUR                  5      (       a  SnO+[        R                  " SUR                  5      (       a  SnOSn[        U5      u  nn[        UUUUR                  UR                  S9nU$ )a  
Perform automatic seasonal ARIMA order identification using x12/x13 ARIMA.

Parameters
----------
endog : array_like, pandas.Series
    The series to model. It is best to use a pandas object with a
    DatetimeIndex or PeriodIndex. However, you can pass an array-like
    object. If your object does not have a dates index then ``start`` and
    ``freq`` are not optional.
maxorder : tuple
    The maximum order of the regular and seasonal ARMA polynomials to
    examine during the model identification. The order for the regular
    polynomial must be greater than zero and no larger than 4. The
    order for the seasonal polynomial may be 1 or 2.
maxdiff : tuple
    The maximum orders for regular and seasonal differencing in the
    automatic differencing procedure. Acceptable inputs for regular
    differencing are 1 and 2. The maximum order for seasonal differencing
    is 1. If ``diff`` is specified then ``maxdiff`` should be None.
    Otherwise, ``diff`` will be ignored. See also ``diff``.
diff : tuple
    Fixes the orders of differencing for the regular and seasonal
    differencing. Regular differencing may be 0, 1, or 2. Seasonal
    differencing may be 0 or 1. ``maxdiff`` must be None, otherwise
    ``diff`` is ignored.
exog : array_like
    Exogenous variables.
log : bool or None
    If None, it is automatically determined whether to log the series or
    not. If False, logs are not taken. If True, logs are taken.
outlier : bool
    Whether or not outliers are tested for and corrected, if detected.
trading : bool
    Whether or not trading day effects are tested for.
forecast_periods : int
    Number of forecasts produced. The default is None.
start : str, datetime
    Must be given if ``endog`` does not have date information in its index.
    Anything accepted by pandas.DatetimeIndex for the start value.
freq : str
    Must be givein if ``endog`` does not have date information in its
    index. Anything accepted by pandas.DatetimeIndex for the freq value.
print_stdout : bool
    The stdout from X12/X13 is suppressed. To print it out, set this
    to True. Default is False.
x12path : str or None
    The path to x12 or x13 binary. If None, the program will attempt
    to find x13as or x12a on the PATH or by looking at X13PATH or X12PATH
    depending on the value of prefer_x13.
prefer_x13 : bool
    If True, will look for x13as first and will fallback to the X13PATH
    environmental variable. If False, will look for x12a first and will
    fallback to the X12PATH environmental variable. If x12path points
    to the path for the X12/X13 binary, it does nothing.
tempdir : str
    The path to where temporary files are created by the function.
    If None, files are created in the default temporary file location.

Returns
-------
Bunch
    A bunch object containing the listed attributes.

    - order : tuple
      The regular order.
    - sorder : tuple
      The seasonal order.
    - include_mean : bool
      Whether to include a mean or not.
    - results : str
      The full results from the X12/X13 analysis.
    - stdout : str
      The captured stdout from the X12/X13 analysis.

Notes
-----
This works by creating a specification file, writing it to a temporary
directory, invoking X12/X13 in a subprocess, and reading the output back
in.
)rD   rw   r'   r
  r   r   ri   rj   rk   r   r   rE   r  z&(?<=Final automatic model choice : ).*zMean is not significantFConstantT)rY   rZ   include_meanr   r6   )r   rQ   searchr   groupr[   r   r6   )r	  ri   rj   rk   rw   r'   r
  r   r   r   r   r  rD   rE   r  r   modelrY   r  rZ   r  s                        r   r
   r
     s    n !d)02B*2$',J)02G II>oo'EKKME	yy*GOO<<	:w	/	/ 'ME6
eF@CJr    c                        \ rS rSrS rS rSrg)r  ic  c                 N    UR                  5        H  u  p#[        XU5        M     g N)r   setattr)r   r   r   r   s       r   r   X13ArimaAnalysisResult.__init__d  s     ,,.JCDu% )r    c                    SSK Jn  U" 5       nUR                  SSSS9u  p4U R                  R	                  US   SS9  US   R                  S	5        U R                  R	                  US   SS9  US   R                  S
5        U R                  R	                  US   SS9  US   R                  S5        U R                  R	                  US   SS9  US   R                  S5        UR                  5         U$ )Nr   )_import_mplr   rV   T)sharexF)axlegendObservedzSeas. Adjustedr   Trend   	Irregular)
statsmodels.graphics.utilsr   subplotsr   plot
set_ylabelr   r   r   tight_layout)r   r   pltfigaxess        r   r*  X13ArimaAnalysisResult.ploth  s    :mLLAdL3	d1ge4Q:&T!WU3Q+,

4751Q7#tAwu5Q;'
r    r!   N)r"   r#   r$   r%   r   r*  r&   r!   r    r   r  r  c  s    &r    r  )NTr  )NFF)r   rV   r1  NNNTFNFFNNFNTN)r1  r1  NNNTFNNNFNTN))r   statsmodels.compat.pandasr   r:   r@   r   rQ   warningsr   r   r   statsmodels.tools.toolsr   statsmodels.tools.sm_exceptionsr   r   r   r	   __all__r9   r   _period_to_freqr   r   rH   rJ   r[   re   rm   ry   r   r   r   r   r   r   r   r   r   r
   r  r!   r    r   <module>r8     s2   6 	   	   )9 9 $%9
:.  "#s#680"J&6$$(!	@ */ /d(V !#56DHBG6;8<DH#k 7k\ !#56HLFK,0?DBF	h 7hV r    