
    !g+              	          d dl mZ d dl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% ejN                  jF                  d        Z(ejN                  jF                  d        Z)ejN                  jF                  d        Z*ejN                  jF                  d        Z+ejN                  jF                  d        Z,ejN                  jF                  d        Z-ejN                  jF                  d        Z.ejN                  jF                  d        Z/ejN                  jF                  d        Z0ejN                  jF                  d        Z1ejN                  jF                  d        Z2ejN                  jF                  d        Z3ejN                  jF                  ejN                  ji                  de  e5dd      fe" e5d      fg      ejN                  ji                  dddg      ejN                  ji                  d dd!g      d"                             Z6ejN                  jF                  d#        Z7y# e&$ r Y w xY w)$    )	MONTH_END)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                         }|j                  d      }t        j                  d   }t        j                  d   }t        j                  ||      }t        j                  j                  d      }|j                  d|j                        }t        ||d       t        ||	       t        ||d 
       y )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           e/var/www/dash_apps/app1/venv/lib/python3.12/site-packages/statsmodels/graphics/tests/test_tsaplots.pytest_plot_acfr;   "   s     **,C		B	y	B	xB//"b)K			t	$B

%
%c23E3E
%
FCSRb!SRSRt$    c                    t        j                         }|j                  d      }t        j                  d   }t        j                  d   }t        j                  ||      }t        j                  j                  d      }|j                  d|j                        }t        ||t        j                  dd      	       t        ||d
d       t        ||d d       y Nr   r   r   r   r   r         r!   r    F)r"   r#   zero)r"   r&   rA   )r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r   aranger2   s           r:   test_plot_acf_irregularrC   2   s     **,C		B	y	B	xB//"b)K			t	$B

%
%c23E3E
%
FCSRbii2./SRbu-SRt%0r<   c                 t   t        j                         }|j                  d      }t        j                  d   }t        j                  d   }t        j                  ||      }t        j                  j                  d      }|j                  d|j                        }t        ||       t        ||d        y )	Nr   r   r   r   r   r   r$   r%   )r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r   r3   r4   r"   r5   r6   r7   r8   pacfs           r:   test_plot_pacfrG   B   s     **,C		B	y	B	xB//"b)K			t	$B&&sB4F4F&GDdrdr&r<   c                    t        j                         }|j                  d      }t        j                  d   }t        j                  d   }t        j                  ||      }t        j                  j                  d      }|j                  d|j                        }t               }t        ||       |j                  |d	       t               }	t        j                         }
|
j                  d      }t        ||d
       |
j                  |	d	       t               }t        j                         }|j                  d      }ddi}t        |||       |j                  |d	       |j                  d       |	j                  d       |j                  d       |j                         }|	j                         }|j                         }t!        ||k7         t!        ||k7         t!        ||k7         y )Nr   r   r   r   r   r   r$   rgbaformat-)r"   ls
linestylesdashdotr"   vlines_kwargsr   )r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r   r   savefigseekreadr   )r3   r4   r"   r5   r6   r7   r8   rF   buffbuff_linestylefig_linestylebuff_with_vlinesfig_with_vlinesrQ   plain	linestylewith_vliness                    r:   test_plot_pacf_kwargsr]   Q   s    **,C		B	y	B	xB//"b)K			t	$B&&sB4F4F&GD9DdrKKVK$YNJJLM		"	"3	'Bdrc".8yjjlO		$	$S	)B!9-Mdr7,V<IIaL!IIKE##%I"'')KEYK5 !I$%r<   c                    t        j                         }|j                  d      }t        j                  d   }t        j                  d   }t        j                  ||      }t        j                  j                  d      }|j                  d|j                        }t               }t        ||       |j                  |d	       t               }	t        j                         }
|
j                  d      }d
di}t        |||       |
j                  |	d	       |j                  d       |	j                  d       |j                         }|	j                         }t!        ||k7         y )Nr   r   r   r   r   r   r$   rI   rJ   rN   rO   rP   r   )r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r   r   rR   rS   rT   r   )r3   r4   r"   r5   r6   r7   r8   r9   rU   rX   rY   rQ   rZ   r\   s                 r:   test_plot_acf_kwargsr_   z   s$    **,C		B	y	B	xB//"b)K			t	$B

%
%c23E3E
%
FC9DSRKKVK$yjjlO		$	$S	)B!9-MSR}5,V<IIaL!IIKE"'')KK5 !r<   c                    t        j                         }|j                  d      }t        j                  d   }t        j                  d   }t        j                  ||      }t        j                  j                  d      }|j                  d|j                        }t        j                  |d d d<   t               }t        ||d	       |j                  |d
       |j                  d       t        j                         }|j                  d      }t               }	t        ||d	       |j                  |	d
       |	j                  d       t!        |j#                         |	j#                         k7         y )Nr   r   r   r   r   r      drop)r"   missingrI   rJ   r   conservative)r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   nanr   r   rR   rS   r   rT   )
r3   r4   r"   r5   r6   r7   r8   r9   rU   buff_conservatives
             r:   test_plot_acf_missingrg      s    **,C		B	y	B	xB//"b)K			t	$B

%
%c23E3E
%
FCC"I9DSR(KKVK$IIaL
**,C		B	SR0KK!&K11DIIK,11334r<   c                    t        j                         }|j                  d      }t        j                  d   }t        j                  d   }t        j                  ||      }t        j                  j                  d      }|j                  d|j                        }t        ||t        j                  dd      	       t        ||d
d       t        ||d d       y r>   )r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r   rB   rE   s           r:   test_plot_pacf_irregularri      s     **,C		B	y	B	xB//"b)K			t	$B&&sB4F4F&GDdr		!R 01dr/drE2r<   c                    t        j                         }|j                  d      }t        j                  d   }t        j                  d   }t        j                  ||      }t        j                  j                  d      }|j                  d|j                        }|j                  d|j                        }t        ||       t        |||d       t        |||	       t        |||d 
       t        |||d       t        |||d       t        |||d       t        |||d       t        |||d       t        |||d       y )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.   r/   r0   r1   r   )	r3   r4   r"   r5   r6   r7   r8   x1x2s	            r:   test_plot_ccfrt      s    **,C		B	y	B	xB//"b)K			t	$B		$	$S"2D2D	$	EB		$	$S"2D2D	$	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                  j                  d      }t        j                  |j                  d|j                        |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       y )Nr   r   r   r   r   r   r?   )xyr    )r4   r#   )r4   F)r4   rk   )r4   r&   T)r4   rl   )r4   rm   )r4   rp   )r4   rq   )r'   r(   r*   r+   r,   r-   r.   r/   vstackr0   r1   Tr   pd	DataFrame)r3   r4   r5   r6   r7   r8   rv   s          r:   test_plot_accf_gridr|      s+    **,C	y	B	xB//"b)K			t	$B
		##C1C1C#D##C1C1C#D 	 	q  12<<a1gAadG <=>1#B'1#1#U31#T*1#-1#4(1#$/1#%0r<   c           
      n   t        j                         j                  }|j                  j	                  t
              j                  t              |d<   |j                  d      j                  j                         }t        j                  |j                  j                  D cg c]  }dj                  |d   |d   g       c}d      }t!        |j                  |d      }t        j"                  |      |_        t!        |      }t        j"                  |d	
      |_        t!        |      }t        j$                  |d
      |_        t!        |      }	 t'        j(                  d      5  t!        |      }|j*                  d   j-                         D cg c]  }|j/                          }}g d}t1        ||      D ]#  \  }}	t3        |	t4              r||	v rJ ||	k(  r#J  	 d d d        y c c}w c c}w # 1 sw Y   y xY w# t6        j8                  $ r t;        j<                  d       Y y w xY w)NYEARrL   r?   r   z%b-%YrJ   zel nino)datesylabelMSfreqMDE_de)JanFeb)u   MärMrzAprMaiJunJulAugSepOktNovDezz!Failure due to unsupported locale)reason)r   load_pandasdatar~   astypeintapplystr	set_indexry   unstackrz   to_datetimeindexvaluesjoinr
   DatetimeIndexPeriodIndexcalendardifferent_localeaxesget_xticklabelsget_textzip
isinstancetuplelocaleErrorpytestxfail)
r3   dtarv   r   r4   _labelsexpectedlblexps
             r:   test_plot_monthr      s   




#
#C((//#&,,S1CK
--

!
!
)
)
+CNN),)9)9:A1Q41,	:7E
 SZZuY
?C   'CI
S/C   T2CI
S/C u3/CI
S/CA&&w/ 	&S/C,/HHQK,G,G,IJqajjlJFJH  1 &Sc5)#:%:#:%:	&#	& 	&) 	;, K	& 	&, << A?@AsT   $ G2H .+G<G70,G<G<%G<)H 7G<<HH H )H43H4c           	         t        j                         j                  }t        dj                  t        |j                  j                  t              j                  t              |j                  j                  t              j                  t                          }t        |j                  j                  |       |j                  t!        j"                  |d      d       t        |j                         t!        j"                  |d      |_        t        |j                         t!        j&                  |d      |_        t        |j                         y )Nz-QzQS-OCTr   T)inplaceQ)r	   r   r   r   r   r   yearr   r   r   r   quarterr   unempr   r   rz   r   r   r   )r3   r   r   s      r:   test_plot_quarterr   )  s    



!
&
&C		HHOOC &&s+S[[-?-?-D-J-J3-O	
E !!5) MM"""5x8$MG   X6CI u3/CIr<   c                    t         j                  j                  d      }|j                  dd      }|dt        j                  t        j
                  d      dz  t         j                  z        d d d f   z  z  }|j                         }t        j                  t        j
                  dd      d	      }|j                         }t        j                  ||gd
dg      j                  }|j                  d      d
   }g d}t        ||      }|j                         d   }|j                         D 	cg c]  }	|	j!                          }
}	t#        ||
       y c c}	w )Nr            g      (@r@   r?   ra   )r   r?   r   monthsr   )r   r   Marr   Mayr   r   r   r   Octr   Decr   )r*   r.   r/   randnsinrB   piraveltilerz   r{   ry   groupbyr   get_axesr   r   r   )r3   r8   r   r   dfgroupedr   r4   r"   tloutputs              r:   test_seasonal_plotr   C  s   			t	$B88BDAryy+bee34T1W===D::<DWWRYYq"%w/F\\^F	tVnVX,>	?	A	ABjj"6*GF 
(C		B&(&8&8&:;bkkm;F;  <s   3Emodel_and_args   F)r#   	old_names)r   r   r   )order
use_pandasTr&   g?c           	      p   |\  }}t         j                  j                  d      }|j                  d      }t	        dd      D ]$  }||xx   d||dz
     z  d||dz
     z  z
  z  cc<   & |dd  }| rat        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 |j                         }t        ||	|
|      }t        |t        j                        sJ y )Nr   i  r   g?r?   r   r   z1960-1-1   )r   periodsir   )r&   )r*   r.   r/   r1   rangerz   
date_ranger   shapeSeriesfitr   r   r'   Figure)r   r   r&   modelkwargsr8   rw   ir   startendresr4   s                r:   test_predict_plotr   a  s6    #ME6			q	!B
4 A1d^ 0	!aAhqQx//0	#$AY
R
 ekk!n)*BiIIauTc{+
aggaj2o

V

 
 
"C
sE3e
4Cc3::&&&r<   c            	         t        d      D  cg c]7  } t        j                  j                         t        j                  |       z   9 }} t        j
                  |dgt        t        d                  }t        |       y c c} w )Nr    )secondsa)r   columnsr   )r   rz   	Timestampnow	Timedeltar{   listr   )r   idxr   s      r:   test_plot_pacf_small_sampler   ~  sd    AFr
KA2<<Q 77
KC
K	%)_
B
 bM Ls   <B)8statsmodels.compat.pandasr   statsmodels.compat.pythonr   r   ior   r   numpyr*   numpy.testingr   r   pandasrz   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;   rC   rG   r]   r_   rg   ri   rt   r|   r   r   r   parametrizedictr   r    r<   r:   <module>r     sv   / *     /   2	 	 	 1 , -	(
 % % 1 1 ' ' %& %&P " "< 5 54 3 3 . .. 1 10 0A 0Af  2 ! !: te,-t)7L/MN e}54,/' 0 6	 ',  C  		s   I# #I,+I,