
    M/Ph-,              	       |   d dl mZ d dlmZmZ d dlZd dlmZ d dlZd dl	Z
d dlmZmZ d dlZd dlZd dlmZmZ d dlmZmZmZmZmZmZmZmZ d dlmZ d d	l m!Z! d d
l"m#Z# 	 d dl$m%Z& n# e'$ r Y nw xY wej(        j$        d             Z)ej(        j$        d             Z*ej(        j$        d             Z+ej(        j$        d             Z,ej(        j$        d             Z-ej(        j$        d             Z.ej(        j$        d             Z/ej(        j$        d             Z0ej(        j$        d             Z1ej(        2                    ed          ej(        j$        d                         Z3ej(        j$        d             Z4ej(        j$        d             Z5ej(        j$        ej(        6                    de! e7dd          fe# e7d          fg          ej(        6                    d d!dg          ej(        6                    d"dd#g          d$                                                 Z8ej(        j$        d%             Z9dS )&    )	MONTH_END)PYTHON_IMPL_WASMlmapN)BytesIO)assert_assert_equal)elnino	macrodata)
month_plotplot_accf_gridplot_acfplot_ccf	plot_pacfplot_predictquarter_plotseasonal_plot)arima_process)AutoReg)ARIMA)pyplotc                    t          j                    }|                    d          }t          j        d         }t          j        d         }t          j        ||          }t          j                            d          }|	                    d|j
                  }t          ||d           t          ||	           t          ||d 
           d S )No         ?g쿩r   ?  d   distrvs
   axlagsr#   r#   alpha)pltfigureadd_subplotnpr_tspArmaProcessrandomRandomStategenerate_samplestandard_normalr   close_figuresfigr#   armaarmaprocessrsacfs           h/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/statsmodels/graphics/tests/test_tsaplots.pytest_plot_acfr<   "   s     *,,C			B	y	B	xB/"b))K			t	$	$B

%
%c23E
%
F
FCSRb!!!!SRSRt$$$$$$    c                    t          j                    }|                    d          }t          j        d         }t          j        d         }t          j        ||          }t          j                            d          }|	                    d|j
                  }t          ||t          j        dd          	           t          ||d
d           t          ||d d           d S Nr   r   r   r   r   r         r"   r!   F)r#   r$   zero)r#   r'   rB   )r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r   aranger3   s           r;   test_plot_acf_irregularrD   2   s     *,,C			B	y	B	xB/"b))K			t	$	$B

%
%c23E
%
F
FCSRbi2..////SRbu----SRt%000000r=   c                    t          j                    }|                    d          }t          j        d         }t          j        d         }t          j        ||          }t          j                            d          }|	                    d|j
                  }t          ||           t          ||d            d S )	Nr   r   r   r   r   r   r%   r&   )r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r   r4   r5   r#   r6   r7   r8   r9   pacfs           r;   test_plot_pacfrH   B   s     *,,C			B	y	B	xB/"b))K			t	$	$B&&sB4F&GGDdrdr&&&&&&r=   c                    t          j                    }|                    d          }t          j        d         }t          j        d         }t          j        ||          }t          j                            d          }|	                    d|j
                  }t                      }t          ||           |                    |d	           t                      }	t          j                    }
|
                    d          }t          ||d
           |
                    |	d	           t                      }t          j                    }|                    d          }ddi}t          |||           |                    |d	           |                    d           |	                    d           |                    d           |                                }|	                                }|                                }t!          ||k               t!          ||k               t!          ||k               d S )Nr   r   r   r   r   r   r%   rgbaformat-)r#   ls
linestylesdashdotr#   vlines_kwargsr   )r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r   r   savefigseekreadr   )r4   r5   r#   r6   r7   r8   r9   rG   buffbuff_linestylefig_linestylebuff_with_vlinesfig_with_vlinesrR   plain	linestylewith_vliness                    r;   test_plot_pacf_kwargsr^   Q   s    *,,C			B	y	B	xB/"b))K			t	$	$B&&sB4F&GGD99DdrKKVK$$$YYNJLLM		"	"3	'	'Bdrc"""".888yyjllO		$	$S	)	)B!9-Mdr7777,V<<<IIaLLL!IIKKE##%%I"''))KEYK5 !!!I$%%%%%r=   c                 :   t          j                    }|                    d          }t          j        d         }t          j        d         }t          j        ||          }t          j                            d          }|	                    d|j
                  }t                      }t          ||           |                    |d	           t                      }	t          j                    }
|
                    d          }d
di}t          |||           |
                    |	d	           |                    d           |	                    d           |                                }|	                                }t!          ||k               d S )Nr   r   r   r   r   r   r%   rJ   rK   rO   rP   rQ   r   )r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r   r   rS   rT   rU   r   )r4   r5   r#   r6   r7   r8   r9   r:   rV   rY   rZ   rR   r[   r]   s                 r;   test_plot_acf_kwargsr`   z   se    *,,C			B	y	B	xB/"b))K			t	$	$B

%
%c23E
%
F
FC99DSRKKVK$$$yyjllO		$	$S	)	)B!9-MSR}5555,V<<<IIaLLL!IIKKE"''))KK5 !!!!!r=   c                 P   t          j                    }|                    d          }t          j        d         }t          j        d         }t          j        ||          }t          j                            d          }|	                    d|j
                  }t          j        |d d d<   t                      }t          ||d	           |                    |d
           |                    d           t          j                    }|                    d          }t                      }	t          ||d	           |                    |	d
           |	                    d           t!          |                                |	                                k               d S )Nr   r   r   r   r   r      drop)r#   missingrJ   rK   r   conservative)r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   nanr   r   rS   rT   r   rU   )
r4   r5   r#   r6   r7   r8   r9   r:   rV   buff_conservatives
             r;   test_plot_acf_missingrh      s`    *,,C			B	y	B	xB/"b))K			t	$	$B

%
%c23E
%
F
FCC"I99DSR((((KKVK$$$IIaLLL
*,,C			B		SR0000KK!&K1111DIIKK,1133344444r=   c                    t          j                    }|                    d          }t          j        d         }t          j        d         }t          j        ||          }t          j                            d          }|	                    d|j
                  }t          ||t          j        dd          	           t          ||d
d           t          ||d d           d S r?   )r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r   rC   rF   s           r;   test_plot_pacf_irregularrj      s     *,,C			B	y	B	xB/"b))K			t	$	$B&&sB4F&GGDdr	!R 0 01111dr////drE222222r=   c                    t          j                    }|                    d          }t          j        d         }t          j        d         }t          j        ||          }t          j                            d          }|	                    d|j
                  }|	                    d|j
                  }t          ||           t          |||d           t          |||	           t          |||d 
           t          |||d           t          |||d           t          |||d           t          |||d           t          |||d           t          |||d           d S )Nr   r   r   r   r   r   r!   r"   r%   r&   T)r#   negative_lags)r#   adjusted)r#   fftCCF)r#   title)r#   
auto_ylimsF)r#   
use_vlines)r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r   )	r4   r5   r#   r6   r7   r8   r9   x1x2s	            r;   test_plot_ccfru      sv    *,,C			B	y	B	xB/"b))K			t	$	$B		$	$S"2D	$	E	EB		$	$S"2D	$	E	EBRR$$$$RR$''''R$////RT****R%%%%R%((((Rt,,,,Ru------r=   c                 &   t          j                    }t          j        d         }t          j        d         }t	          j        ||          }t          j                            d          }t          j        |	                    d|j
                  |	                    d|j
                  g          j        }t          |           t          t          j        |d d df         |d d df         d                     t          ||d	
           t          ||           t          ||d           t          ||d            t          ||d           t          ||d           t          ||d           t          ||d           d S )Nr   r   r   r   r   r   r@   )xyr!   )r5   r$   )r5   F)r5   rl   )r5   r'   T)r5   rm   )r5   rn   )r5   rq   )r5   rr   )r(   r)   r+   r,   r-   r.   r/   r0   vstackr1   r2   Tr   pd	DataFrame)r4   r5   r6   r7   r8   r9   rw   s          r;   test_plot_accf_gridr}      s    *,,C	y	B	xB/"b))K			t	$	$B
	##C1C#DD##C1C#DD 	 	 	  12<a1gAaaadG < <==>>>1#B''''1#1#U33331#T****1#----1#4((((1#$////1#%000000r=   z)Matplotlib uses different backend in WASMreasonc                    t          j                    j        }|j                            t
                                        t                    |d<   |                    d          j	        
                                }t          j        d |j        j        D             d          }t          |j        |d          }t          j        |          |_        t          |          }t          j        |d          |_        t          |          }t          j        |d	          |_        t          |          }	 t%          j        d
          5  t          |          }d |j        d                                         D             }g d}t-          ||          D ])\  }}t/          |t0                    r||v sJ !||k    sJ *	 d d d            d S # 1 swxY w Y   d S # t2          j        $ r t7          j        d           Y d S w xY w)NYEARc                 T    g | ]%}d                      |d         |d         g          &S )rM   r@   r   )join).0rw   s     r;   
<listcomp>z#test_plot_month.<locals>.<listcomp>   s0    :::A1Q41,		:::r=   z%b-%YrK   zel nino)datesylabelMSfreqMDE_dec                 6    g | ]}|                                 S  get_text)r   _s     r;   r   z#test_plot_month.<locals>.<listcomp>  s     JJJqajjllJJJr=   r   )JanFeb)u   MärMrzAprMaiJunJulAugSepOktNovDezz!Failure due to unsupported localer~   )r	   load_pandasdatar   astypeintapplystr	set_indexrz   unstackr{   to_datetimeindexvaluesr   DatetimeIndexPeriodIndexcalendardifferent_localeaxesget_xticklabelszip
isinstancetuplelocaleErrorpytestxfail)r4   dtar   r5   labelsexpectedlblexps           r;   test_plot_monthr      sV    



#C(//#&&,,S11CK
--


!
)
)
+
+CN::)9:::7  E
 SZuY
?
?
?C  ''CI
S//C  T222CI
S//C u3///CI
S//CA&w// 	& 	&S//CJJCHQK,G,G,I,IJJJF  H  11 & &Sc5)) &#:::::#:::::	&#	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&, < A A A?@@@@@@@As7   =G# A7G	G# GG# GG# #$H
Hc           	         t          j                    j        }t          dj        t          |j                            t                    	                    t                    |j                            t                    	                    t                                        }t          |j        j        |           |                    t!          j        |d          d           t          |j                   t!          j        |d          |_        t          |j                   t!          j        |d          |_        t          |j                   d S )Nz-QzQS-OCTr   T)inplaceQ)r
   r   r   r   r   r   yearr   r   r   r   quarterr   unempr   r   r{   r   r   r   )r4   r   r   s      r;   test_plot_quarterr   -  s   


!
!
&C	HOOC  &&s++S[-?-?-D-D-J-J3-O-O	
 	
 E !5))) MM""5x888$MGGG  X666CI u3///CIr=   c                    t           j                            d          }|                    dd          }|dt          j        t          j        d          dz  t           j        z            d d d f         z  z  }|                                }t          j        t          j        dd          d	          }|                                }t          j
        ||gd
dg          j        }|                    d          d
         }g d}t          ||          }|                                d         }d |                                D             }	t!          ||	           d S )Nr            g      (@rA   r@   rb   )r   r@   r   monthsr   )r   r   Marr   Mayr   r   r   r   Octr   Decr   c                 6    g | ]}|                                 S r   r   )r   tls     r;   r   z&test_seasonal_plot.<locals>.<listcomp>a  s     ;;;bkkmm;;;r=   )r+   r/   r0   randnsinrC   piraveltiler{   r|   rz   groupbyr   get_axesr   r   )
r4   r9   r   r   dfgroupedr   r5   r#   outputs
             r;   test_seasonal_plotr   G  s:   			t	$	$B88BDAry+be344T111W===D::<<DWRYq"%%w//F\\^^F	tVnVX,>	?	?	?	ABjj""6*G  F 
(
(C		B;;b&8&8&:&:;;;F     r=   model_and_args   F)r$   	old_names)r   r   r   )order
use_pandasTr'   g?c           	         |\  }}t           j                            d          }|                    d          }t	          dd          D ]-}||xx         d||dz
           z  d||dz
           z  z
  z  cc<   .|dd          }| rgt          j        dt          |j        d         d	z   
          }||j        d         dz           }	|d         }
t          j	        ||d d                   }n |j        d         dz  }	|j        d         d	z   }
 ||fi |
                                }t          ||	|
|          }t          |t          j                  sJ d S )Nr   i  r   g?r@   r   r   z1960-1-1   )r   periodsir   )r'   )r+   r/   r0   r2   ranger{   
date_ranger   shapeSeriesfitr   r   r(   Figure)r   r   r'   modelkwargsr9   rx   ir   startendresr5   s                r;   test_predict_plotr   e  sp    #ME6			q	!	!B
4  A1d^^ 0 0	!aAhqQx//	#$$A 	Y
R
 
 
 ek!n)*BiIauTcT{+++
agaj2o
%

V


 
 
"
"C
sE3e
4
4
4Cc3:&&&&&&&r=   c            	          d t          d          D             } t          j        | dgt          t          d                              }t	          |           d S )Nc                 v    g | ]6}t           j                                        t          j        |           z   7S ))seconds)r{   	Timestampnow	Timedelta)r   r   s     r;   r   z/test_plot_pacf_small_sample.<locals>.<listcomp>  s8    
K
K
KA2<Q 7 7 77
K
K
Kr=   r!   a)r   columnsr   )r   r{   r|   listr   )idxr   s     r;   test_plot_pacf_small_sampler     sY    
K
Kr
K
K
KC	%))__
 
 
B
 bMMMMMr=   ):statsmodels.compat.pandasr   statsmodels.compat.pythonr   r   r   ior   r   numpyr+   numpy.testingr   r   pandasr{   r   statsmodels.datasetsr	   r
   statsmodels.graphics.tsaplotsr   r   r   r   r   r   r   r   statsmodels.tsar   r-   statsmodels.tsa.ar_modelr   statsmodels.tsa.arima.modelr   
matplotlibr   r(   ImportErrormarkr<   rD   rH   r^   r`   rh   rj   ru   r}   skipifr   r   r   parametrizedictr   r   r   r=   r;   <module>r     s   / / / / / / < < < < < < < <             / / / / / / / /      2 2 2 2 2 2 2 2	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 1 0 0 0 0 0 , , , , , , - - - - - -	((((((( 	 	 	D	 % % % 1 1 1 ' ' ' %& %& %&P " " "< 5 5 54 3 3 3 . . .. 1 1 10 6    0A 0A 	 
0Af   2 ! ! !: tte,,,-tt)7L7L7L/MN  e}554,//' ' 0/ 65	  ',     s    A' 'A/.A/