U
    Kvfi                     @   s$   d Z ddlZdddZd	ddZdS )
z4
SARIMAX tools.

Author: Chad Fulton
License: BSD-3
    Nc                 C   s  t | } |dkrdnd| }t | | tksBtd|| f | t} t | dk rftd| | jdkr| jd dkr| dddf } n| jdkrtd	|| f | jdkr| 	 } nt
| dkrd} nd| k}t | dkdk}t | dk}|s|r.|rtd
| t | dkd d } n
t | } t
| dkrLd} n2t | t dt
| d krv| d } n|  } t| tot t | dk}|rtd| | S )a+  
    Standardize lag order input.

    Parameters
    ----------
    order : int or array_like
        Maximum lag order (if integer) or iterable of specific lag orders.
    title : str, optional
        Description of the order (e.g. "autoregressive") to use in error
        messages.

    Returns
    -------
    order : int or list of int
        Maximum lag order if consecutive lag orders were specified, otherwise
        a list of integer lag orders.

    Notes
    -----
    It is ambiguous if order=[1] is meant to be a boolean list or
    a list of lag orders to include, but this is irrelevant because either
    interpretation gives the same result.

    Order=[0] would be ambiguous, except that 0 is not a valid lag
    order to include, so there is no harm in interpreting as a boolean
    list, in which case it is the same as order=0, which seems like
    reasonable behavior.

    Examples
    --------
    >>> standardize_lag_order(3)
    3
    >>> standardize_lag_order(np.arange(1, 4))
    3
    >>> standardize_lag_order([1, 3])
    [1, 3]
    Norderz%s orderz)Invalid %s. Non-integer order (%s) given.r   z#Terms in the %s cannot be negative.      zeInvalid %s. Must be an integer or 1-dimensional array-like object (e.g. list, ndarray, etc.). Got %s.zInvalid %s. Appears to be a boolean list (since it contains a 0 element and/or multiple elements) but also contains elements greater than 1 like a list of lag orders.z+Invalid %s. Cannot have duplicate elements.)nparrayallZastypeint
ValueErroranyndimshapeitemlensumwheresortZarangetolist
isinstancelistZdiff)r   titleZ	has_zerosZhas_multiple_onesZ
has_gt_oneZhas_duplicate r   ?/tmp/pip-unpacked-wheel-2v6byqio/statsmodels/tsa/arima/tools.pystandardize_lag_order
   sL    &





 
 r   Fc                 C   s   |dkrdnd| }zBt j| td} dd |  D }t|rBtnt}t j| |d} W n  tk
rv   td| Y nX |st t 	| st t 
| rtd| t t | } | j|fkr|d	krdnd
}td|||| jf | S )a  
    Validate parameter vector for basic correctness.

    Parameters
    ----------
    params : array_like
        Array of parameters to validate.
    length : int
        Expected length of the parameter vector.
    allow_infnan : bool, optional
            Whether or not to allow `params` to contain -np.Inf, np.Inf, and
            np.nan. Default is False.
    title : str, optional
        Description of the parameters (e.g. "autoregressive") to use in error
        messages.

    Returns
    -------
    params : ndarray
        Array of validated parameters.

    Notes
    -----
    Basic check that the parameters are numeric and that they are the right
    shape. Optionally checks for NaN / infinite values.
    N z for %s)dtypec                 S   s   g | ]}t |tqS r   )r   complex).0pr   r   r   
<listcomp>   s     z"validate_basic.<locals>.<listcomp>z,Parameters vector%s includes invalid values.z/Parameters vector%s includes NaN or Inf values.r   szOSpecification%s implies %d parameter%s, but values with shape %s were provided.)r   r   objectZravelr   r   float	TypeErrorr
   isnanisinfZ
atleast_1dZsqueezer   )paramslengthZallow_infnanr   Z
is_complexr   pluralr   r   r   validate_basico   s.    r)   )N)FN)__doc__Znumpyr   r   r)   r   r   r   r   <module>   s   
e