
    M/Ph!                       d dl mZ d dlmZmZmZ d dlZd dlZd dlZ	d dl
mZmZmZmZmZmZmZmZmZmZ d dlmZ d dlmZ d dlmc mZ d dlmc mZ d dlm Z  dZ!d	Z"ej#        Z$ej%        Z%d
 Z&d Z'	 	 	 	 	 dddZ( G d dej)                  Z* G d dej+                  Z, G d dej-                  Z. ej/        e.e,           dS )    )annotations)is_float_indexis_int_indexis_numeric_dtypeN)
DatetimeIndexIndexPeriodPeriodIndex
RangeIndexSeries	Timestamp
date_rangeperiod_rangeto_datetime)	to_offset)
PandasData)ValueWarninga  
    %(model)s

    Parameters
    ----------
    %(params)s
    dates : array_like, optional
        An array-like object of datetime objects. If a pandas object is given
        for endog or exog, it is assumed to have a DateIndex.
    freq : str, optional
        The frequency of the time-series. A Pandas offset or 'B', 'D', 'W',
        'M', 'A', or 'Q'. This is optional if dates are given.
    %(extra_params)s
    %(extra_sections)szTimeseries model base classc           	        |}|}t          |t          t          f          }t          |          }t          |t                    }t          |          }t          |          }|rt          | t          t          j	        f          rg| dk     r|  |k    r|| z   } nT| |dz
  k    rK	 |j
        }|j        }	n# t          $ r |j        }|j        }	Y nw xY w|| dz   |	z  z   }
t	          ||
|	          }|s||rz|sxt          | t          t          j	        f          rW| dk     r|  |k    r|| z   } nD| |d         k    r8t          t          j        |d         t          | dz                                 }|r4|t          u rt"          }nt$          }t          | t          t          j	        f          rj| dk     r|  |k     r||| z            } n| t          |          dz
  k    r2 ||d         t          | dz             |j                  }|d         } n||          } n|t          u rt)          | |j                  }nt+          |           }||d         k    rV ||d         ||j                  }|d         |k    s) ||d         t          |          dz   |j                  }|d         } |r|                    |           }n[|s|rB	 ||           n5# t.          t0          f$ r!}t3          t5          |                    d}~ww xY w| }n|                    |           }||u}t          |t6                    r|j        dz
  }n|}||d|dz            |fS )	a  
    Get the location of a specific key in an index

    Parameters
    ----------
    key : label
        The key for which to find the location if the underlying index is
        a DateIndex or a location if the underlying index is a RangeIndex
        or an Index with an integer dtype.
    index : pd.Index
        The index to search.

    Returns
    -------
    loc : int
        The location of the key
    index : pd.Index
        The index including the key; this is a copy of the original index
        unless the index had to be expanded to accommodate `key`.
    index_was_expanded : bool
        Whether or not the index was expanded to accommodate `key`.

    Notes
    -----
    If `key` is past the end of of the given index, and the index is either
    an Index with an integral dtype or a date index, this function extends
    the index up to and including key, and then returns the location in the
    new index.
    r      )startstopstep)r   periodsfreq)r   r   endr   N)
isinstancer
   r   r   r   typelenintnpintegerr   r   AttributeError_start_stepr   aranger   r   r   r	   r   get_loc
IndexError
ValueErrorKeyErrorstrslicer   )keyindex
base_index
date_index	int_indexrange_indexindex_classnobsbase_index_startbase_index_stepr   index_fndate_keyloceindex_was_expandedr   s                    ^/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/statsmodels/tsa/base/tsa_model.pyget_index_locr>   5   s   < JEJm(DEEJZ((IZ44Kz""Ku::D  z#RZ'899 77tt||*CC4!8^^3#-#3 ",/! 3 3 3#-#4 ","23 $sQw/&AAD&T  E BB B sS"*-..	B 77tt||*CC:b>!!")JqM3sQw<<@@AAE  / -''!HH#HcC,-- (	 QwwC4$;;D3J' s:*** $Q-aLL#  
 BiCj k))!#JO<<<$S>> *R.(( $Q-XJO  
 RyH,,$H(m #E

Q'_  E Bi  !mmC  	 !k !	##JJJ J' 	# 	# 	#3q66"""	#mmC   j0 #u hliai "444s*   #B2 2CC?K K:K55K:c                   	 t          | |          \  }}}n# t          $ r}	 t          | t          t          j        f          s|                    |           }n t          |t                    r|j        }t          |t          j	                  r-|j
        t          k    rt	          j        |          }n|d         }t          |t          j                  s |d|dz            }d}n#  |xY wY d}~nd}~ww xY w|||fS )a  
    Get the location of a specific key in an index or model row labels

    Parameters
    ----------
    key : label
        The key for which to find the location if the underlying index is
        a DateIndex or is only being used as row labels, or a location if
        the underlying index is a RangeIndex or a NumericIndex.
    index : pd.Index
        The index to search.
    row_labels : pd.Index
        Row labels to search if key not found in index

    Returns
    -------
    loc : int
        The location of the key
    index : pd.Index
        The index including the key; this is a copy of the original index
        unless the index had to be expanded to accommodate `key`.
    index_was_expanded : bool
        Whether or not the index was expanded to accommodate `key`.

    Notes
    -----
    This function expands on `get_index_loc` by first trying the given
    base index (or the model's index if the base index was not given) and
    then falling back to try again with the model row labels as the base
    index.
    r   Nr   F)r>   r+   r   r!   r"   r#   r(   r-   r   ndarraydtypeboolargmaxnumbersIntegral)r.   r/   
row_labelsr:   r<   r;   s         r=   get_index_label_locrG      s5   @%)6sE)B)B&U&& # # #"	cC#455  ((--
 #u%%  i#rz** ! 9$$
 )C..CC a&Cc7#344 yqy)E!&	G C#H )))s'    
C9CC('C4(C,,C44C9Freturn"tuple[int, int, int, Index | None]c	                <   	 t          | ||j                  \  } }	}
n# t          $ r t          d          w xY w| t          | t	          |          dz
            }	 t          |||j                  \  }}}n# t          $ r t          d          w xY wt          | t                    r| j        } t          |t                    r
|j        dz
  }|| d         }|| k     rt          d          |rt	          |          t	          |          k    st          d          t          |t                    s|st          j        dt          d	           t          |          }na|r[|sY|j        |
s|s|j        | |dz            }n?|st          j        d
t          d	           t          j        dt          d	           n|rd}|"|d         |_        |d         |_        ||_        nd|_        d|_        d|_        t          ||dz
  z
  d          }||z  }| |||fS )a)
  
    Get the location of a specific key in an index or model row labels

    Parameters
    ----------
    start : label
        The key at which to start prediction. Depending on the underlying
        model's index, may be an integer, a date (string, datetime object,
        pd.Timestamp, or pd.Period object), or some other object in the
        model's row labels.
    end : label
        The key at which to end prediction (note that this key will be
        *included* in prediction). Depending on the underlying
        model's index, may be an integer, a date (string, datetime object,
        pd.Timestamp, or pd.Period object), or some other object in the
        model's row labels.
    nobs : int
    base_index : pd.Index

    index : pd.Index, optional
        Optionally an index to associate the predicted results to. If None,
        an attempt is made to create an index for the predicted results
        from the model's index or model's row labels.
    silent : bool, optional
        Argument to silence warnings.

    Returns
    -------
    start : int
        The index / observation location at which to begin prediction.
    end : int
        The index / observation location at which to end in-sample
        prediction. The maximum value for this is nobs-1.
    out_of_sample : int
        The number of observations to forecast after the end of the sample.
    prediction_index : pd.Index or None
        The index associated with the prediction results. This index covers
        the range [start, end + out_of_sample]. If the model has no given
        index and no given row labels (i.e. endog/exog is not Pandas), then
        this will be None.

    Notes
    -----
    The arguments `start` and `end` behave differently, depending on if
    they are integer or not. If either is an integer, then it is assumed
    to refer to a *location* in the index, not to an index value. On the
    other hand, if it is a date string or some other type of object, then
    it is assumed to refer to an index *value*. In all cases, the returned
    `start` and `end` values refer to index *locations* (so in the former
    case, the given location is validated and returned whereas in the
    latter case a location is found that corresponds to the given index
    value).

    This difference in behavior is necessary to support `RangeIndex`. This
    is because integers for a RangeIndex could refer either to index values
    or to index locations in an ambiguous way (while for `NumericIndex`,
    since we have required them to be full indexes, there is no ambiguity).
    zYThe `start` argument could not be matched to a location related to the index of the data.Nr   zWThe `end` argument could not be matched to a location related to the index of the data.z)Prediction must have `end` after `start`.zeInvalid `index` provided in prediction. Must have length consistent with `start` and `end` arguments.zBecause the model data (`endog`, `exog`) were not given as Pandas objects, the prediction output will be Numpy arrays, and the given `index` argument will only be used internally.   
stacklevelzmNo supported index is available. Prediction results will be given with an integer index beginning at `start`.zNo supported index is available. In the next version, calling this method in a model without a supported index will result in an exception.r   r   )rG   rF   r+   maxr    r   r-   r   r   r*   r   warningswarnr   r   FutureWarningpredict_startpredict_endpredict_dates)r   r   r5   r0   r/   silent
index_noneindex_generateddata_	start_oos	end_indexend_oosprediction_indexout_of_samples                  r=   get_prediction_indexr_     s   P
1:t
 
q))  
 
 
:
 
 	


 {%Z1,--
"5T_#
 #
Y  
 
 
:
 
 	

 % #u hl !( U{{DEEE
 #$$E

22(   $
++ 		F 		M
     !<< 
    ?&	&W&#usQw?  > !     M      
   #-a0+B/-!! tax(!,,M=C#}&666s    7A8 8Bc                       e Zd Zeeeeddz  Z	 d fd	ZddZ	ddZ
ddZdddZd Zd Z eeedd          Z xZS )TimeSeriesModel )modelparamsextra_paramsextra_sectionsNnonec                n     t                      j        ||fd|i| |                     ||           d S )Nmissing)super__init___init_dates)selfendogexogdatesr   ri   kwargs	__class__s          r=   rk   zTimeSeriesModel.__init__  sI     	@@g@@@@ 	%%%%%    c                   ||}n| j         j        }||t          d          d}|t          |t          t
          f          s	 t          j        |          }t          |          s*t          |          st          |d         t                    rt          d          t          |t                    r|j        }t          |          }t          |t                    st          d          |}n#  |t          d          Y nxY wt          |t          t
          f          r|3|j        ,|j        }|#d}|t#          j        d	|z  t&          d
           |t)          |          }||j        |t          d          n|Q|j        Jt+          |d         |d         |          }|s'||k                                    st          d          |}n0||s|j        |k    st          d          n|t          d          |du}t          |t          t
          f          }t          |t
                    }	t/          |          }
t          |t0                    }|r	|j        dund}t          t3          | j        j        d                             }|
r|                    |          nd}|r 	 |j        }n# t<          $ r
 |j        }Y nw xY wd}|r"|s |s|st#          j        dt&          d
           |r|st#          j        dt&          d
           |r|st#          j        dt&          d
           d}|r|r|p|
o|p|}|r|}n|}d}|| _         || _!        |du | _"        |
o| o| | _#        |o| | _$        | j$        r| j         j        nd| _%        || _&        | j$        r| j         nd| j         _'        | j$        r| j         j(        nd| j         _        dS )a  
        Initialize dates

        Parameters
        ----------
        dates : array_like, optional
            An array like object containing dates.
        freq : str, tuple, datetime.timedelta, DateOffset or None, optional
            A frequency specification for either `dates` or the row labels from
            the endog / exog data.

        Notes
        -----
        Creates `self._index` and related attributes. `self._index` is always
        a Pandas index, and it is always NumericIndex, DatetimeIndex, or
        PeriodIndex.

        If Pandas objects, endog / exog may have any type of index. If it is
        an NumericIndex with values 0, 1, ..., nobs-1 or if it is (coerceable to)
        a DatetimeIndex or PeriodIndex *with an associated frequency*, then it
        is called a "supported" index. Otherwise it is called an "unsupported"
        index.

        Supported indexes are standardized (i.e. a list of date strings is
        converted to a DatetimeIndex) and the result is put in `self._index`.

        Unsupported indexes are ignored, and a supported NumericIndex is
        generated and put in `self._index`. Warnings are issued in this case
        to alert the user if the returned index from some operation (e.g.
        forecasting) is different from the original data's index. However,
        whenever possible (e.g. purely in-sample prediction), the original
        index is returned.

        The benefit of supported indexes is that they allow *forecasting*, i.e.
        it is possible to extend them in a reasonable way. Thus every model
        must have an underlying supported index, even if it is just a generated
        NumericIndex.
        Nz,Frequency provided without associated index.Fr   zNumeric index givenzCould not coerce to date indexz2Non-date index index provided to `dates` argument.TzMNo frequency information was provided, so inferred frequency %s will be used.rK   rL   zYNo frequency information was provided with date index and no frequency could be inferred.r   r   zEThe given frequency argument could not be matched to the given index.zBThe given frequency argument is incompatible with the given index.zKGiven index could not be coerced to dates but `freq` argument was provided.zAn unsupported index was provided. As a result, forecasts cannot be generated. To use the model for forecasting, use one of the supported classes of index.z|A date index has been provided, but it has no associated frequency information and so will be ignored when e.g. forecasting.zeA date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.))rX   rF   r*   r   r   r
   r"   asarrayr   r   floatr   valuesr   r   r   inferred_freqrO   rP   r   r   r   allr   r   rangern   shapeequalsis_monotonic_increasingr$   is_monotonic_index_index_generated_index_none_index_int64_index_dates_index_freq_index_inferred_freqrp   freqstr)rm   rp   r   r/   rx   r   resampled_index	has_indexr1   period_indexr2   r3   has_freq	incrementis_incrementr~   rW   valid_indexs                     r=   rl   zTimeSeriesModel._init_dates  s3   T EEI(E =T-KLLL
 em[%ABB *)  Z..F(00@)%00@ 'vay%88@
 ))>???
 "%00 - % )//F &fe44 K()IJJJ"EE	
 ((1   )( %-!=>> ><EJ$6 .D'(,+$M!137!8 !--.    #$T??D <EJ$6 ((<   ) %%**<&0#AhE"ID' ' 'O ) /U2J1O1O1Q1Q (B   ,EE
 $) %"Z4//$>   ! 9   %	{'CDD
!%55 ''	 
33-7A5:T))T%
 0 34455	2;Eu||I... 	 2$<! 2 2 2$12  L  	j 	K 	< 	M5      	h 	M2      	l 	M       5H5 *l 	  	#FFF"O / D=%Lk/L*n&>+>/3/@J4;++d$1! *.):D$++	040AK,,t	s   B-C5 5D
;K KKc                4    || j         }t          ||          S )a9  
        Get the location of a specific key in an index

        Parameters
        ----------
        key : label
            The key for which to find the location if the underlying index is
            a DateIndex or a location if the underlying index is a RangeIndex
            or an NumericIndex.
        base_index : pd.Index, optional
            Optionally the base index to search. If None, the model's index is
            searched.

        Returns
        -------
        loc : int
            The location of the key
        index : pd.Index
            The index including the key; this is a copy of the original index
            unless the index had to be expanded to accommodate `key`.
        index_was_expanded : bool
            Whether or not the index was expanded to accommodate `key`.

        Notes
        -----
        If `key` is past the end of of the given index, and the index is either
        an NumericIndex or a date index, this function extends the index up to
        and including key, and then returns the location in the new index.
        )r   r>   rm   r.   r0   s      r=   _get_index_loczTimeSeriesModel._get_index_loc  s!    > JS*---rs   c                J    || j         }t          ||| j        j                  S )a|  
        Get the location of a specific key in an index or model row labels

        Parameters
        ----------
        key : label
            The key for which to find the location if the underlying index is
            a DateIndex or is only being used as row labels, or a location if
            the underlying index is a RangeIndex or an NumericIndex.
        base_index : pd.Index, optional
            Optionally the base index to search. If None, the model's index is
            searched.

        Returns
        -------
        loc : int
            The location of the key
        index : pd.Index
            The index including the key; this is a copy of the original index
            unless the index had to be expanded to accommodate `key`.
        index_was_expanded : bool
            Whether or not the index was expanded to accommodate `key`.

        Notes
        -----
        This method expands on `_get_index_loc` by first trying the given
        base index (or the model's index if the base index was not given) and
        then falling back to try again with the model row labels as the base
        index.
        )r   rG   rX   rF   r   s      r=   _get_index_label_locz$TimeSeriesModel._get_index_label_loc  s(    > J"3
DI4HIIIrs   FrH   rI   c                    t          | j                  }t          |||| j        ||| j        | j        | j        	  	        S )a
  
        Get the location of a specific key in an index or model row labels

        Parameters
        ----------
        start : label
            The key at which to start prediction. Depending on the underlying
            model's index, may be an integer, a date (string, datetime object,
            pd.Timestamp, or pd.Period object), or some other object in the
            model's row labels.
        end : label
            The key at which to end prediction (note that this key will be
            *included* in prediction). Depending on the underlying
            model's index, may be an integer, a date (string, datetime object,
            pd.Timestamp, or pd.Period object), or some other object in the
            model's row labels.
        index : pd.Index, optional
            Optionally an index to associate the predicted results to. If None,
            an attempt is made to create an index for the predicted results
            from the model's index or model's row labels.
        silent : bool, optional
            Argument to silence warnings.

        Returns
        -------
        start : int
            The index / observation location at which to begin prediction.
        end : int
            The index / observation location at which to end in-sample
            prediction. The maximum value for this is nobs-1.
        out_of_sample : int
            The number of observations to forecast after the end of the sample.
        prediction_index : pd.Index or None
            The index associated with the prediction results. This index covers
            the range [start, end + out_of_sample]. If the model has no given
            index and no given row labels (i.e. endog/exog is not Pandas), then
            this will be None.

        Notes
        -----
        The arguments `start` and `end` behave differently, depending on if
        they are integer or not. If either is an integer, then it is assumed
        to refer to a *location* in the index, not to an index value. On the
        other hand, if it is a date string or some other type of object, then
        it is assumed to refer to an index *value*. In all cases, the returned
        `start` and `end` values refer to index *locations* (so in the former
        case, the given location is validated and returned whereas in the
        latter case a location is found that corresponds to the given index
        value).

        This difference in behavior is necessary to support `RangeIndex`. This
        is because integers for a RangeIndex could refer either to index values
        or to index locations in an ambiguous way (while for `NumericIndex`,
        since we have required them to be full indexes, there is no ambiguity).
        )r0   r/   rU   rV   rW   rX   )r    rn   r_   r   r   r   rX   )rm   r   r   r/   rU   r5   s         r=   _get_prediction_indexz%TimeSeriesModel._get_prediction_index  sN    p 4:#{' 1

 

 

 
	
rs   c                    | j         j        S N)rX   xnames)rm   s    r=   _get_exog_nameszTimeSeriesModel._get_exog_namesQ  s    yrs   c                N    t          |t                    s|g}|| j        _        d S r   )r   listrX   r   )rm   valss     r=   _set_exog_nameszTimeSeriesModel._set_exog_namesT  s+    $%% 	6D	rs   z%The names of the exogenous variables.)NNNrg   )NNr   )NFrH   rI   )__name__
__module____qualname___tsa_doc
_model_doc_generic_params_missing_param_doc__doc__rk   rl   r   r   r   r   r   property
exog_names__classcell__rr   s   @r=   ra   ra     s        !*	  G @F& & & & & &iL iL iL iLV!. !. !. !.F!J !J !J !JFC
 C
 C
 C
 C
J           /	 JJJJJrs   ra   c                        e Zd Zd fd	Z xZS )TimeSeriesModelResults      ?c                h    |j         | _         t                                          ||||           d S r   )rX   rj   rk   )rm   rc   rd   normalized_cov_paramsscalerr   s        r=   rk   zTimeSeriesModelResults.__init__d  s1    J	(=uEEEEErs   )r   )r   r   r   rk   r   r   s   @r=   r   r   c  sG        F F F F F F F F F Frs   r   c                      e Zd Zi Z ej        ej        j        e          ZddiZ	 ej        ej        j
        e	          Z
dS )TimeSeriesResultsWrapperpredictrp   N)r   r   r   _attrswrapunion_dictsbaseLikelihoodResultsWrapper_wrap_attrs_methods_wrap_methods rs   r=   r   r   i  s]        F"$"%16 K 7#H$D$%3X MMMrs   r   )NFFNNr   )0
__future__r   statsmodels.compat.pandasr   r   r   rD   rO   numpyr"   pandasr   r   r	   r
   r   r   r   r   r   r   pandas.tseries.frequenciesr   statsmodels.base.datar   statsmodels.base.modelr   rc   statsmodels.base.wrapperwrapperr   statsmodels.tools.sm_exceptionsr   r   r   _model_params_docr   r   r>   rG   r_   LikelihoodModelra   LikelihoodModelResultsr   ResultsWrapperr   populate_wrapperr   rs   r=   <module>r      s   " " " " " "                                       1 0 0 0 0 0 , , , , , , % % % % % % % % % ' ' ' ' ' ' ' ' ' 8 8 8 8 8 8 +
(, \5 \5 \5~F* F* F*\ 	k7 k7 k7 k7 k7\U U U U Ud* U U UpF F F F FT8 F F F    t2     4    rs   