o
    0Gf                     @   s   d Z ddlmZ ddlZddlZdddZdd Zd	d
 Z	dd Z
dddZdd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )z7
Compatibility tools for various data structure inputs
    )NP_LT_2NMc                 C   sh   ddl m}m} t| j||fstd| jjd ur| jj}nt	| j}|
|s2td||d S )Nr   )DatetimeIndexPeriodIndexz0The index must be a DatetimeIndex or PeriodIndexzExpected frequency {}. Got {})pandasr   r   
isinstanceindex
ValueErrorfreqZfreqstrpdZ
infer_freq
startswithformat)xr
   r   r   Zinferred_freq r   6lib/python3.10/site-packages/statsmodels/tools/data.py_check_period_index
   s   

r   c                 C   s   t | tjS N)r   r   Z	DataFrameobjr   r   r   is_data_frame   s   r   c                 C   s   ddl m} t| |S )Nr   )DesignMatrix)Zpatsyr   r   )r   r   r   r   r   is_design_matrix   s   
r   c                 C   s   t | tjo| jjd uS r   )r   npndarraydtypenamesr   r   r   r   _is_structured_ndarray!   s   r   c                 C   s   t | tjrt| }|du rdd t|jd D }nt| r.|  } | j}| j	}| j
}ntdjt| jdt |tsBt|}t||jd krOtd|dur_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                 S   s   g | ]}d | qS )zY_%dr   ).0ir   r   r   
<listcomp>8   s    z"interpret_data.<locals>.<listcomp>   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   Zdropnavaluescolumnsr   	TypeErrorr   type__name__listlenr	   )dataZcolnamesZrownamesr%   r   r   r   interpret_data%   s(   



r-   c                 C   s   | j tt| jjfftjdS )N)r(   )viewfloatr+   r   r   r   r   )Zarrr   r   r   struct_to_ndarrayR   s   r0   c                 C   s$   t | tju ot |tju p|d u S r   )r(   r   r   endogexogr   r   r   _is_using_ndarray_typeV   s   r4   c                 C   s    t | tjot |tjp|d u S r   )r   r   r   r1   r   r   r   _is_using_ndarray[   s   r5   c                 C   s    ddl m} t| |pt||S )Nr   )data_klasses)Zstatsmodels.compat.pandasr6   r   )r2   r3   Zklassesr   r   r   _is_using_pandas`   s   r7   c                 C   s(   zt | } t |}W dS    Y dS )NTF)r   r"   r1   r   r   r   _is_array_likee   s   

r8   c                 C   s   t | ot |p|d u S r   )r   r1   r   r   r   _is_using_patsyn   s   r9   c                 C   s    t r	t| tjjS t| tjjS )z,
    Returns true if data is a recarray
    )r   r   r   coreZrecarrayZrec)r,   r   r   r   _is_recarrayt   s   r;   )r   )NN)__doc__Zstatsmodels.compat.numpyr   Znumpyr   r   r   r   r   r   r   r-   r0   r4   r5   r7   r8   r9   r;   r   r   r   r   <module>   s     

-	