U
    Kvf                     @   sx   d dl Z d dlZd dlZd dlZd dlmZ d dlm	Z	 d dl
mZ d dlmZ G dd dZdd	 ZG d
d dZdS )    N)assert_equal)summary_col)add_constant)OLSc                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )TestSummaryLatexc                 C   sx   d}dddddg}t |}dddddg}d	dd
ddg}t|| }t|| }t||g }d| }t|| d S Na  
\begin{table}
\caption{}
\label{}
\begin{center}
\begin{tabular}{lll}
\hline
               & y I      & y II      \\
\hline
const          & 7.7500   & 12.4231   \\
               & (1.1058) & (3.1872)  \\
x1             & -0.7500  & -1.5769   \\
               & (0.2368) & (0.6826)  \\
R-squared      & 0.7697   & 0.6401    \\
R-squared Adj. & 0.6930   & 0.5202    \\
\hline
\end{tabular}
\end{center}
\end{table}
\bigskip
Standard errors in parentheses.
                        r      z
%s
)r   r   fitr   as_latexr   selfdesiredxy1y2reg1reg2actual r   I/tmp/pip-unpacked-wheel-2v6byqio/statsmodels/iolib/tests/test_summary2.pytest_summarycol   s    z TestSummaryLatex.test_summarycolc           	      C   s   d}dddddg}t |}dddddg}d	dd
ddg}t|| }t|| }t||gdd }d| }t||gddd}dt|kstdt|kstdt|kstt|| d S )Na/  
==========================
                y I   y II
--------------------------
const          7.7   12.4 
               (1.1) (3.2)
x1             -0.7  -1.6 
               (0.2) (0.7)
R-squared      0.8   0.6  
R-squared Adj. 0.7   0.5  
==========================
Standard errors in
parentheses.
r   r	   r
   r   r   r   r   r   r   r   z%0.1ffloat_formatz%s
T)Zstarsr    z7.7***z12.4**z12.4***)r   r   r   r   Zas_textstrAssertionErrorr   )	r   r   r   r   r   r   r   r   Zstarredr   r   r   test_summarycol_float_format1   s    z-TestSummaryLatex.test_summarycol_float_formatc              
   C   s   dddddg}t |}t|tdgdgdgdgdgggd}d	dd
ddg}dddddg}t|| }t|| }t||gddgdd}dt|kstt||gdgdd}dt|kstdt|kstd S )Nr   r	   r
   r   	   r   r   r   r   r   r   constx1T)regressor_orderZdrop_omittedx2F)	r   npconcatenatearrayr   r   r   r!   r"   )r   r   r)   r   r   r   r   r   r   r   r   test_summarycol_drop_omittedQ   s     *z-TestSummaryLatex.test_summarycol_drop_omittedc              
   C   s
  dddddg}t |}t|tdgdgdgdgdgggd}tj|d	d
dgd}dddddg}dddddg}t|| }t|| }dd dd d}t||gdd }}	t||gdd
gd|d}	d}
t	|
dD ](}|
D ]}||r|t	|	kstqqd S )Nr   r	   r
   r   r$   r%   r   r   r&   ba)columnsr   r   r   r   c                 S   s   d t| jS )Nz{:.3f})formatintZrsquaredr   r   r   r   <lambda>m       zFTestSummaryLatex.test_summary_col_ordering_preserved.<locals>.<lambda>c                 S   s   d t| jS )Nz{0:d})r1   r2   Znobsr3   r   r   r   r4   n   r5   )ZR2Nz%0.4fr   )r(   r    	info_dict)r&   r.   r/   
)r   r*   r+   r,   pdZ	DataFramer   r   r   r!   split
startswithr"   )r   r   r)   r   r   r   r   r7   originalr   	variableslinevariabler   r   r   #test_summary_col_ordering_preservedb   s*    *
z4TestSummaryLatex.test_summary_col_ordering_preservedc                 C   sx   d}dddddg}t |}dddddg}d	dd
ddg}t|| }t|| }t||g }d| }t|| d S r   )r   r   r   r   Z_repr_latex_r   r   r   r   r   test__repr_latex_y   s    z"TestSummaryLatex.test__repr_latex_c              	   C   sx   dddddg}t |}dddddg}t|| }t  td |  }W 5 Q R X d	}||k}|d
ksttd S )Nr   r	   r
   r   r   r   r   ignorez\end{tabular}
\begin{tabular}T)	r   r   r   warningscatch_warningssimplefiltersummaryr   r"   )r   r   r   r   r   Zstring_to_findresultr   r   r   test_OLSsummary   s    

z TestSummaryLatex.test_OLSsummaryN)	__name__
__module____qualname__r   r#   r-   r@   rA   rH   r   r   r   r   r      s   " "r   c               	   C   s   ddddddddg} ddddddd	dg}t |t|  }d
}tt |t| ks^tW 5 Q R X tt |t|	 kstW 5 Q R X t || dd }d}tt |t| kstW 5 Q R X tt |t|	 kstW 5 Q R X d S )Nr   r	   r
   r   r   r   r   r$   
   z
R-squared:F)hasconstzR-squared (uncentered):)
r   r   r   pytestZwarnsUserWarningr!   Zsummary2r"   rF   )r   yZreg_with_constantZr2_strZreg_without_constantr   r   r   test_ols_summary_rsquared_label   s    rQ   c                   @   s,   e Zd ZdZedd Zdd Zdd ZdS )	TestSummaryLabelsz@
    Test that the labels are correctly set in the summary tablec                 C   s:   ddddgd }t ddddgd }t||d | _d S )Nr   r   r   r   )ZendogZexog)r   r   r   mod)clsrP   r   r   r   r   setup_class   s    zTestSummaryLabels.setup_classc                 C   s2   t | jdd}dt|kstdt|ks.td S )NTresultsZ
include_r2zR-squared  R-squared Adj.r   rS   r!   r"   r   tabler   r   r   test_summary_col_r2   s    z%TestSummaryLabels.test_summary_col_r2c                 C   s2   t | jdd}dt|kstdt|ks.td S )NFrV   z	R-squaredrX   rY   rZ   r   r   r   test_absence_of_r2   s    z$TestSummaryLabels.test_absence_of_r2N)rI   rJ   rK   __doc__classmethodrU   r\   r]   r   r   r   r   rR      s
   
rR   )rC   Znumpyr*   Zpandasr9   rN   Znumpy.testingr   Zstatsmodels.iolib.summary2r   Zstatsmodels.tools.toolsr   Z#statsmodels.regression.linear_modelr   r   rQ   rR   r   r   r   r   <module>   s     