U
    Kvf                  	   @   sx  d dl mZ d dlmZmZ d dlZd dlZd dlm	Z	 ej
dddd Zej
ddd	d
 Zej
dddd Zdd Zdd Zejjdedddfedddfedddfgdgddd Zejdddgdd Zejjded fedfed!fed"fgdgdd#d$ Zd%d& Zd'd( Zejjd)d* Zd+d, Zejjd-ed.d/d0d1fed2d/d3d1fed.dd0dfgdgdd4d5 ZdS )6    )Path)assert_allcloseassert_equalN)MSTLfunction)Zscopec                  C   s    t tj } | d }t|S )Nzresults/mstl_test_results.csvr   __file__parentresolvepdZread_csvZcur_dir	file_path r   G/tmp/pip-unpacked-wheel-2v6byqio/statsmodels/tsa/stl/tests/test_mstl.pymstl_results
   s    r   c                  C   s*   t tj } | d }tj|dgdgdS )Nzresults/mstl_elec_vic.csvZds)Z	index_colZparse_datesr   r   r   r   r   data_pd   s    r   c                 C   s
   | d j S )Ny)values)r   r   r   r   data   s    r   c                 C   s`   t | dd}| }t|jtjs&tt|jtjs8tt|jtjsJtt|j	tjs\td S N   endogperiods)
r   fit
isinstancetrendr   ZSeriesAssertionErrorseasonalresidweightsr   modresr   r   r   ?test_return_pandas_series_when_input_pandas_and_len_periods_one   s    r$   c                 C   s*   t | dd}| }t|jtjs&td S )N   r   r   )r   r   r   r   r   Z	DataFramer   r!   r   r   r   @test_seasonal_is_datafame_when_input_pandas_and_multiple_periods&   s    r'   z data, periods, windows, expectedr&      )r&         )r&   r)   g    .A)Zindirectc                 C   sF   t | ||d}| }|jjdkr.|jjd n|jj}||ksBtd S )Nr   r   windowsr(   )r   r   r   ndimshaper   )r   r   r,   expectedr"   r#   Zn_seasonal_componentsr   r   r   "test_number_of_seasonal_components,   s
    
r0   zperiods, windows)r%   r(   )   r%   c              	   C   s6   t jtdd tdddddg| |d W 5 Q R X d S )	Nz)Periods and windows must have same length)matchr(   r*   r&      r   r+   )pytestZraises
ValueErrorr   )r   r,   r   r   r   <test_raise_value_error_when_periods_and_windows_diff_lengths>   s
     r6   zdata, lmbdag?g      autoc                 C   s   d}t | ||d}|  d S )Nr   r)   r1   r   r   lmbdar   r   )r   r:   r   r"   r   r   r   test_fit_with_box_coxK   s    r<   c                 C   s<   d}t | |dd}|  t|ds(tt|jts8td S )Nr8   r7   r9   	est_lmbda)r   r   hasattrr   r   r=   float)r   r   r"   r   r   r   test_auto_fit_with_box_coxV   s
    r@   c                 C   s@   dddddddddddddd	}d
}t | |d|d}|  d S )N         r   r(   r*   r&   F)Zperiodr   r   Zlow_passseasonal_deg	trend_deglow_pass_degseasonal_jump
trend_jumplow_pass_jumpZrobust
inner_iter
outer_iterr8   r7   )r   r   r:   
stl_kwargsr;   )r   rL   r   r"   r   r   r   test_stl_kwargs_smoke^   s,       rM   c                 C   s<   t | dd}| }|  t |dd}| }|  d S r   )r   r   Zplot)r   r   Zclose_figuresr"   r#   r   r   r   	test_plotu   s    rN   c                 C   s   t | ddddddddddd}| }|d }|d }|d	d
g }|d }t|j| t|j| t|j| t|j| d S )N)      r   r(   r*   )rD   rG   rH   rE   rI   rF   rJ   rK   )r   r   rL   DataZTrendZ
Seasonal24ZSeasonal168Z	Remainder)r   r   r   observedr   r   r   )r   r   r"   r#   Zexpected_observedZexpected_trendZexpected_seasonalZexpected_residr   r   r   'test_output_similar_to_R_implementation   s,    rS   zPdata, periods_ordered, windows_ordered, periods_not_ordered, windows_not_ordered)rA   rO   rP   )   rB      )rA   rP   rO   )rT   rU   rB   )rA   rO       A)rA   rV   rO   c           	      C   sh   t | ||d}| }t | ||d}| }t|j|j t|j|j t|j|j t|j|j d S )Nr+   )r   r   r   rR   r   r   r   )	r   Zperiods_orderedZwindows_orderedZperiods_not_orderedZwindows_not_orderedZmod1Zres1Zmod2Zres2r   r   r   %test_output_invariant_to_period_order   s      rW   )pathlibr   Znumpy.testingr   r   Zpandasr   r4   Zstatsmodels.tsa.seasonalr   Zfixturer   r   r   r$   r'   markZparametrizer0   r6   r<   r@   rM   Z
matplotlibrN   rS   rW   r   r   r   r   <module>   sf   





	


	
	
	


