U
    Ãmœd9  ã                   @   s|   d 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
é    NÚMc                 C   sh   ddl m}m} t| j||fƒs(tdƒ‚| jjd k	r>| jj}nt 	| j¡}| 
|¡sdtd ||¡ƒ‚d S )Nr   )ÚPeriodIndexÚDatetimeIndexz0The 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   úO/home/sam/Atlas/atlas_env/lib/python3.8/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 k	S r   )r   ÚnpÚndarrayÚdtypeÚnamesr   r   r   r   Ú_is_structured_ndarray   s    r   c                 C   sÈ   t | tjƒr8t | ¡}|dkrrdd„ t|jd ƒD ƒ}n:t| ƒr\|  ¡ } | j}| j	}| j
}ntdjt| ƒjd�ƒ‚t |tƒs„t|ƒ}t|ƒ|jd kržtdƒ‚|dk	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>6   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_ndarrayP   s    r/   c                 C   s$   t | ƒtjko"t |ƒtjkp"|d kS r   )r'   r   r   ©ÚendogÚexogr   r   r   Ú_is_using_ndarray_typeT   s    ÿr3   c                 C   s    t | tjƒot |tjƒp|d kS r   )r   r   r   r0   r   r   r   Ú_is_using_ndarrayY   s    ÿr4   c                 C   s    ddl m} t| |ƒpt||ƒS )Nr   )Údata_klasses)Zstatsmodels.compat.pandasr5   r   )r1   r2   Zklassesr   r   r   Ú_is_using_pandas^   s    r6   c                 C   s.   zt  | ¡} t  |¡}W dS    Y dS X d S )NTF)r   r!   r0   r   r   r   Ú_is_array_likec   s    

r7   c                 C   s   t | ƒot |ƒp|d kS r   )r   r0   r   r   r   Ú_is_using_patsyl   s    ÿr8   c                 C   s   t | tjjƒS )z,
    Returns true if data is a recarray
    )r   r   ÚcoreZrecarray)r+   r   r   r   Ú_is_recarrayr   s    r:   )r   )NN)Ú__doc__Únumpyr   r   r
   r   r   r   r   r,   r/   r3   r4   r6   r7   r8   r:   r   r   r   r   Ú<module>   s   

-	