o
    da                     @   s   d Z ddlmZmZmZmZ ddlZddlZddlZddl	m
Z
mZ ddlm  mZ ddlmZmZmZmZmZmZmZ ddlmZ ddlmZmZmZ ddlm Z m!Z!m"Z" ddl#m$Z$ dd	l%m&Z& dd
l'm(Z( ej)G dd de&Z*dddZ+dS )z< Test cases for time series specific (freq conversion, etc)     )datedatetimetime	timedeltaN)
BaseOffset	to_offset)	DataFrameIndexNaTSeriesconcatisnato_datetime)DatetimeIndexbdate_range
date_range)PeriodPeriodIndexperiod_range)timedelta_range)TestPlotBase)WeekOfMonthc                   @   s  e Zd Zejddd Zdd Zdd Zdd	 Z	d
d Z
ejdg ddd Zejdg ddd Zdd Zdd Zejdddgdd Zdd Zdd Zejdg ddd  Zejd!g d"d#d$ Zejdg dd%d& Zejdg dd'd( Zejd!g d"d)d* Zejdg dd+d, Zejdg dd-d. Zd/d0 Zd1d2 Zd3d4 Zejjd5d6d7d8 Zd9d: Zd;d< Z d=d> Z!d?d@ Z"dAdB Z#dCdD Z$dEdF Z%dGdH Z&dIdJ Z'dKdL Z(dMdN Z)dOdP Z*dQdR Z+dSdT Z,ejj-dUdV Z.dWdX Z/dYdZ Z0d[d\ Z1d]d^ Z2d_d` Z3e4j5dadb Z6dcdd Z7dedf Z8dgdh Z9didj Z:dkdl Z;dmdn Z<dodp Z=dqdr Z>dsdt Z?dudv Z@dwdx ZAdydz ZBd{d| ZCd}d~ ZDdd ZEdd ZFdd ZGdd ZHdd ZIdd ZJdd ZKdd ZLdd ZMejjd5d6dd ZNdd ZOdd ZPdd ZQdd ZRdd ZSdd ZTdd ZUdd ZVdd ZWdd ZXdd ZYdd ZZdd Z[ejjdd6dd Z\dd Z]dd Z^dS )
TestTSPlotzignore::UserWarningc                 C   s   |}t ddd|d}tddg|d}t|j | }t| d  }|d j|d jfd	ks3J |d
 j|d
 jfdksAJ d S )N1/1/2011   H)periodsfreqtzg     g@g     t@indexr   r   r   )   r   )	r   r   _check_plot_worksplotlist	get_lines	get_xdatahourminute)selfZtz_aware_fixturer   r    tsaxxdata r/   [/app/.heroku/python/lib/python3.10/site-packages/pandas/tests/plotting/test_datetimelike.pytest_ts_plot_with_tz/   s   
 zTestTSPlot.test_ts_plot_with_tzc                 C   s`   t tjddtdd}| j \}}|jd|d | |	  D ]
}|
 dks-J q#d S )N
   	   r   r   Zfontsizer-   )r   nprandomrandnrangepltsubplotsr%   get_xticklabelsZget_yticklabelsZget_fontsize)r+   dffigr-   labelr/   r/   r0   test_fontsize_set_correctly<   s   z&TestTSPlot.test_fontsize_set_correctlyc                 C   s   t dddd}t|jd d}ttjt|d|d}t|j	 |dd	 
|d
d }ttjt|d|d}t|j	 t dddd}t|jd d}ttjt|d|d}t|j	 d S )N1/1/1987ZMSd   r   r   r      r   r   (   -   c   z2008-1-1 00:15:00Z15Tr2   )r   r   valuesr   r5   r6   r7   lenr$   r%   union)r+   idxr<   df2r/   r/   r0   test_frame_inferredD   s   

zTestTSPlot.test_frame_inferredc                 C   s:   t g d}t||d}t|j|d t|j|d d S )Nr#   r   rD   r   )Zxerr)Zyerr)r5   arrayr   r$   r%   )r+   iar/   r/   r0   test_is_error_nozeroindexW   s   z$TestTSPlot.test_is_error_nozeroindexc                 C   s   t dddd}tg dg dd|}| j \}}|j|d t| d	ks*J | j| d
}tj	t
|d |d   W d    d S 1 sKw   Y  d S )Nr@   ArD   rB   )xyzrN   )rS   Br-   r#   zno numeric data to plotmatch)r   r   r9   r:   r%   rI   r'   closepytestraises	TypeError)r+   rK   r<   r=   r-   msgr/   r/   r0   test_nonnumeric_exclude^   s   "z"TestTSPlot.test_nonnumeric_excluder   )STr   DWMQrS   c                 C   D   t d|dd}ttjt||}| j \}}t|j	|d d S N
12/31/1999rA   rB   rX   )
r   r   r5   r6   r7   rI   r9   r:   r$   r%   r+   r   rK   ser_r-   r/   r/   r0   test_tsplot_periodk   s   zTestTSPlot.test_tsplot_period)	ra   rb   r   rc   rd   re   zQ-DECrS   Z1B30Minc                 C   rg   rh   )
r   r   r5   r6   r7   rI   r9   r:   r$   r%   rj   r/   r/   r0   test_tsplot_datetimer   s   zTestTSPlot.test_tsplot_datetimec                 C   sD   t  }| j \}}|jd|d d}|| d  ks J d S )Nkstyler-   )        rr   rr   r#   r   )tmmakeTimeSeriesr9   r:   r%   r'   	get_color)r+   r,   rl   r-   colorr/   r/   r0   test_tsplot{   s
   zTestTSPlot.test_tsplotc                 C   s   t  }d}tjt|d |jddd W d    n1 sw   Y  |jdd}tjt|d |jddd W d    d S 1 sDw   Y  d S )NzCannot pass 'style' string with a color symbol and 'color' keyword argument. Please use one or the other or pass 'style' without a color symbolrY   zb-z#000099)rq   rv   T)Zdrop)rs   rt   r\   r]   
ValueErrorr%   Zreset_index)r+   r,   r_   sr/   r/   r0   test_both_style_and_color   s   "z$TestTSPlot.test_both_style_and_colormsusc                 C   sD   | j  \}}tdd|d}ttjt||}t|j	|d d S )N1/1/2012rA   r   r   rX   )
r9   r:   r   r   r5   r6   r7   rI   r$   r%   )r+   r   rl   r-   rngrk   r/   r/   r0   test_high_freq   s   zTestTSPlot.test_high_freqc                 C   sn   ddl m} |d dd u sJ |dddksJ |tdddtddjks(J |ddtd	djks5J d S )
Nr   )get_datevaluerc     rS   re   z1987-12r@   z1987-1-1)%pandas.plotting._matplotlib.converterr   r   ordinal)r+   r   r/   r/   r0   test_get_datevalue   s
    zTestTSPlot.test_get_datevaluec                 C   sz   dd }t dtddddd}| j \}}|j|d	 ||d
 t dtddddd}|j|d	 ||d t  d S )Nc                 S   s>   |   d }| d j}| d }|| ||ksJ d S )Nr   )r'   r(   r   	get_ydataZformat_coord)r-   Zexpected_string
first_lineZfirst_xZfirst_yr/   r/   r0   check_format_of_first_point   s   zITestTSPlot.test_ts_plot_format_coord.<locals>.check_format_of_first_pointr#   z
2014-01-01rD   zA-DECr~   r   rX   zt = 2014  y = 1.000000rc   zt = 2014-01-01  y = 1.000000)r   r   r9   r:   r%   rs   r[   )r+   r   Zannualrl   r-   Zdailyr/   r/   r0   test_ts_plot_format_coord   s   

z$TestTSPlot.test_ts_plot_format_coordc                 C   s8   t d|dd}ttjt||}t|j|jj	 d S Nri   rA   rB   )
r   r   r5   r6   r7   rI   r$   r%   r    r   r+   r   rK   rk   r/   r/   r0   test_line_plot_period_series   s   z'TestTSPlot.test_line_plot_period_seriesfrqncy)Z1SZ3SZ5TZ7HZ4DZ8WZ11MZ3Ac                 C   :   t d|dd}ttjt||}t|j|jj	j
 d S r   )r   r   r5   r6   r7   rI   r$   r%   r    r   	rule_code)r+   r   rK   ry   r/   r/   r0    test_line_plot_period_mlt_series   s   z+TestTSPlot.test_line_plot_period_mlt_seriesc                 C   r   r   )r   r   r5   r6   r7   rI   r$   r%   r    r   r   r   r/   r/   r0   test_line_plot_datetime_series   s   z)TestTSPlot.test_line_plot_datetime_seriesc                 C   sB   t d|dd}ttjt|d|g dd}t|j|jj	 d S Nri   rA   rB   rD   )rS   rW   Cr    columns)
r   r   r5   r6   r7   rI   r$   r%   r    r   r+   r   rK   r<   r/   r/   r0   test_line_plot_period_frame   s    z&TestTSPlot.test_line_plot_period_framec                 C   sR   t d|dd}ttjt|d|g dd}|j|jjj	j}t
|j| d S r   )r   r   r5   r6   r7   rI   r    asfreqr   r   r$   r%   )r+   r   rK   r<   r   r/   r/   r0   test_line_plot_period_mlt_frame   s    z*TestTSPlot.test_line_plot_period_mlt_framec                 C   sR   t d|dd}ttjt|d|g dd}|j|jjj	j}t
|j| d S r   )r   r   r5   r6   r7   rI   r    	to_periodr   r   r$   r%   r   r/   r/   r0   test_line_plot_datetime_frame   s    z(TestTSPlot.test_line_plot_datetime_framec                 C   sf   t d|dd}ttjt||}t|jtt|j	}t
|j|j	j |g d }t
|j d S )Nri   rA   rB   )r   rD         )r   r   r5   r6   r7   rI   rH   r	   Zasarrayr    r$   r%   Zinferred_freqr   r/   r/   r0   test_line_plot_inferred_freq   s   z'TestTSPlot.test_line_plot_inferred_freqc                 C   sf   | j  \}}tdd}ttt||d}t|d d |dd  g}|j|d t|dr1J d S )Nz2001-1-1z	2001-1-10r   rD   r   rX   r   )	r9   r:   r   r   r8   rI   r   r%   hasattr)r+   rl   r-   r   r,   r/   r/   r0   test_fake_inferred_business   s   
z&TestTSPlot.test_fake_inferred_businessc                 C   sL   t  }t|j t|jd ddd}ttj	t
||d}t|j d S )Nr   ZBQSr2   rB   r   )rs   rt   r$   r%   r   r    r   r5   r6   r7   rI   )r+   rk   drr/   r/   r0   test_plot_offset_freq   s
   
z TestTSPlot.test_plot_offset_freqc                 C   sL   t tdddtdddtdddg}ttjt||d}t|j d S )N  r#   r      r   )	r	   r   r   r5   r6   r7   rI   r$   r%   )r+   r   rk   r/   r/   r0    test_plot_multiple_inferred_freq  s   &z+TestTSPlot.test_plot_multiple_inferred_freqzApi changed in 3.6.0)reasonc                 C   s   dd l m  m  m} tdddd}ttjt	|d|d}| j
 \}}|j|d | }| }| }t||D ]\}	}
||	d	}t|
 }t	|rZ||ksZJ q>d S )
Nr   z2012-6-22 21:59:51.960928L  rB   r   r   rX   %H:%M:%S.%f)r   plotting_matplotlib	converterr   r   r5   r6   r7   rI   r9   r:   r%   	get_xaxisZget_ticklocsget_ticklabelszipZ_from_ordinalstrftimestrget_text)r+   convrK   r<   rl   r-   ZaxisZtlocsZtlabelslocr>   xprsr/   r/   r0   test_uhf  s   zTestTSPlot.test_uhfc           	      C   s  t dddd}ttjt|d|d}|jg d }| j \}}|j	|d t
| d	  d d d	f  }d
}t|dd  ||d |g dk  sRJ | j \}}| }|jt|_|j	|d t
| d	  d d d	f  }t|dd  | dk  sJ d S )Nz2012-6-22 21:59:51ra   rA   rB   r   r   )r   r#   rD      rX   r   g)QΠE>r#   g:0yE>)r   r   r5   r6   r7   rI   ilocr9   r:   r%   r   r'   
get_xydatadifffabsallcopyr    astypeobject)	r+   rK   r<   irregrl   r-   ZdiffssecrL   r/   r/   r0   test_irreg_hf  s   $,$&zTestTSPlot.test_irreg_hfc                 C   sl   t  }|g d }| j \}}|j|d}|d usJ t| d  |jD ]
\}}||ks3J q)d S )N)r   r#   r      rX   r   )	rs   rt   r9   r:   r%   r   r'   r(   r    )r+   rk   rl   r-   retr   r   r/   r/   r0   "test_irregular_datetime64_repr_bug,  s    z-TestTSPlot.test_irregular_datetime64_repr_bugc                 C   sn   t  }| j \}}|j|d | d  d |jd jks#J | d 	 }t
|djdks5J d S )NrX   r   r!   datarW   )rs   ZmakePeriodSeriesr9   r:   r%   r'   r   r    r   r(   r   freqstrr+   btsrl   r-   rK   r/   r/   r0   test_business_freq8  s   $zTestTSPlot.test_business_freqc                 C   s   t dd}|d}| j \}}|j|d | d  d |j	d j
ks,J | d  }t|djdks>J d S )Ni,  ZBMre   rX   r   r!   r   )rs   rt   r   r   r9   r:   r%   r'   r   r    r   r(   r   r   )r+   r   r,   rl   r-   rK   r/   r/   r0   test_business_freq_convert@  s   
$z%TestTSPlot.test_business_freq_convertc                 C   s   t  }td|}| j \}}|j|d | d  }d}t	j
t|d t|d W d    d S 1 s:w   Y  d S )Nr   rX   r   z)freq not specified and cannot be inferredrY   r   )r   rs   rt   r   r9   r:   r%   r'   r(   r\   r]   rx   r   )r+   r   r   rl   r-   rK   r_   r/   r/   r0   test_freq_with_no_period_aliasI  s   "z)TestTSPlot.test_freq_with_no_period_aliasc                 C   sf   t ddddtdd }ttd|d}| j \}}|j|d | d	 	 }t
|jr1J d S )
Nz
2012-12-20   r   r~      minutesr   rX   r   )r   r   r   r5   aranger9   r:   r%   r'   r(   r	   is_normalized)r+   rK   r<   rl   r-   r   r/   r/   r0   test_nonzero_baseU  s   zTestTSPlot.test_nonzero_basec                 C   sT   t dt i}| j \}}|j|d | d  }t|j	
 t| d S )NrQ   rX   r   )r   rs   rt   r9   r:   r%   r'   r(   assert_index_equalr    r   r   r   r/   r/   r0   test_dataframe^  s
   zTestTSPlot.test_dataframec                    s    fdd}t  } j \}}|j|d ||  j \}}t||d d}|j|d || t||d d}|jdd}|D ]}|| qFd S )Nc                    sD  |   }| |d d |d d  |   }|d |d d ks"J |d |d d ks.J td| jtd| jf}| dd |   }t|d |d jksQJ t|d |d jks^J td| jtd| jf}| tdddtddd |   }t|d |d jksJ t|d |d jksJ |  } j	| d S )	Nr   r   r#   r2   1/1/2000z4/1/2000r   r   )
get_xlimset_xlimr   r   intr   r   
get_figurer9   r[   )r-   Zxlimresultexpectedr=   r+   r/   r0   _testf  s"   z*TestTSPlot.test_axis_limits.<locals>._testrX   r#   rQ   bT)r:   )rs   rt   r9   r:   r%   r   )r+   r   rk   rl   r-   r<   axesr/   r   r0   test_axis_limitse  s   
zTestTSPlot.test_axis_limitsc                 C   s   dd l m  m  m} |td|jksJ |td|jks$J |td|jks0J |td|jks<J |td|j	ksHJ |td|jksTJ d S )Nr   rW   rc   re   rf   rS   rd   )
r   r   r   r   Z
get_finderr   Z_daily_finderZ_monthly_finderZ_quarterly_finderZ_annual_finder)r+   r   r/   r/   r0   test_get_finder  s   zTestTSPlot.test_get_finderc                 C   s   g d}t dddjgt|  }}g }g }|D ]L}td|d}ttjt||}| j	 \}	}
|j
|
d |
 }|| d  |
 \}}|
|d | || d  | j|
  q||kskJ ||ksqJ d S )	N)r2   rE      i  i  i
  '  z1999-1-1rW   rC   r   rX   r   ?)r   r   rI   r   r   r5   r6   r7   r9   r:   r%   r   appendget_majorticklocsr   r   r[   r   )r+   Zday_lstxpl1xpl2rs1rs2nr   rk   rl   r-   xaxisvminvmaxr/   r/   r0   test_finder_daily  s"   zTestTSPlot.test_finder_dailyc                 C   s   ddg}t djgt|  }}g }g }|D ]Q}tdt|d dd}ttjt||}| j	
 \}	}
|j|
d |
 }|| d	  |
 \}}|
|d
 | || d	  | j	|
  q||ksnJ ||kstJ d S )Ng      @r   1988Q11987Q2r   rf   r~   rX   r   r   r   r   rI   r   r   r   r5   r6   r7   r9   r:   r%   r   r   r   r   r   r[   r   r+   Zyrsr   r   r   r   r   r   rk   rl   r-   r   r   r   r/   r/   r0   test_finder_quarterly  "   z TestTSPlot.test_finder_quarterlyc                 C   s   g d}t djgt|  }}g }g }|D ]Q}tdt|d dd}ttjt||}| j	
 \}	}
|j|
d |
 }|| d  |
 \}}|
|d	 | || d  | j	|
  q||ksnJ ||kstJ d S )
N)gffffff?g      @r   r   zJan 1988r      re   r~   rX   r   r   r   r   r/   r/   r0   test_finder_monthly  r   zTestTSPlot.test_finder_monthlyc                 C   sn   t dddd}ttjt||}| j \}}|j|d |	 }|
 d }tddj}||ks5J d S )Nr   i   re   r~   rX   r   Z1989Q1)r   r   r5   r6   r7   rI   r9   r:   r%   r   r   r   r   )r+   r   rk   rl   r-   r   r   r   r/   r/   r0   test_finder_monthly_long  s   z#TestTSPlot.test_finder_monthly_longc           	      C   s   g d}dd |D }g }dD ]6}t d|dd}ttjt||}| j \}}|j|d |	 }|
| d	  | j|  q||ksLJ d S )
N)r   i    r     i  i  iz  c                 S   s   g | ]	}t |d djqS )rS   rC   )r   r   .0rT   r/   r/   r0   
<listcomp>  s    z1TestTSPlot.test_finder_annual.<locals>.<listcomp>)r   r2      1   rG      iW  i  Z1987rS   r~   rX   r   )r   r   r5   r6   r7   rI   r9   r:   r%   r   r   r   r[   r   )	r+   r   r   Znyearsr   rk   rl   r-   r   r/   r/   r0   test_finder_annual  s   zTestTSPlot.test_finder_annualc           	      C   t   d}t dd|d}ttjt||}| j \}}|j|d |	 }|
 d }tdddj}||ks8J d S )Ni@ 1/1/1999ZMinrB   rX   r   rC   r   r   r5   r6   r7   rI   r9   r:   r%   r   r   r   r   )	r+   Znminutesr   rk   rl   r-   r   r   r   r/   r/   r0   test_finder_minutely  s   zTestTSPlot.test_finder_minutelyc           	      C   r  )N   r  r   rB   rX   r   rC   r	  )	r+   Znhoursr   rk   rl   r-   r   r   r   r/   r/   r0   test_finder_hourly  s   zTestTSPlot.test_finder_hourlyc           
      C   s6  t  }tj|jdd< | j \}}|j|d | }t	|dks%J |d }|
 }tjj|t|tjd}t|tjjjsCJ |j}|dddf  sRJ | j|  t  }|g d }tj|jdd< | j \}}|j|d}| }t	|dksJ |d }|
 }tjj|t|tjd}t|tjjjsJ |j}|dddf  sJ | j|  g d}ttjt	||}	tj|	jdd< | j \}}|	j|d | }t	|dksJ |d }|
 }tjj|t|tjd}t|tjjjs	J |j}|dddf  sJ d S )	Nr      rX   r#   r   maskZ
fill_value)	r   r#   r   r   r   r3   r         r   )rs   rt   r5   nanr   r9   r:   r%   r'   rI   r   maMaskedArrayr   
isinstancecorer  r   r[   r   r   r6   r7   )
r+   r,   rl   r-   linesliner   r  rK   rk   r/   r/   r0   	test_gaps  sP   zTestTSPlot.test_gapsc           
      C   s   t  }tj|jdd< | j \}}|j|d t|j	d |j	d dd}t
tjt||}|jdd	 | }t|d
ksCJ t|j d
ksNJ |d }| }tjj|t|tjd}t|tjjjslJ |j}	|	ddd
f  s{J d S )Nr   r  rX   r   r"   Z12hrC   Tsecondary_yr#   r  )rs   rt   r5   r  r   r9   r:   r%   r   r    r   r6   r7   rI   r'   right_axr   r  r  r   r  r  r  r   )
r+   lowrl   r-   idxhry   r  r  r   r  r/   r/   r0   test_gap_upsample>  s    zTestTSPlot.test_gap_upsamplec           
      C   sZ  t tjd}t tjd}| j \}}|jdd}t|ds$J t|dr+J | }|	 d }t |
 | }t|| |  dksNJ |d   rXJ | j| | j \}}	|j|	d |	  d	ksuJ | j|	  | }|jdd}	|  sJ t|drJ t|dsJ t|	dsJ t|	drJ d S )
Nr2   Tr  left_axr  r   rightrX   left)r   r5   r6   r7   r9   r:   r%   r   get_axesr'   r   r(   rs   assert_series_equal	get_yaxisget_ticks_positionget_visibler[   r   )
r+   rk   ser2r=   rl   r-   r   r  r   ax2r/   r/   r0   test_secondary_yS  s0   zTestTSPlot.test_secondary_yc                 C   s6  t ddd}ttjd|}ttjd|}| j \}}|jdd}t|ds,J t|dr3J |	 }|
 d }t| |  }	t||	 |  d	ksXJ |d   rbJ | j| | j \}}
|j|
d
 |
  dksJ | j|
  | }|jdd}
|  sJ d S )Nr   r2   r   Tr  r   r  r   r!  rX   r"  )r   r   r5   r6   r7   r9   r:   r%   r   r#  r'   r   r(   Zto_timestamprs   r$  r%  r&  r'  r[   r   )r+   rK   rk   r(  r=   rl   r-   r   r  r   r)  r/   r/   r0   test_secondary_y_tso  s*   zTestTSPlot.test_secondary_y_tsc                 C   sn   t tjd}| j \}}|jdd|d}t|dsJ t|dr%J | }|d 	 
 dks5J d S )	Nr2   TZdensityr  kindr-   r   r  r#   r!  )r   r5   r6   r7   r9   r:   r%   r   r#  r%  r&  r+   rk   r=   r-   r   r/   r/   r0   test_secondary_kde  s   zTestTSPlot.test_secondary_kdec                 C   sR   t tjd}| j \}}|jdd|d | }|d  	 dks'J d S )Nr2   Tbarr,  r#   r!  )
r   r5   r6   r7   r9   r:   r%   r#  r%  r&  r.  r/   r/   r0   test_secondary_bar  s
   zTestTSPlot.test_secondary_barc                 C   sx   t tjddg dd}|jddgdd}|d	   d
ks"J |d   dks.J |d   d
ks:J d S )Nr   rD   rQ   r   cr   rQ   r3  T)r  r:   r   r!  r#   r"  r   r   r5   r6   r7   r%   r%  r&  r+   r<   r   r/   r/   r0   test_secondary_frame  s
   zTestTSPlot.test_secondary_framec                 C   sz   t tjddg dd}|jdddgdd	}|d
   dks#J |d   dks/J |d   dks;J d S )Nr   rD   r2  r4  r0  rQ   r3  T)r-  r  r:   r   r!  r#   r"  r   r5  r6  r/   r/   r0   test_secondary_bar_frame  s
   z#TestTSPlot.test_secondary_bar_framec                 C   s   t  }|g d }| j \}}|j|d |jd|d}| }t|d  }t|d  }t ||j	
d t ||j	
d | \}	}
|j	
 }|	|d jksZJ |
|d jkscJ d S 	Nr   r   r2   r   r         r  rX   grp   r   r#   rW   r"   )rs   rt   r9   r:   r%   r'   r   r(   r   r    r   r   r   r+   s1s2rl   r-   r)  r  idx1idx2r"  r!  Zpidxr/   r/   r0   test_mixed_freq_regular_first  s   
z(TestTSPlot.test_mixed_freq_regular_firstc                 C   s   t  }|g d }| j \}}|jd|d |j|d t|dr%J | }|d  }t ||j	
tj |d  }t ||j	
tj d S Nr:  r=  rp   rX   r   r   r#   )rs   rt   r9   r:   r%   r   r'   r(   assert_numpy_array_equalr    r   r   rH   r+   r?  r@  rl   r-   r  x1Zx2r/   r/   r0   test_mixed_freq_irregular_first  s   z*TestTSPlot.test_mixed_freq_irregular_firstc                 C   s   t   }|jg dd d f }| j \}}|j|d |jd|d}| }t|d 	 }t|d 	 }|
|jdsDJ |
|jdsOJ | \}	}
|j }|	|d jkscJ |
|d jkslJ d S r9  )rs   rt   to_framer   r9   r:   r%   r'   r   r(   equalsr    r   r   r   r>  r/   r/   r0    test_mixed_freq_regular_first_df  s   
z+TestTSPlot.test_mixed_freq_regular_first_dfc                 C   s   t   }|jg dd d f }| j \}}|jd|d |j|d t|dr,J | }|d 	 }t 
||jtj |d 	 }t 
||jtj d S rD  )rs   rt   rI  r   r9   r:   r%   r   r'   r(   rE  r    r   r   rH   rF  r/   r/   r0   "test_mixed_freq_irregular_first_df  s   z-TestTSPlot.test_mixed_freq_irregular_first_dfc                 C   s   t dddd}t dddd}ttjt||}ttjt||}| j \}}|j|d |j|d |	 D ]}t
| djdksIJ q;d S )	Nr  m  rc   r~   r   re   rX   r   r   r   r5   r6   r7   rI   r9   r:   r%   r'   r   r(   r   r+   r  idxlhighr  rl   r-   r  r/   r/   r0   test_mixed_freq_hf_first  s   z#TestTSPlot.test_mixed_freq_hf_firstc                 C   s   t dddd}tjd}t||d}|d }| j \}}|j	|d}|j	d	|d
 |j
d  d |j
d  d ksBJ d S )Nz2012-01-01 13:00
2012-01-02r   rC   r   r   rb   rX   rrp   r   r#   )r   r5   r6   r7   r   r   Zinterpolater9   r:   r%   r  r(   )r+   Zts_indZts_datar,   Zts2rl   r-   r/   r/   r0   test_mixed_freq_alignment  s   ,z$TestTSPlot.test_mixed_freq_alignmentc           	      C   sZ  t dddd}t dddd}ttjt||}ttjt||}| j \}}|jd|d |jd|d |	 D ]}t
| d	jdksKJ q=| }t|jd
ksYJ | j|  t dddd}t dddd}ttjt||}ttjt||}| j \}}|j|d |j|d |	 D ]}t
| d	jdksJ qd S )Nr  rM  rc   r~   r   re   T)Zlegendr-   r   r      rb   r   r   rX   )r   r   r5   r6   r7   rI   r9   r:   r%   r'   r   r(   r   
get_legendZtextsr[   r   )	r+   r  rP  rQ  r  rl   r-   r  legr/   r/   r0   test_mixed_freq_lf_first  s,   z#TestTSPlot.test_mixed_freq_lf_firstc                 C   sb   t  }|g d }tdddd}ttjt||}| j	 \}}|j
|d |j
|d d S )N)r   r#   r   rD   r   r   r   r      r3   r2   r              z1/3/2000r   rW   r~   rX   )rs   rt   r   r   r5   r6   r7   rI   r9   r:   r%   )r+   r,   r   r   Zpsrl   r-   r/   r/   r0   test_mixed_freq_irreg_period  s   z'TestTSPlot.test_mixed_freq_irreg_periodc                 C   s  t dddd}|d d |dd  }ttt||}ttt||}| jjddd\}\}}|j|d	 |j|d	 |jdksEJ |jdksLJ |j	d
 
 d |j	d
 
 d ks`J | j \}}| }|j|d	 |j|d	 |j	d
 
 d |j	d
 
 d ksJ d S )N
2015-01-01rD   re   r~   r#   r   T)ZnrowssharexrX   r   r!   )r   rJ   r   r8   rI   r9   r:   r%   r   r  r   Ztwinx)r+   rA  rB  r?  r@  r=   Zax1r)  r/   r/   r0   test_mixed_freq_shared_ax"  s   (,z$TestTSPlot.test_mixed_freq_shared_axc                 C   s   | j  \}}tdtdg}ttt||}|j|d | d 	 }|j
 t| ks2J t| |j
 ks?J d S )Nr`  z
2015-01-03rX   r   )r9   r:   r   r
   r   r8   rI   r%   r'   r(   r    minmax)r+   rl   r-   Zdtiry   r.   r/   r/   r0   test_nat_handlingB  s   zTestTSPlot.test_nat_handlingc                 C   s   t dddd}t dddd}ttjt||}ttjt||}| j \}}|j|d |j|d |	 D ]}t
| dj|jksJJ q;d S )	Nr  4   rd   r~   r   re   rX   r   rN  rO  r/   r/   r0   test_to_weekly_resamplingM  s   z$TestTSPlot.test_to_weekly_resamplingc                 C   s   t dddd}t dddd}ttjt||}ttjt||}| j \}}|j|d |j|d |	 j
tj}tjg dtjd	}| D ](}	t|	 d
j|jks]J |	jdd}
t|
dkrpt|
| qNt|
| qNt  d S )Nr  rf  rd   r~   r   re   rX   i  i  i  i  i  i   i  i  i  i  i  i  Zdtyper   Forig)r   r   r5   r6   r7   rI   r9   r:   r%   r   asi8r   float64rO   r'   r   r(   r   rs   rE  r[   )r+   r  rP  rQ  r  rl   r-   Z
expected_hZ
expected_lr  r.   r/   r/   r0   test_from_weekly_resamplingX  s&   z&TestTSPlot.test_from_weekly_resamplingc                 C   s"  t dddd}t dddd}ttjt|d|g dd	}ttjt|d|g dd	}d
D ]\}}| j \}}|j|d|d |j|d|d tj	g dtj
d}	tjt|	tj
d}
tdD ].}|j| }t| j|jksvJ t|jdd|	 |
|| j7 }
t|jdd|
 qc| jtj
}	tjt|	tj
d}
tdD ]1}|jd|  }t| dj|jksJ t|jdd|	 |
|| j7 }
t|jdd|
 qq0d
D ]\}}| j \}}|j|d|d |j|d|d | jtj
}	tjt|	tj
d}
tdD ]1}|j| }t| dj|jks%J t|jdd|	 |
|| j7 }
t|jdd|
 qtj	g dtj
d}	tjt|	tj
d}
tdD ]3}|jd|  }t| dj|jksqJ t|jdd|	 |
|| j7 }
t|jdd|
 qZqd S )Nr  rf  rd   r~   r   re   rD   )r   r#   r   r   ))r  area)ro  r  T)r-  Zstackedr-   rh  ri  Frj  r   )r   r   r5   r6   randrI   r9   r:   r%   rO   rm  Zzerosr8   r  r   r(   r   rs   rE  rH   r   r   rl  r   )r+   r  rP  rQ  r  Zkind1Zkind2rl   r-   Z
expected_xZ
expected_yrP   r  r  r/   r/   r0   $test_from_resampling_area_line_mixedo  sj     

z/TestTSPlot.test_from_resampling_area_line_mixedc                 C   s  t dddd}t dddd}ttjt||}ttjt||}| j \}}|j|d |j|d t|	 dksAJ |	 D ]}t
| d	jd
ksSJ qEt  | j \}}|j|d |j|d t|	 dksuJ |	 D ]}t
| d	jd
ksJ qyd S )Nz2014-07-01 09:00ra   2   rB   Z100Lr   rX   r   r   r   )r   r   r5   r6   r7   rI   r9   r:   r%   r'   r   r(   r   rs   r[   rO  r/   r/   r0   "test_mixed_freq_second_millisecond  s$   z-TestTSPlot.test_mixed_freq_second_millisecondc                 C   s   t dddt dddt dddg}ttjt|dt|td}t|j	 t
ddd	}|g d
 t}ttjt|d|}| j \}}t|j	|d d S )Nr   r#   r   r  rD   ri  r   r2   r   )r   r   r   r3   rX   )r   r   r5   r6   r7   rI   r	   r   r$   r%   r   r   r9   r:   )r+   rK   r<   rl   r-   r/   r/   r0   test_irreg_dtypes  s   " 
zTestTSPlot.test_irreg_dtypesc                    s  t dddddd tjddd }t fdd|D }ttjt|tjt|d|d	}| j	
 \}}|j|d
 | }| }t||D ];\}}	tt|d\}
}t|
d\}}
|	 }t|dkr|dkrzt||
|d}n	t||
|d}||ksJ qNd S )Nr#   rD   r   r   r  c                    "   g | ]} t t|d   qS r   r   r   r   r   tr/   r0   r       " z(TestTSPlot.test_time.<locals>.<listcomp>r   r   rX   <   %H:%M:%S%H:%M)r   r5   r6   randintcumsumrO   r   r7   rI   r9   r:   r%   
get_xticksr;   r   divmodr   r   r   r   r+   deltasr,   r<   r=   r-   tickslabels_tick_labelmry   hr   r   r/   rx  r0   	test_time  s*   "zTestTSPlot.test_timec                    s  t dddddd tjddd }t fdd|D }ttjt|tjt|d|d	}| j	
 \}}|j|d
 | }| }t||D ];\}}	tt|d\}
}t|
d\}}
|	 }t|dkr|dkrzt||
|d}n	t||
|d}||ksJ qN|dd | }| }t||D ];\}}	tt|d\}
}t|
d\}}
|	 }t|dkr|dkrt||
|d}n	t||
|d}||ksJ qd S )Nr#   rD   r   r   r  c                    ru  rv  rw  r   rx  r/   r0   r  	  rz  z4TestTSPlot.test_time_change_xlim.<locals>.<listcomp>r   r   rX   r{  r|  r}  z1:30z5:00)r   r5   r6   r~  r  rO   r   r7   rI   r9   r:   r%   r  r;   r   r  r   r   r   r   r   r  r/   rx  r0   test_time_change_xlim  sD   "z TestTSPlot.test_time_change_xlimc                    s|  t dddddd tjddd }t fdd|D }ttjt|tjt|d|d	}| j	
 \}}|j|d
}| }| }t||D ]m\}}	tt|d\}
}t|t| d }t|
d\}}
|	 }t|dkr|d dkrt||
||d}n.|d dkrt||
||dd d }n|dkrt||
||d}n
t||
||d}||ksJ qNd S )Nr#   rD   r   r   r  c                    ru  ))microsecondsrw  r   rx  r/   r0   r  2  rz  z.TestTSPlot.test_time_musec.<locals>.<listcomp>r   r   rX   r{  g    .Ai  r   r|  r}  )r   r5   r6   r~  r  rO   r   r7   rI   r9   r:   r%   r  r;   r   r  r   roundr   r   r   )r+   r  r,   r<   r=   r-   r  r  r  r  r  ry   r|   r  r   r   r/   rx  r0   test_time_musec/  s4   "zTestTSPlot.test_time_musecc                 C   s   t dddd}t dddd}ttjt||}ttjt||}| j \}}|j|d |jd|d	}|	 D ]}t
| jdksIJ q<t|d
sQJ t|drXJ |j	 D ]}t
| jdksjJ q]d S )Nr  rM  rc   r~   r   re   rX   Tr  r-   r   r  )r   r   r5   r6   r7   rI   r9   r:   r%   r'   r   r(   r   r   r   rO  r/   r/   r0   test_secondary_upsampleN  s   z"TestTSPlot.test_secondary_upsamplec                 C   sN  | j  }|d}t }|jddg|d | }t| dks%J |	 d 
 dks1J |	 d 
 d	ks=J |	 d
 
 dksIJ |	 d 
 dksUJ |j d u s^J t }| D ]	}||  qet|dkswJ | j | | j  }|d}|jddgd|d | }t| dksJ |	 d 
 dksJ |	 d 
 dksJ |	 d
 
 dksJ |	 d 
 dksJ | j | | j  \}}|jddg|d | }|	 d 
 dksJ |	 d 
 dksJ | j | | j  \}}|jddgd|d | }|	 d 
 dks*J |	 d 
 dks7J | j | | j  }|d}t }|jddg|d}| }t| dkscJ |j d u smJ t }| D ]
}||  qtt|dksJ | j | t }| j  }|d}|jddg|d}| }t| dksJ |j d u sJ t }| D ]
}||  qt|dksJ | j   | j  }|d}|jddg|d}| }t| dks J |j d u s
J t }| D ]
}||  qt|dks%J d S )N   rS   rW   r  r   r   z	A (right)r#   z	B (right)r   r   rD   rc   F)r  
mark_rightr-   r0  )r-  r  r-   )r-  r  r  r-   )r9   Zfigureadd_subplotrs   ZmakeTimeDataFramer%   rW  rI   r'   Z	get_textsr   r  setaddru   r[   r:   ZmakeDataFrame)r+   r=   r-   r<   rX  colorsr  r/   r/   r0   test_secondary_legend]  s   










z TestTSPlot.test_secondary_legendc                 C   sz   t dddd}ttjt|d|}| j \}}|j|d}|	 }|
 D ]}t| dkr:| dks:J q(d S )	Nr}   r   re   r~   rD   rX   r   r   )r   r   r5   r6   r7   rI   r9   r:   r%   r   r   r   Zget_rotation)r+   r   r<   rl   r-   r   r  r/   r/   r0   test_format_date_axis  s   z TestTSPlot.test_format_date_axisc                 C   sX   t dddd}ttt|}| j \}}|j||dd}tt	|d 
 | d S )NrS  r2   rc   startr   r   Y)r>   r   )r   r&   r8   rI   r9   r:   r%   rs   r   r   r(   )r+   rT   rU   rl   r-   r  r/   r/   r0   test_ax_plot  s
   zTestTSPlot.test_ax_plotc           
      C   s  t dddt dddg}tddd}tdd	d}d
dd}| j \}}|jdd |D |fi | |jdd |D |fi | | \}}tjdd |D tjd}	t	
| d d df |	 tjdd |D tjd}	t	
| d d df |	 d S )N  r      i  r#   g      $@g      &@g      ?g      (@-r   )fmtZlwc                 S      g | ]}|  qS r/   	toordinalr   r/   r/   r0   r        z0TestTSPlot.test_mpl_nopandas.<locals>.<listcomp>c                 S   r  r/   r  r   r/   r/   r0   r    r  c                 S   r  r/   r  r   r/   r/   r0   r    r  ri  r   c                 S   r  r/   r  r   r/   r/   r0   r    r  )r   r5   r   r9   r:   Z	plot_dater'   rO   rm  rs   rE  r   )
r+   datesZvalues1Zvalues2kwrl   r-   line1line2expr/   r/   r0   test_mpl_nopandas  s   
 zTestTSPlot.test_mpl_nopandasc                 C   s   ddl m} t d d }|g d }| j \}}|d d j|d |dd  j|d | \}}|||j	
 d|ksCJ |||j	 d|ksQJ d S )Nr   DatetimeConverterr  r#   r   r   r   rZ  r3   r2   r   r;  r<  r  r\  r]  r   rX    r   r  rs   rt   r9   r:   r%   r   convertr    rc  rd  r+   r  r,   Zts_irregularrl   r-   r"  r!  r/   r/   r0    test_irregular_ts_shared_ax_xlim  s    z+TestTSPlot.test_irregular_ts_shared_ax_xlimc                 C   s   g d}g d}t d|d}t d|d}| j \}}|j|d | \}}|jd|d | \}	}
||	ks:J ||
k s@J d S )	N)r#   r   rD   r   )r   r   r   rZ  r#   r   r   rX   Tr  )r   r9   r:   r%   r   r+   Zindex_1Zindex_2r?  r@  rl   r-   left_beforeright_before
left_afterright_afterr/   r/   r0   test_secondary_y_non_ts_xlim  s   z'TestTSPlot.test_secondary_y_non_ts_xlimc                 C   s   t dddd}t dddd}td|d}td|d}| j \}}|j|d	 | \}}|jd
|d | \}	}
||	ks@J ||
k sFJ d S )N
2000-01-01r   rc   r  z
2000-01-05r#   r   r   rX   Tr  )r   r   r9   r:   r%   r   r  r/   r/   r0    test_secondary_y_regular_ts_xlim  s   z+TestTSPlot.test_secondary_y_regular_ts_xlimc           	      C   s   t dddd}td|d}| j \}}|j|d | \}}|d jd	|d
 | \}}||ks8J ||ks>J d S )Nr  r   rc  r~   r#   r   rX   rc   Tr  )r   r   r9   r:   r%   r   Zresamplemean)	r+   r   r,   rl   r-   r  r  r  r  r/   r/   r0   #test_secondary_y_mixed_freq_ts_xlim  s   z.TestTSPlot.test_secondary_y_mixed_freq_ts_xlimc                 C   s   ddl m} t d d }|g d }| j \}}|d d j|d |dd  jd|d |d d j|d | \}}|||j	
 d	|ksNJ |||j	 d	|ks\J d S )
Nr   r  r  r  r   rX   Tr  r  r  r  r/   r/   r0   "test_secondary_y_irregular_ts_xlim  s    z-TestTSPlot.test_secondary_y_irregular_ts_xlimc                 C   sZ   t dddt dddg}| j \}}|| tddddtddddg}|| d S )Ni  r#   r   r   )r   r9   r:   r%   r   )r+   rH   rl   r-   r/   r/   r0   test_plot_outofbounds_datetime.  s
   
z)TestTSPlot.test_plot_outofbounds_datetimec                 C   s   dd t dD }tdddd}tt jt|d|}| j \}}|j	d|d	 | j
  | }d
d |D }t|t|ksEJ ||ksKJ d S )Nc                 S   s   g | ]}d |dqS )z00:00:00.0000000z0>2dr/   )r  rP   r/   r/   r0   r  8  s    zATestTSPlot.test_format_timedelta_ticks_narrow.<locals>.<listcomp>r2   0nsr~   rD   r   r4   c                 S   r  r/   r   r   r/   r/   r0   r  A  r  )r5   r   r   r   r6   r7   rI   r9   r:   r%   drawr;   r+   Zexpected_labelsr   r<   r=   r-   r  Zresult_labelsr/   r/   r0   "test_format_timedelta_ticks_narrow7  s   
z-TestTSPlot.test_format_timedelta_ticks_narrowc                 C   s   g d}t dddd}ttjt|d|}| j \}}|jd|d}| j	  |
 }d	d
 |D }t|t|ks?J ||ksEJ d S )N)	z00:00:00z1 days 03:46:40z2 days 07:33:20z3 days 11:20:00z4 days 15:06:40z5 days 18:53:20z6 days 22:40:00z8 days 02:26:40z9 days 06:13:20r  r2   1 dr~   rD   r   r4   c                 S   r  r/   r  r   r/   r/   r0   r  Y  r  z?TestTSPlot.test_format_timedelta_ticks_wide.<locals>.<listcomp>)r   r   r5   r6   r7   rI   r9   r:   r%   r  r;   r  r/   r/   r0    test_format_timedelta_ticks_wideE  s   
z+TestTSPlot.test_format_timedelta_ticks_widec                 C   s   t tdtddd}| j \}}t|j|d tdddd}t tj	t
||}| j \}}t|j|d tddd	d}t tj	t
||}| j \}}t|j|d d S )
Nr   Z1dayr   rX   z1 day 2 hr 30 min 10 sr2   r  r~   z1 ns)r   r8   r   r9   r:   r$   r%   r5   r6   r7   rI   )r+   ry   rl   r-   r    r/   r/   r0   test_timedelta_plot]  s   zTestTSPlot.test_timedelta_plotc                 C   s`   t dddd}|}tddd}tdddd d d }| j \}}|j||g||gd	 d S )
Nr   r2   r   r~   r   r#   g?r"   )weights)r   r5   r   r9   r:   hist)r+   r   rT   Zw1Zw2rl   r-   r/   r/   r0   	test_histo  s   zTestTSPlot.test_histc                 C   s   t g dtdddtdddtdddgd}t g dtdddtd	ddtd
ddgd}| j \}}|j|d |j|d |j|d d S )NrN   r   r   r  r   i  r   i  i  r  rX   )r   r   r9   r:   r%   )r+   r?  r@  rl   r-   r/   r/   r0   test_overlapping_datetimex  s$   





z$TestTSPlot.test_overlapping_datetimez1GH9053 matplotlib does not use ax.xaxis.converterc                 C   s   t tjdtdddd}| }tt |j|j	|j
dd W d    n1 s,w   Y  |j\}}t| |  d S )Nr2   z
1970-01-02r   r   r=  )rv   )r   r5   r6   r7   r   r%   rs   Zassert_produces_warningDeprecationWarningr    rH   r  rE  r   )r+   ry   r-   l1l2r/   r/   r0   test_add_matplotlib_datetime64  s   
z)TestTSPlot.test_add_matplotlib_datetime64c                 C   s~   t tjdddddgd}tdddd	|d
< | j \}}|jd
d|d | j	  |
 d }d}| |ks=J d S )Nr   r2   r   rT   rU   r4  z
2018-01-01rc   r~   r   )rT   rU   r   )r   r5   r6   ZRandomStaterp  r   r9   r:   Zscatterr  r;   r   )r+   r<   r=   r-   r>   r   r/   r/   r0   "test_matplotlib_scatter_datetime64  s    
z-TestTSPlot.test_matplotlib_scatter_datetime64c                 C   s   t g d}t|g dd}|jddd}| j|dd t g d}t|g dd}|jddd}| j|d	d |djdd
d}| j|d	d |djddd}| j|dd |jddd
d
d}| j|d	d |jddd
dd}| j|dd d S )N)
2020-05-01
2020-05-02z
2020-05-03rN   )rT   rU   rT   rU   r   )Zxrot)r  r  z
2020-05-04r   T)rU   Z	use_indexF)rT   rU   r:   ra  )r   r   r%   Z_check_ticks_propsZ	set_index)r+   rT   r<   r   r/   r/   r0   test_check_xticks_rot  s    z TestTSPlot.test_check_xticks_rotN)___name__
__module____qualname__r\   markfilterwarningsr1   r?   rM   rR   r`   Zparametrizerm   rn   rw   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   Zxfailr   r   r   r   r   r   r   r   r   r   r   r   r   r   r  Zslowr
  r  r  r  r*  r+  tdZskip_if_no_scipyr/  r1  r7  r8  rC  rH  rK  rL  rR  rU  rY  r_  rb  re  rg  rn  rq  rs  rt  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r/   r/   r/   r0   r   -   s    









	

	
		(


3
		 [)[

		
r   c              	   O   s  dd l m} | }z|  |d}|d| }t|dd }	| |i |}
|
d us/J |d| }|d urR|jj	}t
|trG|j}|	d u rR|j	|ksRJ |d ura|	d u ra|j	|ksaJ |d}||d< | |i |}
|
d uswJ tjdd}|| W d    n1 sw   Y  tjdd}t|| W d    n1 sw   Y  W || d S W || d S || w )Nr   r  r-   r      T)Zreturn_filelike)Zmatplotlib.pyplotZpyplotZgcfZclfr  popZgcagetattrr    r   r  r   r   rs   Zensure_cleanZsavefigpickledumpr[   )fr   Zseriesargskwargsr9   r=   r-   Zorig_axZorig_axfreqr   Zdfreqpathr/   r/   r0   r$     s>   


r$   )NN),__doc__r   r   r   r   r  numpyr5   r\   Zpandas._libs.tslibsr   r   Zpandas.util._test_decoratorsutilZ_test_decoratorsr  Zpandasr   r	   r
   r   r   r   r   Zpandas._testingZ_testingrs   Zpandas.core.indexes.datetimesr   r   r   Zpandas.core.indexes.periodr   r   r   Zpandas.core.indexes.timedeltasr   Zpandas.tests.plotting.commonr   Zpandas.tseries.offsetsr   Zskip_if_no_mplr   r$   r/   r/   r/   r0   <module>   s8    $	           "