
    'YHh-,              	       "   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& ejP                  jH                  d        Z)ejP                  jH                  d        Z*ejP                  jH                  d        Z+ejP                  jH                  d        Z,ejP                  jH                  d        Z-ejP                  jH                  d        Z.ejP                  jH                  d        Z/ejP                  jH                  d        Z0ejP                  jH                  d        Z1ejP                  je                  ed      ejP                  jH                  d               Z3ejP                  jH                  d        Z4ejP                  jH                  d        Z5ejP                  jH                  ejP                  jm                  de! e7dd      fe# e7d      fg      ejP                  jm                  d d!dg      ejP                  jm                  d"dd#g      d$                             Z8ejP                  jH                  d%        Z9y# e'$ r Y 'w xY w)&    )	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                         }|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           a/var/www/html/planif/env/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'   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

%
%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/   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&&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/   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&&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%   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   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#   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

%
%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/   r0   r1   r2   r   rC   rF   s           r;   test_plot_pacf_irregularrj      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/   r0   r1   r2   r   )	r4   r5   r#   r6   r7   r8   r9   x1x2s	            r;   test_plot_ccfru      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!   )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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=   z)Matplotlib uses different backend in WASMreasonc           
      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YEARrM   r@   r   z%b-%YrK   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 localer~   )r	   load_pandasdatar   astypeintapplystr	set_indexrz   unstackr{   to_datetimeindexvaluesjoinr   DatetimeIndexPeriodIndexcalendardifferent_localeaxesget_xticklabelsget_textzip
isinstancetuplelocaleErrorpytestxfail)
r4   dtarw   r   r5   _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   r{   r   r   r   )r4   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      (@rA   r@   rb   )r   r@   r   monthsr   )r   r   Marr   Mayr   r   r   r   Octr   Decr   )r+   r/   r0   randnsinrC   piraveltiler{   r|   rz   groupbyr   get_axesr   r   r   )r4   r9   r   r   dfgroupedr   r5   r#   tloutputs              r;   test_seasonal_plotr   G  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/   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  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   r{   	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):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;   <module>r     s   / <     /   2	 	 	 1 , -	(
 % % 1 1 ' ' %& %&P " "< 5 54 3 3 . .. 1 10 6   0A 	
0Af  2 ! !: te,-t)7L/MN e}54,/' 0 6	 ',  K  		s    J JJ