a
    j=ic4                     @   sJ  d dl mZm Z  d dlZd dlZd dlZd dlZd dlm  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 d dlmZmZm Z m!Z! zd dl"m#Z# W n e$y   Y n0 e%d e%dZ&d	d
 Z'dd Z(G dd dZ)G dd dZ*G dd dZ+G dd dZ,ej-.dg ddd Z/dS )    )datedatetimeN)IndexPeriodPeriodIndexSeries	Timestamparrays
date_range) deregister_matplotlib_convertersregister_matplotlib_converters)DayMicroMilliSecond)	convertermatplotlib.pyplotmatplotlib.datesc                  C   s   d} t jd| g}t| d S )Nzimport matplotlib.units as units; import matplotlib.dates as mdates; n_conv = len(units.registry); import pandas as pd; pd.plotting.register_matplotlib_converters(); pd.plotting.deregister_matplotlib_converters(); assert len(units.registry) == n_conv-c)sys
executable
subprocesscheck_output)codecall r   u/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/pandas/tests/plotting/test_converter.pytest_registry_mpl_resets0   s    	r   c                   C   s   t dt dksJ d S )Nz00:01)r   Ztime2numr   r   r   r   test_timtetonum_accepts_unicode?   s    r   c                   @   sX   e Zd Zdd Zejddddd Zdd	 Zd
d Zejddddd Z	dd Z
dS )TestRegistrationc                 C   s&   d}t jd|g}t|dks"J d S )Nzwimport matplotlib.units; import pandas as pd; units = dict(matplotlib.units.registry); assert pd.Timestamp not in unitsr   r   )r   r   r   
check_call)selfr   r   r   r   r   test_dont_register_by_defaultD   s    z.TestRegistration.test_dont_register_by_defaultZ
matplotlibz3.1.3)min_versionc                 C   sP   t d}ttdtdddd}| \}}t  ||j|j	 |
  d S )Nr      2017Zperiodsindex)pytestimportorskipr   ranger
   subplotsr   plotr(   valuesclose)r!   plts_axr   r   r   test_registering_no_warningO   s    
z,TestRegistration.test_registering_no_warningc                 C   s   t d}ttdtdddd}td }|  W d    n1 sJ0    Y  zt|dksfJ W |	  n
|	  0 d S )Nr   r$   r%   r&   r'   r   )
r)   r*   r   r+   r
   tmZassert_produces_warningr-   lenr/   )r!   r0   r1   wr   r   r   test_pandas_plots_registerZ   s    
&z+TestRegistration.test_pandas_plots_registerc              	   C   s   t d}tddX tdd t|jvs4J W d    n1 sH0    Y  t|jv s`J W d    n1 st0    Y  d S )Nmatplotlib.units'plotting.matplotlib.register_convertersTF)r)   r*   cfoption_contextr   registry)r!   unitsr   r   r   test_matplotlib_formattersf   s
    
,z+TestRegistration.test_matplotlib_formattersc                 C   s   t d tdd}t d}ttdtdddd}| \}}|  ||j	|j
 W d    n1 sn0    Y  t  |  ||j	|j
 W d    n1 s0    Y  |  d S )Nr   r:   Fr$   r%   r&   r'   )r)   r*   r;   r<   r   r+   r
   r,   r-   r(   r.   r   r/   )r!   ctxr0   r1   r2   r3   r   r   r   test_option_no_warningr   s    

..z'TestRegistration.test_option_no_warningc              
   C   s   t d}t d}t|j}z|j  | }||jt< ||jt< t  |jt |us^J t	  |jt |u svJ W |j  |
 D ]\}}||j|< qn(|j  |
 D ]\}}||j|< q0 d S )Nr9   r   )r)   r*   dictr=   clearZDateConverterr   r   r   r   items)r!   r>   datesoriginalZdate_converterkvr   r   r   test_registry_resets   s$    







z%TestRegistration.test_registry_resetsN)__name__
__module____qualname__r"   tdZ
skip_if_nor4   r8   r?   rA   rI   r   r   r   r   r   C   s   


r   c                   @   s   e Zd Zej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ddd Zej
de e edgdd Zdd ZdS )TestDateTimeConverterc                 C   s   t  S N)r   ZDatetimeConverterr!   r   r   r   dtc   s    zTestDateTimeConverter.dtcc                 C   s0   | dd d }| dd d }||ks,J dd S )Nz12:22z/DatetimeConverter.convert should accept unicodeconvert)r!   rQ   r1r2r   r   r   test_convert_accepts_unicode   s    z2TestDateTimeConverter.test_convert_accepts_unicodec                 C   s  | dgd d d }ttddd}||ks2J | dd d }||ksLJ | tdddd d }||ksnJ | dd d }||ksJ | tdd d }||ksJ | dd d }||ksJ | dd d }||ksJ | tddgd d }|d |ksJ tdd	d	}| |d d }||ks4J | |
 d d }||ksTJ | t|td |gd d }|d |ksJ | t|td |g
 d d }|d |ksJ d S )
N2012-1-1r        
2012-01-012012-01-01 00:00:00+0000z2012-01-02 00:00:00+0000UTCz
US/Eastern)rS   rE   date2numr   r   r   nparrayZtz_localizeZ
tz_convertZto_pydatetimer   r   )r!   rQ   rsxptsr   r   r   test_conversion   s<    "z%TestDateTimeConverter.test_conversionc              	   C   s   d}| tdddd d }tjtddd}tj|||d | tdddd d }tj|||d | tdd	d	d	d
dd d }tj|||d d S )Ng&.>z2012-1-1 01:02:03r\   )tzrtolz2012-1-1 09:02:03zAsia/Hong_KongrX   rY         )rS   r   r   rE   r]   r5   assert_almost_equalr   )r!   rQ   rf   r`   ra   r   r   r   test_conversion_float   s    z+TestDateTimeConverter.test_conversion_floatc                 C   s   t dddt dddg}||d d }tj|}t|| ||d d d }tj|d }||kslJ tddddtddddg}||d d }tj|}t|| ||d d d }tj|d }||ksJ d S )Ni  rY   rg   r   r$   )r   rS   r   rE   r]   r5   Zassert_numpy_array_equalr   )r!   rQ   r.   r`   ra   r   r   r   $test_conversion_outofbounds_datetime   s    z:TestDateTimeConverter.test_conversion_outofbounds_datetimeztime,format_expected))r   z00:00)g@z23:59:59.999999)i_ z01:00)i  z01:02:03)gfffffe@z11:02:03.200c                 C   s   t d |}||ksJ d S rO   )r   ZTimeFormatter)r!   timeformat_expectedresultr   r   r   test_time_formatter   s    z)TestDateTimeConverter.test_time_formatterfreq)BLSc                 C   sD   d}t jd|d}||d d }tj| }t j|||d d S )Ng&.>
   )rG   rp   re   )r5   ZmakeDateIndexrS   r   rE   r]   Z	_mpl_reprri   )r!   rp   rQ   rf   Z	dateindexr`   ra   r   r   r   test_dateindex_conversion  s
    z/TestDateTimeConverter.test_dateindex_conversionoffset2   c                 C   sL   t d}|| }||d d }||d d }||k sHt| d| dd S )NrW   z is not less than .)r   rS   AssertionError)r!   rv   rQ   Zts1Zts2Zval1Zval2r   r   r   test_resolution  s    z%TestDateTimeConverter.test_resolutionc                    sR   t dt dg}||g} |d d } fdd|D }t||k sNJ d S )Nz
2017-01-01z
2017-01-02c                    s   g | ]}  |d d qS rO   rR   .0xrQ   r   r   
<listcomp>      z=TestDateTimeConverter.test_convert_nested.<locals>.<listcomp>)r   rS   r^   r_   all)r!   rQ   innerdatarn   expectedr   r~   r   test_convert_nested  s
    z)TestDateTimeConverter.test_convert_nestedN)rJ   rK   rL   r)   ZfixturerQ   rV   rc   rj   rk   markparametrizero   ru   r   r   r   rz   r   r   r   r   r   rN      s    
.




rN   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )TestPeriodConverterc                 C   s,   t  | _G dd d}| | _d| j_d S )Nc                   @   s   e Zd ZdS )z.TestPeriodConverter.setup_method.<locals>.AxisN)rJ   rK   rL   r   r   r   r   Axis%  s   r   D)r   ZPeriodConverterpcaxisrp   )r!   r   r   r   r   setup_method"  s    
z TestPeriodConverter.setup_methodc                 C   s4   | j dd | j}| j dd | j}||ks0J d S )NrW   r   rS   r   r!   rT   rU   r   r   r   rV   +  s    z0TestPeriodConverter.test_convert_accepts_unicodec                 C   s^  | j dgd | jd }tdj}||ks.J | j dd | j}||ksLJ | j tdddgd | jd }||ksxJ | j tdddd | j}||ksJ | j tdgd | jd }||ksJ | j tdd | j}||ksJ | j dd | j}||ksJ | j dd | j}||ks(J | j tjddgd	d
d | j}|d |ksZJ d S )NrW   r   rX   rY   rZ   r[   z2012-01-01 00:00:00z2012-01-02 00:00:00zdatetime64[ns])Zdtype)	r   rS   r   r   Zordinalr   r   r^   r_   r!   r`   ra   r   r   r   rc   0  s4    
 z#TestPeriodConverter.test_conversionc                 C   s.   | j ddgd | j}ddg}||ks*J d S )Nr   rY   r   r   r   r   r   test_integer_passthroughT  s    z,TestPeriodConverter.test_integer_passthroughc                    sF   ddg j   gd j} fddtdD }||ksBJ d S )NrW   z2012-1-2c                    s   g | ]}j  d jqS rO   r   )r|   r2   r   r!   r   r   r   ]  r   z;TestPeriodConverter.test_convert_nested.<locals>.<listcomp>rg   )r   rS   r   r+   r   r   r   r   r   Z  s    z'TestPeriodConverter.test_convert_nestedN)rJ   rK   rL   r   rV   rc   r   r   r   r   r   r   r   !  s
   	$r   c                   @   sD   e Zd ZdZejdg ddd Zejdddgd	d
 ZdS )TestTimeDeltaConverterzTest timedelta converterzx, decimal, format_expected))        r   z00:00:00)l    xqAsrY   z
01:06:12.3)l    62" rg   z8 days 06:07:13.43)l    KVu   z09:00:23.4320c                 C   s&   t j}|j|d |d}||ks"J d S )N)posZ
n_decimals)r   TimeSeries_TimedeltaFormatterZformat_timedelta_ticks)r!   r}   decimalrm   tdcrn   r   r   r   test_format_timedelta_ticksd  s    
z2TestTimeDeltaConverter.test_format_timedelta_ticksview_interval)rY   rg   )rg   rY   c                    s8   G  fddd}t  }||d|  |dd d S )Nc                       s   e Zd Z fddZdS )zNTestTimeDeltaConverter.test_call_w_different_view_intervals.<locals>.mock_axisc                    s    S rO   r   rP   r   r   r   get_view_intervalv  s    z`TestTimeDeltaConverter.test_call_w_different_view_intervals.<locals>.mock_axis.get_view_intervalN)rJ   rK   rL   r   r   r   r   r   	mock_axisu  s   r   r   r   r   )r   r   setattr)r!   r   Zmonkeypatchr   r   r   r   r   $test_call_w_different_view_intervalsr  s    z;TestTimeDeltaConverter.test_call_w_different_view_intervalsN)	rJ   rK   rL   __doc__r)   r   r   r   r   r   r   r   r   r   a  s   	
r   	year_span)	g     &@   P      i  i   i  i	  i  c                 C   s  d}|| d  }|| d }|dk r(d S |d }t |\}}t ||d}ttjtdd |D dd}td	d |D }	td
d |D }
||	 }||
 }|j| dk}|j| dk}|j	dk}|j	dk}t
|sJ t
|sJ t
|sJ t
|sJ d S )Nir   rY   -   Qc                 S   s   g | ]}|d  qS )r   r   r{   r   r   r   r     r   z)test_quarterly_finder.<locals>.<listcomp>)rp   c                 S   s   g | ]}|d  qS )rY   r   r{   r   r   r   r     r   c                 S   s   g | ]}|d  qS )rg   r   r{   r   r   r   r     r   r   )r   Z_get_default_annual_spacingZ_quarterly_finderr   r	   ZPeriodArrayr^   r_   yearZquarterr   )r   ZvminZvmaxspanZnyearsZ
min_anndefZ
maj_anndefrn   ZquartersZmajorsZminorsZmajor_quartersZminor_quartersZcheck_major_yearsZcheck_minor_yearsZcheck_major_quartersZcheck_minor_quartersr   r   r   test_quarterly_finder~  s.    

r   )0r   r   r   r   numpyr^   r)   Zpandas._config.config_configconfigr;   Zpandas.util._test_decoratorsutilZ_test_decoratorsrM   Zpandasr   r   r   r   r   r	   r
   Zpandas._testingZ_testingr5   Zpandas.plottingr   r   Zpandas.tseries.offsetsr   r   r   r   Zpandas.plotting._matplotlibr   ImportErrorr*   rE   r   r   r   rN   r   r   r   r   r   r   r   r   r   <module>   s2   $	

[ @