
    M/Ph                     r    d Z ddlmZ ddlZddlZddZd Zd Z	d Z
dd	Zd
 Zd Zd Zd Zd Zd Zd ZdS )z7
Compatibility tools for various data structure inputs
    )NP_LT_2NMc                 6   ddl m}m} t          | j        ||f          st          d          | j        j        | j        j        }nt          j	        | j                  }|
                    |          s#t          d                    ||                    d S )Nr   )DatetimeIndexPeriodIndexz0The index must be a DatetimeIndex or PeriodIndexzExpected frequency {}. Got {})pandasr   r   
isinstanceindex
ValueErrorfreqfreqstrpd
infer_freq
startswithformat)xr   r   r   inferred_freqs        V/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/statsmodels/tools/data.py_check_period_indexr   
   s    11111111ag{;<< MKLLLw|ag..##D)) P8??@MO O P P 	PP P    c                 6    t          | t          j                  S N)r	   r   	DataFrameobjs    r   is_data_framer      s    c2<(((r   c                 .    ddl m} t          | |          S )Nr   )DesignMatrix)patsyr   r	   )r   r   s     r   is_design_matrixr       s$    """"""c<(((r   c                 R    t          | t          j                  o| j        j        d uS r   )r	   npndarraydtypenamesr   s    r   _is_structured_ndarrayr&   !   s"    c2:&&F39?$+FFr   c                    t          | t          j                  r;t          j        |           }|$d t	          |j        d                   D             }nnt          |           r*|                                 } | j        }| j	        }| j
        }n5t          d                    t          |           j                            t          |t                    st          |          }t!          |          |j        d         k    rt#          d          |/t!          |          t!          |          k    rt#          d          |||fS )aA  
    Convert passed data structure to form required by estimation classes

    Parameters
    ----------
    data : array_like
    colnames : sequence or None
        May be part of data structure
    rownames : sequence or None

    Returns
    -------
    (values, colnames, rownames) : (homogeneous ndarray, list)
    Nc                     g | ]}d |z  S )zY_%d ).0is     r   
<listcomp>z"interpret_data.<locals>.<listcomp>8   s    CCCq
CCCr      zCannot handle input type {typ})typz;length of colnames does not match number of columns in dataz8length of rownames does not match number of rows in data)r	   r"   r#   asarrayrangeshaper   dropnavaluescolumnsr
   	TypeErrorr   type__name__listlenr   )datacolnamesrownamesr3   s       r   interpret_datar=   %   sC    $
## :D!!CCE&,q/,B,BCCCH	t		 :{{}}<:8DJJ$788: : 	: h%% ">> 8}}Q'' . / / 	/ HV < < + , , 	, 8X%%r   c                     |                      t          t          | j        j                  fft
          j                  S )N)r6   )viewfloatr9   r$   r%   r"   r#   )arrs    r   struct_to_ndarrayrB   R   s.    88US11342:8FFFr   c                 v    t          |           t          j        u ot          |          t          j        u p|d u S r   )r6   r"   r#   endogexogs     r   _is_using_ndarray_typerG   V   s5    KK2:% 7$ZZ2:%58r   c                 r    t          | t          j                  ot          |t          j                  p|d u S r   )r	   r"   r#   rD   s     r   _is_using_ndarrayrI   [   s3    ubj)) ;bj))9TT\<r   c                 N    ddl m} t          | |          pt          ||          S )Nr   )data_klasses)statsmodels.compat.pandasrK   r	   )rE   rF   klassess      r   _is_using_pandasrN   `   s3    AAAAAAug&&C*T7*C*CDr   c                 h    	 t          j        |           } t          j        |          }dS #  Y dS xY w)NTF)r"   r/   rD   s     r   _is_array_likerP   e   s:    
5!!z$tuus   (, 1c                 F    t          |           ot          |          p|d u S r   )r    rD   s     r   _is_using_patsyrR   n   s+    U## 5d##3tt|6r   c                     t           rt          | t          j        j                  S t          | t          j        j                  S )z,
    Returns true if data is a recarray
    )r   r	   r"   corerecarrayrec)r:   s    r   _is_recarrayrW   t   s5      1$ 0111$000r   )r   )NN)__doc__statsmodels.compat.numpyr   numpyr"   r   r   r   r   r    r&   r=   rB   rG   rI   rN   rP   rR   rW   r)   r   r   <module>r[      s    - , , , , ,        P P P P) ) )) ) )
G G G*& *& *& *&ZG G G8 8 8
< < <
E E E
  6 6 61 1 1 1 1r   