U
    Ãmœd‹	  ã                   @   st   d Z ddlmZ ddlmZ ddlZddlmZ ddddgZ	d	d
„ Z
e
de	ƒZe
de	ƒZG dd„ dƒZddd„ZdS )z0assert functions from numpy and pandas testing

é    )ÚtestingN©ÚBunchÚparamsZbseZtvaluesZpvaluesc                    s   G ‡ ‡‡fdd„dt ƒ‰ ˆ S )a­  
    Generates a special purpose Bunch class

    Parameters
    ----------
    attribute: str
        Attribute to access when splitting
    columns: List[str]
        List of names to use when splitting the columns of attribute

    Notes
    -----
    After the class is initialized as a Bunch, the columne of attribute
    are split so that Bunch has the keys in columns and
    bunch[column[i]] = bunch[attribute][:, i]
    c                       s"   e Zd Z‡‡ ‡‡fdd„Z‡  ZS )z#bunch_factory.<locals>.FactoryBunchc                    sZ   t ˆ | ƒj||Ž t| ˆƒs*td ˆ¡ƒ‚tˆƒD ]"\}}t| ˆƒd d …|f | |< q2d S )Nz5{0} is required and must be passed to the constructor)ÚsuperÚ__init__ÚhasattrÚAttributeErrorÚformatÚ	enumerateÚgetattr)ÚselfÚargsÚkwargsÚiZatt)ÚFactoryBunchÚ	__class__Ú	attributeÚcolumns© úR/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/statsmodels/tools/testing.pyr   !   s    
ÿz,bunch_factory.<locals>.FactoryBunch.__init__)Ú__name__Ú
__module__Ú__qualname__r   Ú__classcell__r   ©r   r   r   )r   r   r       s   r   r   )r   r   r   r   r   Úbunch_factory   s    	r   Zparams_tableZmargins_tablec                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚHolderzF
    Test-focused class to simplify accessing values by attribute
    c                 K   s   | j  |¡ d S )N)Ú__dict__Úupdate)r   Úkwdsr   r   r   r   5   s    zHolder.__init__c                 C   s    d  dd„ t| ƒ ¡ D ƒ¡}|S )NÚ
c                 s   s.   | ]&\}}t |ƒd  t |ƒ dd¡ V  qdS ©z = r!   z
    N)ÚstrÚreplace©Ú.0ÚkÚvr   r   r   Ú	<genexpr>9   s   ÿz!Holder.__str__.<locals>.<genexpr>)ÚjoinÚvarsÚitems©r   Ússr   r   r   Ú__str__8   s    

ÿzHolder.__str__c                 C   s2   d  dd„ t| ƒ ¡ D ƒ¡}t| jƒd | }|S )Nr!   c                 s   s.   | ]&\}}t |ƒd  t|ƒ dd¡ V  qdS r"   )r#   Úreprr$   r%   r   r   r   r)   ?   s   ÿz"Holder.__repr__.<locals>.<genexpr>)r*   r+   r,   r#   r   r-   r   r   r   Ú__repr__=   s
    

ÿzHolder.__repr__N)r   r   r   Ú__doc__r   r/   r1   r   r   r   r   r   1   s   r   Ú Tc                 K   sl   t |tjƒrt | |¡ nNt |tjƒr8tj| |f|Ž n0t |tjƒrVtj| |f|Ž nt	j
| |ddd� d S )Nr3   T)Úerr_msgÚverbose)Ú
isinstanceÚpandasÚIndexÚpdtZassert_index_equalZSeriesZassert_series_equalZ	DataFrameZassert_frame_equalÚnptÚassert_equal)ÚactualZdesiredr4   r5   r    r   r   r   r;   G   s    r;   )r3   T)r2   Zstatsmodels.compat.pandasr   r9   Znumpy.testingr:   r7   Zstatsmodels.tools.toolsr   Z
PARAM_LISTr   ZParamsTableTestBunchZMarginTableTestBunchr   r;   r   r   r   r   Ú<module>   s   

