o
    d3                     @   s8  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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w 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   i/var/www/html/visualizacion-main/env/lib/python3.10/site-packages/pandas/tests/plotting/test_converter.pytest_registry_mpl_resets.   s   	r   c                   C   s   t dt dksJ d S )Nz00:01)r   time2numr   r   r   r   test_timtetonum_accepts_unicode=   s   r   c                   @   s<   e Zd Zdd Zdd Zdd Zdd Z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_defaultB   s   z.TestRegistration.test_dont_register_by_defaultc                 C   sP   t d}ttdtdddd}| \}}t  ||j|j	 |
  d S )Nr      2017periodsindex)pytestimportorskipr   ranger
   subplotsr   plotr)   valuesclose)r"   plts_axr   r   r   test_registering_no_warningM   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 s%w   Y  zt|dks3J W |	  d S |	  w )Nr   r$   r%   r&   r(   r   )
r*   r+   r   r,   r
   tmassert_produces_warningr.   lenr0   )r"   r1   r2   wr   r   r   test_pandas_plots_registerW   s   

z+TestRegistration.test_pandas_plots_registerc              	   C   s   t d}tdd- tdd t|jvsJ W d    n1 s$w   Y  t|jv s0J W d    d S 1 s;w   Y  d S )Nmatplotlib.units'plotting.matplotlib.register_convertersTF)r*   r+   cfoption_contextr   registry)r"   unitsr   r   r   test_matplotlib_formattersc   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 s7w   Y  t  | ||j	|j
 W d    n1 sTw   Y  |  d S )Nr   r<   Fr$   r%   r&   r(   )r*   r+   r=   r>   r   r,   r
   r-   r.   r)   r/   r   r0   )r"   ctxr1   r2   r3   r4   r   r   r   test_option_no_warningo   s   

z'TestRegistration.test_option_no_warningc              
   C   s   t d}t d}t|j}zA|j  | }||jt< ||jt< t  |jt |us/J t	  |jt |u s;J W |j  |
 D ]	\}}||j|< qEd S |j  |
 D ]	\}}||j|< qZw )Nr;   r   )r*   r+   dictr?   clearDateConverterr   r   r   r   items)r"   r@   datesoriginaldate_converterkvr   r   r   test_registry_resets   s(   







z%TestRegistration.test_registry_resetsN)	__name__
__module____qualname__r#   r5   r:   rA   rC   rM   r   r   r   r   r    A   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      t  S N)r   DatetimeConverterr"   r   r   r   dtc      zTestDateTimeConverter.dtcc                 C   s0   | dd d }| dd d }||ksJ dd S )Nz2000-01-01 12:22z/DatetimeConverter.convert should accept unicodeconvert)r"   rV   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sJ | dd d }||ks&J | tdddd d }||ks7J | dd d }||ksDJ | tdd d }||ksSJ | dd d }||ks`J | dd d }||ksmJ | tddgd d }|d |ksJ tdd	d	}| |d d }||ksJ | |
 d d }||ksJ | 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)rY   rH   date2numr   r   r   nparraytz_localize
tz_convertto_pydatetimer   r   )r"   rV   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:03rb   )tzrtolz2012-1-1 09:02:03zAsia/Hong_Kongr^   r_         )rY   r   r   mdatesrc   r6   assert_almost_equalr   )r"   rV   ro   ri   rj   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s6J tddddtddddg}||d d }tj|}t|| ||d d d }tj|d }||ksnJ d S )Ni  r_   rp   r   r$   )r   rY   r   rr   rc   r6   assert_numpy_array_equalr   )r"   rV   r/   ri   rj   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 rS   )r   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&.>
   )rK   r|   rn   )r6   makeDateIndexrY   r   rr   rc   	_mpl_reprrs   )r"   r|   rV   ro   	dateindexri   rj   r   r   r   test_dateindex_conversion  s
   z/TestDateTimeConverter.test_dateindex_conversionoffset2   c                 C   sL   t d}|| }||d d }||d d }||k s$t| d| dd S )Nr]   z is not less than .)r   rY   AssertionError)r"   r   rV   ts1ts2val1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 s'J d S )Nz
2017-01-01z
2017-01-02c                    s   g | ]	}  |d d qS rS   rX   .0xrV   r   r   
<listcomp>      z=TestDateTimeConverter.test_convert_nested.<locals>.<listcomp>)r   rY   rd   re   all)r"   rV   innerdatarz   expectedr   r   r   test_convert_nested  s
   z)TestDateTimeConverter.test_convert_nestedN)rN   rO   rP   r*   fixturerV   r\   rl   rt   rv   markparametrizer{   r   r   r   r   r   r   r   r   r   r   rQ      s"    
.




rQ   c                   @   sH   e Zd Zejdd Zejdd Zdd Zdd Zd	d
 Z	dd Z
dS )TestPeriodConverterc                 C   rR   rS   )r   PeriodConverterrU   r   r   r   pc  rW   zTestPeriodConverter.pcc                 C   s   G dd d}| }d|_ |S )Nc                   @   s   e Zd ZdS )z&TestPeriodConverter.axis.<locals>.AxisN)rN   rO   rP   r   r   r   r   Axis$  s    r   Dr|   )r"   r   axisr   r   r   r   "  s   zTestPeriodConverter.axisc                 C   s,   | dd |}| dd |}||ksJ d S )Nr]   rX   r"   r   r   rZ   r[   r   r   r   r\   +  s   z0TestPeriodConverter.test_convert_accepts_unicodec                 C   s4  | dgd |d }tdj}||ksJ | dd |}||ks"J | tdddgd |d }||ks6J | tdddd |}||ksGJ | tdgd |d }||ksYJ | tdd |}||kshJ | dd |}||ksuJ | dd |}||ksJ | tjddgd	d
d |}|d |ksJ d S )Nr]   r   r^   r_   r`   ra   z2012-01-01 00:00:00z2012-01-02 00:00:00zdatetime64[ns])dtype)rY   r   ordinalr   r   rd   re   r"   r   r   ri   rj   r   r   r   rl   0  s4   
z#TestPeriodConverter.test_conversionc                 C   s*   | ddgd |}ddg}||ksJ d S )Nr   r_   rX   r   r   r   r   test_integer_passthroughT  s   z,TestPeriodConverter.test_integer_passthroughc                    sD   ddg gd  } fddtdD }||ks J d S )Nr]   z2012-1-2c                    s   g | ]	} d  qS rS   rX   )r   r3   r   r   r   r   r   r   ]  r   z;TestPeriodConverter.test_convert_nested.<locals>.<listcomp>rp   )rY   r,   r   r   r   r   r   Z  s   z'TestPeriodConverter.test_convert_nestedN)rN   rO   rP   r*   r   r   r   r\   rl   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r_   z
01:06:12.3)l    62" rp   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)pos
n_decimals)r   TimeSeries_TimedeltaFormatterformat_timedelta_ticks)r"   r   decimalry   tdcrz   r   r   r   test_format_timedelta_ticksd  s   
z2TestTimeDeltaConverter.test_format_timedelta_ticksview_interval)r_   rp   )rp   r_   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 rS   r   rU   r   r   r   get_view_intervalv  s   z`TestTimeDeltaConverter.test_call_w_different_view_intervals.<locals>.mock_axis.get_view_intervalN)rN   rO   rP   r   r   r   r   r   	mock_axisu  s    r   r   r   r   )r   r   setattr)r"   r   monkeypatchr   r   r   r   r   $test_call_w_different_view_intervalsr  s   z;TestTimeDeltaConverter.test_call_w_different_view_intervalsN)	rN   rO   rP   __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
|srJ t
|syJ t
|sJ t
|sJ d S )Nir   r_   -   Qc                 S      g | ]}|d  qS )r   r   r   r   r   r   r         z)test_quarterly_finder.<locals>.<listcomp>r   c                 S   r   )r_   r   r   r   r   r   r     r   c                 S   r   )rp   r   r   r   r   r   r     r   r   )r   _get_default_annual_spacing_quarterly_finderr   r	   PeriodArrayrd   re   yearquarterr   )r   vminvmaxspannyears
min_anndef
maj_anndefrz   quartersmajorsminorsmajor_quartersminor_quarterscheck_major_yearscheck_minor_yearscheck_major_quarterscheck_minor_quartersr   r   r   test_quarterly_finder~  s.   

r   ),r   r   r   r   numpyrd   r*   pandas._config.config_configconfigr=   pandasr   r   r   r   r   r	   r
   pandas._testing_testingr6   pandas.plottingr   r   pandas.tseries.offsetsr   r   r   r   pandas.plotting._matplotlibr   ImportErrorr+   rH   r   r   r    rQ   r   r   r   r   r   r   r   r   r   <module>   s4    $	

Y D