U
    f/eUo                    @   s  d Z ddlZddlmZ ddlmZmZ ddlmZ ddlZddl	m
Z
 ddlmZ ddlZddlZddlZddlmZ dd	lmZmZ dd
lmZmZ ddlm  mZ ddlmZ ddlZ ddlm!Z!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/m0Z1 ddl2m3Z3 G dd dZ4G dd dZ5G dd dZ6G dd dZ7G dd dZ8G dd dZ9G dd dZ:G dd dZ;ej<d d!d"d#d$gd%d&d' Z=ej<d(d) Z>ej<d*d+ Z?ej<d,d-d.d/gd%d0d1 Z@ej<d2d3 ZAG d4d5 d5ZBejCDd6d7d8d9d:d;d<d=d>d?dg
d@fd7d7d7d7d:d;d<d=d>d?g
dAfgdBdC ZEejCDdDdEdFgdGdH ZFdIdJ ZGejCDdKejHeIgdLdM ZJdNdO ZKdPdQ ZLdS )Rz test to_datetime     N)deque)datetime	timedelta)Decimalparse)tzoffset)tslib)iNaTparsing)OutOfBoundsDatetimeOutOfBoundsTimedelta)is_datetime64_ns_dtype)		DataFrameDatetimeIndexIndexNaTSeries	Timestamp
date_rangeisnato_datetime)DatetimeArray)	datetimes)start_caching_atc                   @   s  e Zd Zejdddgdd Zejdddgdd Zejdddgd	d
 Zejddddgdde	j
gddegdddgdddgdde	j
gddegdddggdd Zejdede	j
ddgeede	j
e	j
e	j
ggeddde	j
geede	j
e	j
e	j
ggede	j
ddgeede	j
e	j
e	j
ggedde	j
dgeede	j
e	j
e	j
gggdd Zejdddgdd Zejdd ed!d"d#gd$ed%d&d'gd(d(gd)d)gd*d*gd+d+ggd,d- Zejdddgd.d/ Zejdddgd0d1 Zejejdddgd2d3 Zejdddgd4d5 Zejdddgd6d7 Zejd8d9d:gd; ed<d=d>gd; gd9d:d?d@ged<d=d>ed<dAd>ed<dBd>ggdCdDgd; ed<edEdFgd; gdGdHgd; ed<edEdFgd; gdGdHdIged<edEdFed<edJdFggdGdKdKged<edLdFed<edLdFgggdMdN ZdOdP ZejdQdRdSdTdUdVdWgdXdY ZdZd[ ZdS )\TestTimeConversionFormatsreadonlyTFc                 C   s>   t jg td}|r|jdd t|}tg }t|| d S )NdtypeF)write)nparrayobjectZsetflagsr   tmassert_index_equal)selfr   arrresultexpected r)   G/tmp/pip-unpacked-wheel-tiezk1ph/pandas/tests/tools/test_to_datetime.pytest_to_datetime_readonly2   s    z3TestTimeConversionFormats.test_to_datetime_readonlycachec                 C   s"  dddg}t dt dt dg}t dt dt dg}|t|t|fft|t|t|ff|d	 |d	 |d	 ff|d
 |d
 |d
 ff|d |d |d fffD ]x\}}tddgD ]b\}}t|||d}	|| }
t|
trt|	t|
 qt|
t r|	|
kstqt	|	|
 qqd S )N1/1/20001/2/20001/3/200020000101Z20000201Z20000301Z20000102Z20000103r         z%d/%m/%Y%m/%d/%Yformatr,   )
r   r   r   	enumerater   
isinstancer#   assert_series_equalAssertionErrorr$   )r%   r,   valuesZresults1Zresults2vals	expectedsifmtr'   r(   r)   r)   r*   test_to_datetime_format<   s"    

z1TestTimeConversionFormats.test_to_datetime_formatc                 C   sj  t ddgdgd  }t dd |tD }t|d|d}t|| t|td|d}t|| t tdtdgtd	gd  }tj|d
< tj|d
< t|d|d}t|| |t}d|d
< t|d|d}t|| t dddg}t|dd|d}t t	dddt	dddt	dddgt
d}t|| t|dd|d}t dddgdd}t|| d S )N$.i9G.   c                 S   s   g | ]}t |qS r)   r   .0xr)   r)   r*   
<listcomp>X   s     zNTestTimeConversionFormats.test_to_datetime_format_YYYYMMDD.<locals>.<listcomp>%Y%m%dr4   19801222Z19810105r2   Znati3iT3iignorer5   errorsr,             i'  r   coerceZ20121231Z20141231r   M8[ns])r   applystrr   r#   r8   r   r    nanr   r"   r%   r,   sr(   r'   r)   r)   r*    test_to_datetime_format_YYYYMMDDU   s6    


 z:TestTimeConversionFormats.test_to_datetime_format_YYYYMMDDinput_srH   20010112Nr   r@   iT1c                 C   s6   t tdtdtg}t t|dd}t|| d S )NrH   rY   rG   r5   )r   r   r   r   r#   r8   r%   rX   r(   r'   r)   r)   r*   *test_to_datetime_format_YYYYMMDD_with_none~   s    zDTestTimeConversionFormats.test_to_datetime_format_YYYYMMDD_with_nonezinput_s, expectedZ20010012Z10019999i]4iT1i{1Z20190813c                 C   s   t |ddd}t|| d S )NrG   rP   r5   rK   )r   r#   r8   r[   r)   r)   r*   )test_to_datetime_format_YYYYMMDD_overflow   s    zCTestTimeConversionFormats.test_to_datetime_format_YYYYMMDD_overflowc                 C   s   t dddg}t dd |tD }t|d|d}t|| t dd	d
g}t dd |tD }t|d|d}t|| d S )N    i  c                 S   s   g | ]}t |qS r)   rB   rC   r)   r)   r*   rF      s     zMTestTimeConversionFormats.test_to_datetime_format_integer.<locals>.<listcomp>z%Yr4   iA i i c                 S   s,   g | ]$}t |d d d |dd   qS )N   -rB   rC   r)   r)   r*   rF      s     z%Y%m)r   rR   rS   r   r#   r8   rU   r)   r)   r*   test_to_datetime_format_integer   s    z9TestTimeConversionFormats.test_to_datetime_format_integerzint_date, expectedi3rL   
      i i     ra   iuwi(3iA iI  c                 C   s   t |ddd}||kstd S )NrG   rI   r]   r   r9   )r%   Zint_dater(   r'   r)   r)   r*   .test_int_to_datetime_format_YYYYMMDD_typeerror   s    zHTestTimeConversionFormats.test_int_to_datetime_format_YYYYMMDD_typeerrorc           	      C   sP   t  \}}tjd }d| d}d}t|||d}t||}||ksLtd S )Nra   z01-z-2011 00:00:01.978z%d-%b-%Y %H:%M:%S.%fr4   )locale	getlocalecalendar
month_abbrr   r   strptimer9   )	r%   r,   lang_rl   valr5   r'   expr)   r)   r*   #test_to_datetime_format_microsecond   s    
z=TestTimeConversionFormats.test_to_datetime_format_microsecondc                 C   sR   ddt dgddt dgddt d	gg}|D ] \}}}t|||d
|ks,tq,d S )Nz01/10/2010 15:20z%m/%d/%Y %H:%Mz2010-01-10 15:20z01/10/2010 05:43z%m/%d/%Y %I:%Mz2010-01-10 05:43z01/10/2010 13:56:01z%m/%d/%Y %H:%M:%Sz2010-01-10 13:56:01r4   r   r   r9   r%   r,   datarV   r5   dtr)   r)   r*   test_to_datetime_format_time   s    z6TestTimeConversionFormats.test_to_datetime_format_timec                 C   sJ   t ddddg}t|dd|d}t|jjddd	d|d
}t|| d S )NZ19MAY11Zfoobar19MAY11z19MAY11:00:00:00z19MAY11 00:00:00Zz%d%b%yF)r5   exactr,   z(\d+\w+\d+))expandr4   )r   r   rS   extractr#   r8   )r%   r,   rV   r'   r(   r)   r)   r*   test_to_datetime_with_non_exact   s    
  z9TestTimeConversionFormats.test_to_datetime_with_non_exactc                 C   s4   dD ]*}t ||d}t |d|d}||kstqd S )N)z2012-01-01 09:00:00.000000001z2012-01-01 09:00:00.000001z2012-01-01 09:00:00.001z2012-01-01 09:00:00.001000z2012-01-01 09:00:00.001000000r,   %Y-%m-%d %H:%M:%S.%fr4   rg   )r%   r,   vr(   r'   r)   r)   r*   #test_parse_nanoseconds_with_formula	  s    z=TestTimeConversionFormats.test_parse_nanoseconds_with_formulac                 C   sF   ddt dgddt dgg}|D ] \}}}t|||d|ks tq d S )NZ2009324z%Y%W%wz
2009-08-13Z2013020z%Y%U%wz
2013-01-13r4   rs   rt   r)   r)   r*   test_to_datetime_format_weeks  s
    z7TestTimeConversionFormats.test_to_datetime_format_weekszfmt,dates,expected_datesz%Y-%m-%d %H:%M:%S %Zz2010-01-01 12:00:00 UTCr2   2010-01-01 12:00:00UTCtzz2010-01-01 12:00:00 GMTz2010-01-01 12:00:00 US/PacificGMT
US/Pacificz%Y-%m-%d %H:%M:%S%zz2010-01-01 12:00:00+0100<   tzinfo%Y-%m-%d %H:%M:%S %z2010-01-01 12:00:00 +01002010-01-01 12:00:00 -0100i2010-01-01 12:00:00 Zr   c                 C   s$   t ||d}t|}t|| d S NrZ   )r   r   r#   assert_equal)r%   r>   datesexpected_datesr'   r(   r)   r)   r*   )test_to_datetime_parse_tzname_or_tzoffset"  s    5zCTestTimeConversionFormats.test_to_datetime_parse_tzname_or_tzoffsetc                 C   sB   ddddg}ddddg}d	}t ||d
d}t|}t|| d S )Nr   r   z2010-01-01 12:00:00 +0300z2010-01-01 12:00:00 +0400z2010-01-01 11:00:00+00:00z2010-01-01 13:00:00+00:00z2010-01-01 09:00:00+00:00z2010-01-01 08:00:00+00:00r   T)r5   utcr   r   r#   r$   )r%   r   r   r>   r'   r(   r)   r)   r*   =test_to_datetime_parse_tzname_or_tzoffset_different_tz_to_utc[  s    zWTestTimeConversionFormats.test_to_datetime_parse_tzname_or_tzoffset_different_tz_to_utcoffsetz+0z-1fooZUTCbarz:10z
+01:000:01 c              	   C   s<   d}d| }d}t jt|d t|g|d W 5 Q R X d S )Nr   z2010-01-01 12:00:00 z.does not match format|unconverted data remainsmatchrZ   pytestraises
ValueErrorr   )r%   r   r>   datemsgr)   r)   r*   )test_to_datetime_parse_timezone_malformedo  s
    zCTestTimeConversionFormats.test_to_datetime_parse_timezone_malformedc                 C   s>   d}t dgdd}t||d}tdgddd}t|| d S )	Nr   r   foonamerZ   r   r   )r   r   )r   r   r   r#   r$   )r%   r>   argr'   r(   r)   r)   r*   *test_to_datetime_parse_timezone_keeps_namez  s
    zDTestTimeConversionFormats.test_to_datetime_parse_timezone_keeps_name) __name__
__module____qualname__r   markparametrizer+   r?   rW   r    rT   r   r\   r   r   r^   rc   r   rh   rr   rw   tdskip_if_has_localer{   r   r   pytzFixedOffsetr   r   r   r   r)   r)   r)   r*   r   1   s   
	

(












	 3
 
r   c                   @   sL  e Zd Zejdddedddddgdded	d
d
ddgdded	d
dddggdd Zejddddgdddgdddgdddgdddgdddgdddgdd d!gd"d#d$gd"d%d&gd"d'd(gd"d'd)gdd*d+ggd,d- Zejd.d/d0gd1d2 Z	d3d4 Z
d5d6 Zd7d8 Zejd9d: Zejd;d< Zd=d> Zejd?d@dAgdBdC ZejdDedEedFgejd?d@dAgdGdH Zejd?d@dAgejdIdJdKgdLdM Zejd?d@dAgdNdO Zejd?d@dAgdPdQ Zejd?d@dAgdRdS Zejd?d@dAgejdTeeejfeeejfejeejfe e ej!fgdUdV Z"ejd?d@dAgdWdX Z#ejd?d@dAgdYdZ Z$ejd?d@dAgejd[d\d]gd^d_ Z%ejd?d@dAge&d`dadb Z'ejd?d@dAgdcdd Z(dedf Z)ejdgdhdigejdjd@dAgejdkd/dlgdmdn Z*ejdgdogejdjd@dAgejdkd/dlgdpdq Z+ejdrdhgdigdhdsdtggejdjd@dAgejdkd/dlgdudv Z,ejdwd@d/gejdkdxd/gejdyee-ejee.gdzd{ Z/ejd|e.e0d}gd~ e0d}gd~ e-e0d}gd~ gdd Z1dd Z2ejdwd@d/gejdkdxd/gdd Z3dd Z4dd Z5ejdddddddgdd Z6dd Z7dd Z8dd Z9dd Z:dd Z;dd Z<dd Z=ejde0de0dddfe0ddde0dddfgdd Z>ejdddddgdd Z?dd Z@dd ZAd/S )TestToDatetimezs, _format, dtz2015-1-1z%G-%V-%urO   rM      r   z2015-1-4  r1   z2015-1-7ra   c                 C   s   t ||d|kstd S r   rg   )r%   rV   _formatrv   r)   r)   r*   %test_to_datetime_iso_week_year_format  s    
z4TestToDatetime.test_to_datetime_iso_week_year_formatzmsg, s, _formatzxISO week directive '%V' must be used with the ISO year directive '%G' and a weekday directive '%A', '%a', '%w', or '%u'.z1999 50z%Y %VzxISO year directive '%G' must be used with the ISO week directive '%V' and a weekday directive '%A', '%a', '%w', or '%u'.z1999 51z%G %Vz1999 Mondayz%G %Az1999 Monz%G %az1999 6z%G %wz%G %uZ2051z%Gz`Day of the year directive '%j' is not compatible with ISO year directive '%G'. Use '%Y' instead.z1999 51 6 256z%G %V %u %jzdISO week directive '%V' is incompatible with the year directive '%Y'. Use the ISO year '%G' instead.z1999 51 Sundayz%Y %V %Az1999 51 Sunz%Y %V %az	1999 51 1z%Y %V %wz%Y %V %uZ20z%Vc              	   C   sB   t  dkr>t  dkr>tjt|d t||d W 5 Q R X d S )N)zh_CNUTF-8)it_ITr   r   rZ   )ri   rj   r   r   r   r   )r%   r   rV   r   r)   r)   r*   test_error_iso_week_year  s    [z'TestToDatetime.test_error_iso_week_yearr   Nz
US/Centralc                 C   sD   t ddd|d}t|}t|}||ks,tt|}||ks@td S )Nz
1965-04-03   Z2W)periodsfreqr   )r   r   r   r9   )r%   r   dtir&   r'   r)   r)   r*   test_to_datetime_dtarr  s    z%TestToDatetime.test_to_datetime_dtarrc                 C   s(   t tddd}|tdddks$td S )N  r1      r   r   r9   r%   actualr)   r)   r*   test_to_datetime_pydatetime  s    z*TestToDatetime.test_to_datetime_pydatetimec                 C   s    t d}|tdddkstd S )NZ20080115r   r1   r   r   r   r)   r)   r*   test_to_datetime_YYYYMMDD  s    z(TestToDatetime.test_to_datetime_YYYYMMDDc                 C   s   d}t |dd|kstd S )NzMonth 1, 1999rI   rK   rg   )r%   rV   r)   r)   r*   #test_to_datetime_unparseable_ignore  s    z2TestToDatetime.test_to_datetime_unparseable_ignorec              	   C   s   t d tdd}td}tdgd }t|j|tj dk sPt	t|j|tj dk snt	|j
d ks|t	|j
d kst	W 5 Q R X d S )N
US/Easternnowdatetime64[ns]r       _B)r#   set_timezoner    
datetime64astyper   absvalueint64r9   r   )r%   ZnpnowZpdnowZpdnow2r)   r)   r*   test_to_datetime_now  s    z#TestToDatetime.test_to_datetime_nowc              	   C   st  t d tddtj}td}tdgd }td}t }t	|
 j| dk sdtt	|
 j| dk s~tt	|j|j dk stt	|j|j dk st|jd kst|jd kstW 5 Q R X t d tddtj}td}tdgd }t	|
 j| dk s*tt	|
 j| dk sFt|jd ksVt|jd ksftW 5 Q R X d S )NzPacific/Aucklandtodayr   r   r   zUS/Samoa)r#   r   r    r   r   r   r   r   r   r   	normalizer   r9   r   )r%   ZnptodayZpdtodayZpdtoday2ZtstodayZtstoday2r)   r)   r*   test_to_datetime_today  s(    z%TestToDatetime.test_to_datetime_todayc                 C   s   t dg t dg d S )Nr   r   r   r%   r)   r)   r*   (test_to_datetime_today_now_unicode_bytesB  s    
z7TestToDatetime.test_to_datetime_today_now_unicode_bytesr,   TFc                 C   s:   t dt dg}|D ]}t||dt|kstqd S )N
2000-01-01
2000-01-02r|   )r    r   r   r   r9   )r%   r,   Zin_bound_dtsrv   r)   r)   r*   test_to_datetime_dt64sF  s    z%TestToDatetime.test_to_datetime_dt64srv   z
1000-01-01z
5000-01-02c              	   C   sl   d| }t jt|d t|dd W 5 Q R X t jt|d t| W 5 Q R X t|d|dtkshtd S )Nz$Out of bounds nanosecond timestamp: r   raiser   rP   rK   r,   )r   r   r   r   r   r   r9   )r%   r,   rv   r   r)   r)   r*   $test_to_datetime_dt64s_out_of_boundsM  s    
z3TestToDatetime.test_to_datetime_dt64s_out_of_boundsunitrV   Dc              	   C   s   t d|t d|gd }tt||dtdd |D  |t dg }d}tjt|d	 t|d
d W 5 Q R X tt|d|dtt	|d j
t	|d j
gd tg  tt|d|dtdd |D  d S )Nr   r   re   r|   c                 S   s   g | ]}t |jqS r)   )r   asm8rC   r)   r)   r*   rF   f  s     zBTestToDatetime.test_to_datetime_array_of_dt64s.<locals>.<listcomp>z
9999-01-01z7Out of bounds nanosecond timestamp: 9999-01-01 00:00:00r   r   r   rP   r   r   r1   rI   c                 S   s   g | ]}|  qS r)   )item)rD   rv   r)   r)   r*   rF   }  s     )r    r   r#   r$   r   r   r   r   r   r   r   r   r   )r%   r,   r   ZdtsZdts_with_oobr   r)   r)   r*   test_to_datetime_array_of_dt64sY  s2    


z.TestToDatetime.test_to_datetime_array_of_dt64sc              	   C   s   t dddt dddg}t||d}tddgdd}t|| t dddt dddg}d	}tjt|d
 t||d W 5 Q R X d S )Nz2013-01-01 13:00:00-0800r   r   z2013-01-02 14:00:00-0800r|   z2013-01-01 13:00:00z2013-01-02 14:00:00r   zLTz-aware datetime.datetime cannot be converted to datetime64 unless utc=Truer   )r   r   r   r#   r$   r   r   r   )r%   r,   r&   r'   r(   r   r)   r)   r*   test_to_datetime_tz  s     

 

z"TestToDatetime.test_to_datetime_tzc                 C   sJ   d}d}|gd |gd  }t dd |D }t||d}t|| d S )NMarch 1, 2018 12:00:00+0400March 1, 2018 12:00:00+0500rA   c                 S   s   g | ]}t |qS r)   r   rC   r)   r)   r*   rF     s     zETestToDatetime.test_to_datetime_different_offsets.<locals>.<listcomp>r|   r   r   r#   r$   )r%   r,   Zts_string_1Zts_string_2r&   r(   r'   r)   r)   r*   "test_to_datetime_different_offsets  s    z1TestToDatetime.test_to_datetime_different_offsetsc                 C   st   t d}tj|tdddddd|tddddddgtd}t|d	|d
}tddgdd d}t	
|| d S )Nr   r_   r1   rf   r   )yearmonthdayhourminute   r   Tr   r,   2000-01-01 08:00:00+00:002000-06-01 07:00:00+00:00datetime64[ns, UTC]r   r   )r   timezoner    r!   Zlocalizer   r"   r   r   r#   r$   )r%   r,   Z
us_easternr&   r'   r(   r)   r)   r*   test_to_datetime_tz_pytz  s$    
z'TestToDatetime.test_to_datetime_tz_pytzz.init_constructor, end_constructor, test_methodc           
      C   sz   ddg}t dddt dddg}t||dd|d	}||}||| t||D ]$\}	}t|	dd|d	}||ksPtqPd S )
Nz20100102 121314z20100102 121315z2010-01-02 12:13:14r   r   z2010-01-02 12:13:15z%Y%m%d %H%M%ST)r5   r   r,   )r   r   zipr9   )
r%   r,   Zinit_constructorZend_constructorZtest_methodru   Zexpected_datar'   r(   scalarr)   r)   r*   test_to_datetime_utc_true  s    

   
z(TestToDatetime.test_to_datetime_utc_truec                 C   s:   d}t t|gd|d}tt|ddg}t|| d S )Ng {ѴCTr   r   r   )r   r   r   r#   r8   )r%   r,   tsr'   r(   r)   r)   r*   2test_to_datetime_utc_true_with_series_single_value  s    zATestToDatetime.test_to_datetime_utc_true_with_series_single_valuec                 C   sJ   d}d}t |gd }t|d|d}t t|ddgd }t|| d S )Nz2013-01-01 00:00:00-01:002013-01-01 01:00:00rf   Tr   r   r   )r   r   r   r#   r8   )r%   r,   r   Zexpected_tsru   r'   r(   r)   r)   r*   4test_to_datetime_utc_true_with_series_tzaware_string  s    zCTestToDatetime.test_to_datetime_utc_true_with_series_tzaware_stringzdate, dtype)r   r   )r   r   c                 C   s:   t tdddg}tt |g|dd|d}t|| d S )Nr   r   r   r   Tr   )r   r   r   r#   r8   )r%   r,   r   r   r(   r'   r)   r)   r*   1test_to_datetime_utc_true_with_series_datetime_ns  s    	z@TestToDatetime.test_to_datetime_utc_true_with_series_datetime_nspsycopg2c           	   
   C   s   dd l }|jjdd d}|jjdd d}tjtddddd|dtdd	ddd|dgtd
}t|dd|d}tddgdd d}t	
|| tdg|jjdd dd}t|stt|d|d}t	
|| t|dd|d}tdgdd
}t	
|| d S )Nr   i)r   r   ir_   r1   rf   r   r   r   rP   T)rK   r   r,   r   r   r   r   z2000-01-01 08:00:00r   r   z2000-01-01 13:00:00)r   r   ZFixedOffsetTimezoner    r!   r   r"   r   r   r#   r$   r   r9   )	r%   r,   r   Ztz1Ztz2r&   r'   r(   r=   r)   r)   r*   test_to_datetime_tz_psycopg2  s4    z+TestToDatetime.test_to_datetime_tz_psycopg2c                 C   sD  d}t jt|d td W 5 Q R X tdd|dtks<ttdd|ddksRtt jt|d td W 5 Q R X tdd|dtksttdd|ddkstt| d}t jt|d tdt g|d	 W 5 Q R X t jt|d td
dg|d	 W 5 Q R X t	
tddtdgd|dttd|d	tttd|d	g d S )Nz2dtype bool cannot be converted to datetime64\[ns\]r   FrP   r   rI   Tz is not convertible to datetimer|   20130101r   g        )r   r   	TypeErrorr   r   r9   typer   r   r#   r$   r   r%   r,   r   r)   r)   r*   test_datetime_bool#  s(    z!TestToDatetime.test_datetime_boolc              	   C   sL   d}t jt|d tt W 5 Q R X t jt|d tt W 5 Q R X d S )Nzis not convertible to datetimer   )r   r   r   r   boolr%   r   r)   r)   r*   test_datetime_invalid_datatype;  s
    z-TestToDatetime.test_datetime_invalid_datatyper   az00:01:99inferr5   zH%:M%:S%c              	   C   sj   t |d||d}||kstt |d||d}|tks8td}tjt|d t |d||d W 5 Q R X d S )NrI   rK   r5   infer_datetime_formatrP   z\is a bad directive in format|second must be in 0..59|Given date string not likely a datetimer   r   )r   r9   r   r   r   r   r%   r   r5   r  resr   r)   r)   r*   test_datetime_invalid_scalarC  s.             z+TestToDatetime.test_datetime_invalid_scalarz3000/12/11 00:00:00c              	   C   s   t |d||d}||kstt |d||d}|tks8t|d k	rpd}tjt|d t |d||d W 5 Q R X n.d}tjt|d t |d||d W 5 Q R X d S )NrI   r  rP   z?is a bad directive in format|Out of bounds nanosecond timestampr   r   "Out of bounds nanosecond timestamp)r   r9   r   r   r   r   r   r
  r)   r)   r*    test_datetime_outofbounds_scalar\  s>                z/TestToDatetime.test_datetime_outofbounds_scalarr:   bz99:00:00c              	   C   s|   t |d||d}t|t| t |d||d}t|ttgt|  d}tjt	|d t |d||d W 5 Q R X d S )NrI   r  rP   z\is a bad directive in format|Given date string not likely a datetime|second must be in 0..59r   r   )
r   r#   r$   r   r   r   lenr   r   r   )r%   r:   r5   r  r  r   r)   r)   r*   test_datetime_invalid_indexx  s.             z*TestToDatetime.test_datetime_invalid_indexr   z%Y%m%d %H:%M:%Sconstructorc           	      C   sF   d}|gd }||}t |||dd}t |||dd}t|| d S N20130101 00:00:00順 T)r   r5   r,   Fr   r#   r$   )	r%   r   r5   r  r   
test_datesru   r'   r(   r)   r)   r*   test_to_datetime_cache  s    
z%TestToDatetime.test_to_datetime_cachelistlike2010-06-02 09:30:003   c                 C   s   t |dkstd S )NT)toolsshould_cacher9   )r%   r  r)   r)   r*   &test_no_slicing_errors_in_should_cache  s    
z5TestToDatetime.test_no_slicing_errors_in_should_cachec                 C   s8   t ttdgd }t tdgd }t|| d S )Nr  r  )r   r   r   r#   r$   r%   r'   r(   r)   r)   r*   test_to_datetime_from_deque  s    z*TestToDatetime.test_to_datetime_from_dequec                 C   sF   d}|gd }t |}t|||dd}t|||dd}t|| d S r  r   r   r#   r8   )r%   r   r5   r   r  ru   r'   r(   r)   r)   r*   test_to_datetime_cache_series  s    
z,TestToDatetime.test_to_datetime_cache_seriesc                 C   s(   d}t |dd}td}||ks$td S )Nr  Tr|   r   r   r9   )r%   r   r'   r(   r)   r)   r*   test_to_datetime_cache_scalar  s    z,TestToDatetime.test_to_datetime_cache_scalarc                 C   s^   t d gtgt  tdg dd}t|dd}t tgtd  tdg dd}t|| d S )Nz
2012-07-26r"   r   rP   r   r1   r   )r   r   r   r   r   r#   r8   )r%   serr'   r(   r)   r)   r*   *test_convert_object_to_datetime_with_cache  s    z9TestToDatetime.test_convert_object_to_datetime_with_cachezdate, format)z2017-20z%Y-%W)	20 Sundayz%W %A)20 Sunz%W %a)z2017-21z%Y-%U)r'  z%U %A)r(  z%U %ac              	   C   s.   d}t jt|d t||d W 5 Q R X d S )Nz,Cannot use '%W' or '%U' without day and yearr   rZ   r   )r%   r   r5   r   r)   r)   r*   'test_week_without_day_and_calendar_year  s    z6TestToDatetime.test_week_without_day_and_calendar_yearc                 C   s`   dddg}t |dd}ttdddd	d
td ddtdddd	d
td ddtg}t|| d S )Nr   r   Z20100240rP   r     rf   r1   rM   r   i@8  r   iPF  )r   r   r   r   r   r#   r$   r%   Z
ts_stringsr'   r(   r)   r)   r*   test_to_datetime_coerce  s    z&TestToDatetime.test_to_datetime_coercec                 C   s0   ddg}t |dd}tttg}t|| d S )Nz200622-12-31z111111-24-11rP   r   )r   r   r   r#   r$   r+  r)   r)   r*   !test_to_datetime_coerce_malformed  s    z0TestToDatetime.test_to_datetime_coerce_malformedc                 C   sj   d}t |}t|}||ks ttt|gd }t |gd }t|| t|gd }t|| d S )N2015-11-18 15:30:00+05:30r2   )r   r   r9   r   r#   r$   )r%   Zts_strr'   r(   r)   r)   r*   &test_iso_8601_strings_with_same_offset  s    z5TestToDatetime.test_iso_8601_strings_with_same_offsetc                 C   s   ddt g}t|}tjtdddddtd dd	tdddd
dtd dd	t gtd}t|}t	|| t|dd}t
tddddtddddt gdd}t	|| d S )Nr.  z2015-11-18 16:30:00+06:30r         r   re   iXM  r      ih[  r   Tr   rd   r   r   )r   r   r    r!   r   r   r"   r   r#   r$   r   r   r+  r)   r)   r*   ,test_iso_8601_strings_with_different_offsets  s"    
	 z;TestToDatetime.test_iso_8601_strings_with_different_offsetsc                 C   sz   t dddddgdd}t dddddgdd}t|| ddg}t |dd}t tt|ddd d d }t|| d S )	Nz2018-11-28T00:00:00z2018-11-28T00:00:00+12:00z2018-11-28T00:00:00+06:00Tr3  z2018-11-27T12:00:00z2018-11-27T18:00:00)r   r#   r$   listreversed)r%   r'   r(   itemsr)   r)   r*   -test_iso8601_strings_mixed_offsets_with_naive  s.    

z<TestToDatetime.test_iso8601_strings_mixed_offsets_with_naivec              	   C   s<   t dtdddd g}tjtdd t| W 5 Q R X d S )NrT   z
1990-01-01z2015-03-14T16:15:14.123-08:00z2019-03-04T21:56:32.620-07:00zTz-aware datetime.datetimer   )r   r   r   r   r   r   )r%   r%  r)   r)   r*   .test_mixed_offsets_with_native_datetime_raises8  s    	z=TestToDatetime.test_mixed_offsets_with_native_datetime_raisesc              	   C   s@   t dgd }ttddddtddgd }t|| d S )	Nr   r2   r*  rf   r1   rM      r   )r   r   r   r   r   r#   r$   r  r)   r)   r*   #test_non_iso_strings_with_tz_offsetF  s
    z2TestToDatetime.test_non_iso_strings_with_tz_offsetzts, expectedz
2018-01-01r   r   r   z2018-01-01 08:00c                 C   s   t |dd}||kstd S )NTr3  rg   )r%   r   r(   r'   r)   r)   r*   test_timestamp_utc_trueM  s    z&TestToDatetime.test_timestamp_utc_truedt_strZ00010101Z13000101Z30000101Z99990101c              	   C   s.   d}t jt|d t|dd W 5 Q R X d S )Nr  r   rG   rZ   r   r   r   r   )r%   r>  r   r)   r)   r*   *test_to_datetime_with_format_out_of_bounds\  s    z9TestToDatetime.test_to_datetime_with_format_out_of_boundsc                 C   s4   t jtdgtd}t|dd}|jtjks0td S )Nz2012-06-13T01:39:00Zr   Tr3  )	r    r!   r   r"   r   r   r   r   r9   )r%   r&   r'   r)   r)   r*   test_to_datetime_utcc  s    z#TestToDatetime.test_to_datetime_utcc                 C   sT   ddl m} tddd|dtddd|dtddd|dg}t|}|j|ksPtd S )Nr   )	fixed_offr_   r1   r   r2   rf   )Z-pandas.tests.indexes.datetimes.test_timezonesrB  r   r   r   r9   )r%   rB  r   r'   r)   r)   r*   test_to_datetime_fixed_offseti  s    z,TestToDatetime.test_to_datetime_fixed_offset)Br   r   r   r   r   r   r   r   r   r   r   r   r   r   Zskip_if_windowsr   r   r   r   r    r   r   r   r   r   r   r   r   r#   r$   r6  r!   r   r8   r   r   r   r   Z
skip_if_nor   r  r  r  r  r  tupler   r  r   r  r   r"  r$  r&  r)  r,  r-  r/  r4  r9  r:  r<  r=  r@  rA  rC  r)   r)   r)   r*   r     sj  
S



&
 %






	

'








r   c                   @   s   e Zd Zejdddgdd Zejdddgdd Zejdddgdd	 Zejdddgd
d Z	ejdddgdd Z
ejdddgdd Zejdddgdd Zejdddgdd Zdd Zdd Zdd ZdS )TestToDatetimeUnitr,   TFc                 C   s  d}t jt|d tdgdd|d W 5 Q R X dddtttjd	d
g}t|dd|d}tdt	dt	dtttttgt
d}t|| t|dd|d}td	ddd	d	d	d	d	g}t|| d}t jt|d t|dd|d W 5 Q R X dtttjd	g}t|dd|d}tdttttgt
d}t|| t|dd|d}td	d	d	d	d	g}t|| d}t jt|d t|dd|d W 5 Q R X dt	dfD ]^}zt|dd|d W nB tk
r } ztd|W 5 d }~X Y n tk
r   Y nX qd S )Nz#cannot specify both format and unitr   r1   r   rG   )r   r5   r,   Ǌ g      ?r   r   rI   r   rK   r,   
1970-01-02r   rP   z/cannot convert input 11111111 with the unit 'D'r   l   _B*rV   rK   r   r,   z4cannot convert input 1420043460000 with the unit 's'r   r   zincorrect exception raised)r   r   r   r   r
   r   r    rT   r   r   r"   r#   r$   r   r   r9   )r%   r,   r   r:   r'   r(   rp   errr)   r)   r*   	test_unitv  sV    
zTestToDatetimeUnit.test_unitc                 C   s   t d}tddd|d}||ks$tt|t s2ttddd|d}||ksNtt|t s\ttddd|d}||ksxtt|t std S )Nz1970-05-09 14:25:11rF  rV   r   rG  rP   rI   )r   r   r9   r7   r%   r,   r(   r'   r)   r)   r*   test_unit_consistency  s    z(TestToDatetimeUnit.test_unit_consistencyc                 C   s   t ddg}ddg}t|d}dD ]8}t|||d}t|| t|||d}t|| q(t dddg}d	ddg}t|d
|d}t|| t ddddg}ddd	dg}t|d
|d}t|| d S )Nz2015-06-19 05:33:20z2015-05-27 22:33:20@CA5Cr   )rI   r   rP   r   r   r   rP   )r   r    r!   r   r   r#   r$   )r%   r,   r(   Zarr1Zarr2rK   r'   r&   r)   r)   r*   test_unit_with_numeric  s$    

z)TestToDatetimeUnit.test_unit_with_numericc              	   C   s   t dddg}tdddg}t|d|d}t|| d}tjt|d	 t|d
|d W 5 Q R X t dddg}ddtdg}t|d|d}t|| tjt|d	 t|d
|d W 5 Q R X d S )Nz
2013-01-01r   r   rN  rO  rP   r   z,mixed datetimes and integers in passed arrayr   r   )r   r   r   r#   r$   r   r   r   )r%   r,   r(   r&   r'   r   r)   r)   r*   test_unit_mixed  s    z"TestToDatetimeUnit.test_unit_mixedc                 C   s&   t dd|d}td}||ks"td S )Ng aArV   )r   r,   z2015-06-19 19:55:31.877000192r#  )r%   r,   r'   r(   r)   r)   r*   test_unit_rounding  s    z%TestToDatetimeUnit.test_unit_roundingc                 C   s2   t dgd dd}t|dd|d}t|| d S )Ng   Br2   r   r   rI   rV   rI  r   rL  r)   r)   r*   test_unit_ignore_keeps_name  s    z.TestToDatetimeUnit.test_unit_ignore_keeps_namec                 C   sv  t ddgddgddgddgd	d
gddgddgddgddgd	}t|d |d |d d|d}ttdtdg}t|| t|dddg  |d}t|| |dddg  }d|d< t||d}ttdtdg}t|| ddddddddddddd dg}|D ]F}t|t|  j	|d!|d}ttd"td#g}t|| qdddddd d$d%d&d	}t|j	|d!|d}ttd'td(g}t|| t|
t|d}t|| t ddgdd)gddgd}d*}	tjt|	d+ t||d W 5 Q R X t|d,|d-}ttdtg}t|| d.}	tjt|	d+" | }d|d/< t||d W 5 Q R X d0}	dgddgddd gddgddd gfD ]0}
tjt|	d+ t||
 |d W 5 Q R X qd1}	t ddgdd)gddgd}dddg|_tjt|	d+ t||d W 5 Q R X t ddgdd)gddgddgd2}ddddg|_tjt|	d+ t||d W 5 Q R X d S )3Nr     r2   rf   ra   rA   r      :   ;   rd   r0  r1   )	r   r   r   r   r   secondmsusnsr   r   r   r   r   r   r|   20150204 00:00:00z20160305 00:0:00z20160205 00:0:00Zyearsmonthsdayshoursminutesseconds)r   r   r   r   r   rX  r   r   rX  )columnsz20150204 06:58:10z20160305 07:59:11rY  rZ  r[  z20150204 06:58:10.001002003z20160305 07:59:11.001002003   zTcannot assemble the datetimes: time data .+ does not match format '%Y%m%d' \(match\)r   rP   r   z?extra keys have been passed to the datetime assemblage: \[foo\]r   z`to assemble mappings requires at least that \[year, month, day\] be specified: \[.+\] is missingz#cannot assemble with duplicate keys)r   r   r   r   )r   r   r   r   r#   r8   Zto_dictr6  keysrenamer   rS   r   r   r   r   copyrc  )r%   r,   dfr'   r(   Zdf2Z	expected2unitsdr   cr)   r)   r*   test_dataframe  s     	 z!TestToDatetimeUnit.test_dataframec              	   C   s   t ddgddgddgd}t|d|d	}ttd
tdg}t|| |d d|d< |d d|d< t||d	}ttd
tdg}t|| t ddgddgddgd}d}tjt	|d t||d	 W 5 Q R X d S )Nr   rT  r2   rf   ra   rA   r\  Zint16r|   r]  z20160305 00:00:00r   Zint8r   r_   r`   g      ?r1   z:cannot assemble the datetimes: unconverted data remains: 1r   )
r   r   r   r   r   r#   r8   r   r   r   )r%   r,   rh  r'   r(   r   r)   r)   r*   test_dataframe_dtypes  s"    z(TestToDatetimeUnit.test_dataframe_dtypesc                 C   sV   t ddgddgddgd}t|dd	}ttjd
dgddjd}t|| d S )Nr   rT  r2   rf   ra   rA   r\  Tr3  z
2015-02-04z
2016-03-05r   r   r   )	r   r   r   r    r!   rv   tz_localizer#   r8   )r%   rh  r'   r(   r)   r)   r*   test_dataframe_utc_true  s    z*TestToDatetimeUnit.test_dataframe_utc_truec                 C   s0   t dgdddd}tdgdd}t|| d S )	Nr1   rV   TrI   )r   r   rK   1970-01-01 00:00:01r   r   r   r  r)   r)   r*   'test_to_datetime_errors_ignore_utc_true  s    z:TestToDatetimeUnit.test_to_datetime_errors_ignore_utc_truec              	      s&  d t  fddtdD }t|dd}t dd tdD }t|| t  fddtdD t}t|dd}t d	d tdD }t|| t  fd
dtdD tg }t|dd}t dd tdD tg }t|| t  fddtdD tg t}t|dd}t dd tdD tg }t|| t  fddt	
dddD tg t}t|dd}t dd t	
dddD tg }|d}t|| tjt  fddtdD tt t	jggdd}t|dd}t dd tdD tg }t|| tdddtt	jgdd}ttdtdgdgd  }t|| d}tjt|d tddd gdd W 5 Q R X d!}tjt|d tddd"gdd W 5 Q R X ttdtdgdgd  }tddd gdd#d$}t|| tddd"gdd#d$}t|| d S )%NiQc                    s   g | ]} | qS r)   r)   rD   tepochr)   r*   rF     s     z<TestToDatetimeUnit.test_to_datetime_unit.<locals>.<listcomp>rd  rV   r   c                 S   s   g | ]}t d t|d qS z2013-06-09 02:42:28)rb  r   r   rr  r)   r)   r*   rF     s     c                    s   g | ]} | qS r)   r)   rr  rt  r)   r*   rF     s     c                 S   s   g | ]}t d t|d qS rw  rx  rr  r)   r)   r*   rF     s     c                    s   g | ]} | qS r)   r)   rr  rt  r)   r*   rF     s     c                 S   s   g | ]}t d t|d qS rw  rx  rr  r)   r)   r*   rF     s     c                    s   g | ]} | qS r)   r)   rr  rt  r)   r*   rF     s     c                 S   s   g | ]}t d t|d qS rw  rx  rr  r)   r)   r*   rF     s     c                    s   g | ]} | qS r)   r)   rr  rt  r)   r*   rF     s     r   r2   g      ?c                 S   s   g | ]}t d t|d qS rw  rx  rr  r)   r)   r*   rF     s   rY  c                    s   g | ]} | qS r)   r)   rr  rt  r)   r*   rF     s     T)Zignore_indexc                 S   s   g | ]}t d t|d qS rw  rx  rr  r)   r)   r*   rF     s     r1   r   r   rH  
1970-01-03rf   z+non convertible value foo with the unit 'D'r   r   z0cannot convert input 111111111 with the unit 'D'ikrP   r   rK   )r   ranger   r#   r8   r   floatr
   r   r    ZarangeroundpdconcatrT   r   r   r$   r   r   r   r   )r%   rV   r'   r(   r   r)   rt  r*   test_to_datetime_unit  s      &,
*z(TestToDatetimeUnit.test_to_datetime_unitN)r   r   r   r   r   r   rK  rM  rP  rQ  rR  rS  rl  rm  ro  rq  r  r)   r)   r)   r*   rE  u  s(   
:





 
	rE  c                	   @   s  e Zd Zdd Zejdddgdd Zejdddgdd	 Zejdddgd
d Z	ejdddgdd Z
ejejdddgdd Zejdddgdd Zejdddgdd Zejdddgdd Zdd Zdd Zdd Zejdddgdd Zejddd d!d"d#d$gejdddgd%d& Zejdddgd'd( Zejd)eegd*d+ Zd,S )-TestToDatetimeMiscc              	   C   s:   t jdgtd}d}tjt|d t| W 5 Q R X d S )Nz2262-04-11 23:47:16.854775808r   r  r   )r    r!   r"   r   r   r   r   )r%   r&   r   r)   r)   r*   %test_to_datetime_barely_out_of_bounds  s    z8TestToDatetimeMisc.test_to_datetime_barely_out_of_boundsr,   TFc                 C   sP   t dg|d}td}|d |ks&tt dg|d}td}|d |ksLtd S )Nz2012-01-01 00:00:00r|   r   Z20121001z
2012-10-01r#  )r%   r,   r'   rq   r)   r)   r*   test_to_datetime_iso8601  s    z+TestToDatetimeMisc.test_to_datetime_iso8601c                 C   s(   t d|d}tddd}||ks$td S )NZ2001r|   r`   r1   r   )r%   r,   rsZxpr)   r)   r*   test_to_datetime_default   s    z+TestToDatetimeMisc.test_to_datetime_defaultc                 C   s4   t tddd}t||d}|d |d ks0td S )Nr-   rd   r   r|   r   )r   r   r   r9   )r%   r,   rV   r'   r)   r)   r*   %test_to_datetime_on_datetime64_series,  s    z8TestToDatetimeMisc.test_to_datetime_on_datetime64_seriesc              	   C   s   t dddg}d}tjt|d t|d|d W 5 Q R X t|d|d}t td	d
dtdd
dtg}t|| t|d|d}t|| d S )Nz
10/18/2006z
10/18/2008 z0(\(')?String does not contain a date(:', ' '\))?r   r   r   rP   i  rd   r1  r   rI   )	r   r   r   r   r   r   r   r#   r8   )r%   r,   rV   r   Zresult_coerceZexpected_coerceZresult_ignorer)   r)   r*   %test_to_datetime_with_space_in_series4  s    z8TestToDatetimeMisc.test_to_datetime_with_space_in_seriesc              	      s   t dddgdddgd}t|d d	}|jtd d	}t|| t ddd
gdddgd}d}tjt|d t|dd d W 5 Q R X tjt|d |jtdd d W 5 Q R X t|dd d}| fdd}t|| d S )NzMay 04zJun 02zDec 11r1   r2   rf   index%b %yr4   r   z4time data '' does not match format '%b %y' \(match\)r   r   rJ   rP   c                    s   t | dd dS )Nr  rP   rJ   r   rE   r|   r)   r*   <lambda>U      z@TestToDatetimeMisc.test_to_datetime_with_apply.<locals>.<lambda>)r   r   rR   r#   r8   r   r   r   )r%   r,   r   r(   r'   r   r)   r|   r*   test_to_datetime_with_applyA  s    
z.TestToDatetimeMisc.test_to_datetime_with_applyc                 C   s   t d|d}|tkstt ddg|d}t| s8ttd}t d|d}||ksXtt dg|dd }t d|d}||kstddg}tt ||d}dd |D }t|| d S )	Nr   r|   r   Z2012Z20120101z20120101 12:01:01c                 S   s   g | ]}t |qS r)   rB   )rD   date_strr)   r)   r*   rF   p  s     z=TestToDatetimeMisc.test_to_datetime_types.<locals>.<listcomp>)	r   r   r9   r   allr   r6  r#   assert_almost_equal)r%   r,   r'   r(   r!   r)   r)   r*   test_to_datetime_typesY  s    z)TestToDatetimeMisc.test_to_datetime_typesc              	   C   sh   t ddgd|d}ttjddgdd}t|| d}tjt|d t ddgd	|d W 5 Q R X d S )
Nr1   1rI   r   Or   z#invalid string coercion to datetimer   r   )	r   r   r    r!   r#   r   r   r   r   )r%   r,   r'   r(   r   r)   r)   r*   $test_to_datetime_unprocessable_inputx  s    z7TestToDatetimeMisc.test_to_datetime_unprocessable_inputc                 C   s.   t dggd }t|d|d}t|| d S )Nr  d   rI   r   r!  )r%   r,   seriesr'   r)   r)   r*   !test_to_datetime_unhashable_input  s    z4TestToDatetimeMisc.test_to_datetime_unhashable_inputc                 C   sR   t dd}|d}t|g}|d |dks:tt|}||ksNtd S )Nl    `SD& zM8[us]r  r   )r    r   viewr   r   r9   r   )r%   r   Zas_objr  r   r)   r)   r*   'test_to_datetime_other_datetime64_units  s    

z:TestToDatetimeMisc.test_to_datetime_other_datetime64_unitsc                 C   s8   t ddd}t|j}t|j}t|}t|| d S )Nr-   rd  r  )r   r   r:   r6  Zasi8r#   r$   )r%   rngZintsr'   r)   r)   r*   !test_to_datetime_list_of_integers  s
    

z4TestToDatetimeMisc.test_to_datetime_list_of_integersc              	   C   s<   d dddg}tjt|d tdddd	 W 5 Q R X d S )
N|z)Python int too large to convert to C longzlong too big to convertzint too big to convertr   z1/1/1700Br  )startr   r   )joinr   r   r   r   r  r)   r)   r*   test_to_datetime_overflow  s    z,TestToDatetimeMisc.test_to_datetime_overflowc              	   C   s.  t jddt jdgtd}t jddd}t|D ]&\}}t|rHt||< q.t|||< q.t	
|d }t|| t||d}t|tstt||j t jd	t jgtd}d
}	tjt|	d t|d|d W 5 Q R X t|d|d}t|}t|| tjt|	d t|d|d W 5 Q R X dddddg}
tdt jdt jdg|
dd}ttd|dt jtd|dt jtd|dg|
dd}t||d}t||d}tt jddd|
d}tdD ]2}|| }t|rt||< nt||d||< qtj||dd |jdks
ttj||dd |jdks*td S )Nr-   r.   z1/4/2000, 12:34:56r   ra   rQ   r   r|   z
1/100/2000z4Unknown string format:|day is out of range for monthr   r   r   rI   r  r  rk  rj  er/   z1/5/2000r   )r  r   rA   r  F)Zcheck_names)r    r!   rT   r"   emptyr6   r   r
   r   r	   Zarray_to_datetimer#   r  r   r7   r   r9   Zassert_numpy_array_equalr:   r   r   r   r   r$   r   r{  r   r8   r   )r%   r,   stringsr(   r=   rp   r'   result2Z	malformedr   idxr  ZdseriesZdresultrE   r)   r)   r*   test_string_na_nat_conversion  sf     
  




z0TestToDatetimeMisc.test_string_na_nat_conversionr   zdatetime64[h]zdatetime64[m]zdatetime64[s]zdatetime64[ms]zdatetime64[us]r   c                 C   sF   t dddg|d}|j|}tt|| tt ||d| d S )Nz2000-01-01T00:00z2000-01-02T00:00r   r|   )r   r:   r   r#   r$   r   )r%   r,   r   baser:   r)   r)   r*   $test_dti_constructor_numpy_timeunits  s    z7TestToDatetimeMisc.test_dti_constructor_numpy_timeunitsc           
      C   s   dddg}t tdddtdddtdddg}t |d	d
}t t|d	d
}t|d	|d}tt|d	|d}t t|d	d
}t t|d	d
}	t|| t|| t|| t|| t|| t||	 d S )Nz
10/02/2014z
11/02/2014z
12/02/2014rO   r2   rd   r0  rM   T)dayfirst)r  r,   )	r   r   r    r!   r   r   r   r#   r$   )
r%   r,   r&   r(   Zidx1Zidx2Zidx3Zidx4Zidx5Zidx6r)   r)   r*   test_dayfirst  s     
 z TestToDatetimeMisc.test_dayfirstklassc                 C   sH   t dddd}|d}||}||}t|dd}t|| d S )Nz
2015-04-05rf   r  r   r   Tr3  )r   rf  rn  r   r#   r   )r%   r  r   r(   objr'   r)   r)   r*   test_to_datetime_dta_tz  s    
z*TestToDatetimeMisc.test_to_datetime_dta_tzN)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   r  r)   r)   r)   r*   r    sN   

	







E	
r  c                   @   s   e Zd Zejdd ZdS )TestGuessDatetimeFormatc                 C   s   d}t dddddd|}tj|||gddtjtjtj|gddtj|dgddg}|D ]}t||ks\tq\ttjtjtjtjgdd}|d kstd S )	Nr}     rM   re   r   r  r   random_string)r   strftimer    r!   rT   r  Z _guess_datetime_format_for_arrayr9   )r%   Zexpected_format	dt_stringZtest_arraysZ
test_arrayZformat_for_string_of_nansr)   r)   r*   $test_guess_datetime_format_for_array*  s    z<TestGuessDatetimeFormat.test_guess_datetime_format_for_arrayN)r   r   r   r   Zskip_if_not_us_localer  r)   r)   r)   r*   r  )  s   r  c                   @   s   e Zd Zejdddgdd Zejdddgdd Zejdddgdd	 Zejdddgd
d Z	ejddddgdd Z
ejdddgdd ZdS )TestToDatetimeInferFormatr,   TFc                    s~   t tdddd}dddg}|D ]X | fdd	}t| |d
}t|d|d}t|d|d}t|| t|| q d S )Nr0   2   H)r   r   z%m-%d-%Yz%m/%d/%Y %H:%M:%S.%fz%Y-%m-%dT%H:%M:%S.%fc                    s
   |   S )N)r  r  Ztest_formatr)   r*   r  F  r  zdTestToDatetimeInferFormat.test_to_datetime_infer_datetime_format_consistent_format.<locals>.<lambda>r4   Fr	  r,   T)r   r   rR   r   r#   r8   )r%   r,   rV   Ztest_formatsZs_as_dt_stringsZwith_formatZno_inferZ	yes_inferr)   r  r*   8test_to_datetime_infer_datetime_format_consistent_format?  s"    
    zRTestToDatetimeInferFormat.test_to_datetime_infer_datetime_format_consistent_formatc                 C   sl   t tdddg}tt|d|dt|d|d t tddd	g}tt|d|dt|d|d d S )
N01/01/2011 00:00:00z01-02-2011 00:00:00z2011-01-03T00:00:00Fr  TzJan/01/2011zFeb/01/2011zMar/01/2011)r   r    r!   r#   r8   r   r%   r,   rV   r)   r)   r*   :test_to_datetime_infer_datetime_format_inconsistent_formatU  s    zTTestToDatetimeInferFormat.test_to_datetime_infer_datetime_format_inconsistent_formatc                 C   sB   t tjdtjdtjgtd}tt|d|dt|d|d d S )Nr  01/03/2011 00:00:00r   Fr  Tr   r    r!   rT   r"   r#   r8   r   r  r)   r)   r*   7test_to_datetime_infer_datetime_format_series_with_nansk  s    zQTestToDatetimeInferFormat.test_to_datetime_infer_datetime_format_series_with_nansc                 C   sD   t tjtjtjdddgtd}tt|d|dt|d|d d S )Nr  z01/02/2011 00:00:00r  r   Fr  Tr  r  r)   r)   r*   =test_to_datetime_infer_datetime_format_series_start_with_nansx  s    zWTestToDatetimeInferFormat.test_to_datetime_infer_datetime_format_series_start_with_nansztz_name, offset)r   r   )zUTC-3   )zUTC+3iLc                 C   sF   t d| g}t|dd}t tdt|g}t|| d S )Nz2019-02-02 08:07:13 T)r	  z2019-02-02 08:07:13)r   r   r   rn  r   r   r#   r8   )r%   Ztz_namer   rV   r'   r(   r)   r)   r*   "test_infer_datetime_format_tz_name  s    z<TestToDatetimeInferFormat.test_infer_datetime_format_tz_namec                 C   sV   t dddg}t tdtdtdg}tt||d| tt|d|d	| d S )
N2014-1-1z2014-2-2z2015-3-3z
2014-01-01z
2014-02-02z
2015-03-03r|   %Y-%m-%dr4   )r   r   r#   r8   r   )r%   r,   rV   r(   r)   r)   r*   %test_to_datetime_iso8601_noleading_0s  s    z?TestToDatetimeInferFormat.test_to_datetime_iso8601_noleading_0sN)r   r   r   r   r   r   r  r  r  r  r  r  r)   r)   r)   r*   r  >  s   



 
	r  c                   @   sZ   e Zd Zejdddgdd Zejdddgdd Zejdddgdd	 Zd
S )TestDaysInMonthr,   TFc                 C   sb   t tdd|dstt tddd|ds.tt tddd|dsFtt tddd|ds^td S )N
2015-02-29rP   r   r  rJ   
2015-02-32
2015-04-31)r   r   r9   r%   r,   r)   r)   r*   test_day_not_in_month_coerce  s    z,TestDaysInMonth.test_day_not_in_month_coercec              	   C   s   d}t jt|d tdd|d W 5 Q R X d}t jt|d tddd|d W 5 Q R X d	}t jt|d td
dd|d W 5 Q R X d}t jt|d tddd|d W 5 Q R X d S )Nzday is out of range for monthr   r  r   r   z3time data 2015-02-29 doesn't match format specifiedr  rK   r5   r,   z3time data 2015-02-32 doesn't match format specifiedr  z3time data 2015-04-31 doesn't match format specifiedr  r   r  r)   r)   r*   test_day_not_in_month_raise  s    z+TestDaysInMonth.test_day_not_in_month_raisec                 C   sb   t dd|ddkstt ddd|ddks.tt ddd|ddksFtt ddd|ddks^td S )Nr  rI   r   r  r  r  r  rg   r  r)   r)   r*   test_day_not_in_month_ignore  s    z,TestDaysInMonth.test_day_not_in_month_ignoreN)	r   r   r   r   r   r   r  r  r  r)   r)   r)   r*   r    s   

r  c                5   @   s  e Zd Zejdeedddedddedddedddedddedddedddedddedddedddedddedddedddedddedddedddedddedddedddedddedd	dedd	dedd	dedd	ded
dd	edd	dedd	dddedd	dddedd	dddedd	dddedd	dddedd	dddeddddddedddedddedddedddedddedddedddeddddedddddeddddddd+ ejdddgdd Z	ejdddgd d! Z
d"d# Zejdddgd$d% Zejdddgd&d' Zejdddgejd(d)ed*d+fd,ed-d.fgd/d0 Zd1S )2TestDatetimeParsingWrapperszdate_str,expectedr  r1   i  ra   rU  r_   rd   r0    rA   	   r      r   i     $      rO   r   r`   rM   "   8   )+z
2011-01-01Z2Q2005Z2Q05Z2005Q1Z05Q1Z2011Q3Z11Q3Z3Q2011Z3Q11Z2000Q4Z00Q4Z4Q2000Z4Q00Z2000q4z2000-Q4z00-Q4z4Q-2000z4Q-00Z00q4Z2005z2005-11z2005 11z11-2005z11 2005Z200511Z20051109z20051109 10:15z20051109 08Hz2005-11-09 10:15z2005-11-09 08Hz2005/11/09 10:15z2005/11/09 08HzThu Sep 25 10:36:28 2003zThu Sep 25 2003zSep 25 2003zJanuary 1 2014z2014-06z06-2014z2014-6z6-2014z20010101 12z20010101 1234z20010101 123456r,   TFc                 C   s   d}t j||d\}}t||d}t|g|d}ttj|gtd||d}	t|g|d}
tt|g|d}tt|g|d}||fD ]}||kst	q||	|
||fD ]}tt
|g}t|| q|st
|}||kst	t|dd|d}||kst	d S )NT)	yearfirstr   )r  r,   Sr1   )r   r   r  )r   parse_time_stringr   r    r!   r"   r   r   r   r9   r   r#   r$   r   )r%   r  r(   r,   r  result1ro   r  result3result4Zresult6Zresult8Zresult9r  rq   result5Zresult7r)   r)   r*   test_parsers  s,    9  z(TestDatetimeParsingWrappers.test_parsersc                 C   s0   t ttgdd}t||g|d}t|| d S )Nr   r   r|   )r   r   r   r#   r$   )r%   r,   Zunique_nulls_fixtureZunique_nulls_fixture2r(   r'   r)   r)   r*   test_na_values_with_cache/  s    z5TestDatetimeParsingWrappers.test_na_values_with_cachec                 C   s`   t d\}}td}td}tdgd }|tks8t|tksDt|tksPt|tks\td S )Nr   r   )r   r  r   r   r   r   r9   )r%   r  ro   r  r  r  r)   r)   r*   test_parsers_nat8  s    z,TestDatetimeParsingWrappers.test_parsers_natc              
   C   sF  ddt dddfddt dddfddt dddfddt dddfgddt ddd	fddt ddd	fddt d
ddfddt d
ddfgd}| D ]\}}|D ]\}}}t|||d}||ksttj|||d\}	}
|s|st|}||kstt||||d}t|g||dd }|	|ks$t||ks2t||kstqqd S )NFrL   rd   r0  Ti  rM   i  rd  r     )z10-11-12z20/12/21)r  r  )r  r  r,   r   )	r   r8  r   r9   r   r  r   r   r   )r%   r,   casesr  r:   r  r  r(   Zdateutil_resultr  ro   r  r  r  r)   r)   r*   test_parsers_dayfirst_yearfirstC  sV    -    
     z;TestDatetimeParsingWrappers.test_parsers_dayfirst_yearfirstc                 C   s   t dtdddddft dtdddddfd}| D ]~\}\}}t|\}}t|}t|g}	t|}
t|gd	 }||kst||kst|	|kst|
|kst||ks:tq:d S )
N10:15r1   rd   r   9:05r  rA   )r  r  r   )	r   r   r8  r   r  r   r   r   r9   )r%   r,   r  r  Zexp_nowZexp_defr  ro   r  r  r  r  r)   r)   r*   test_parsers_timestring  s    
z3TestDatetimeParsingWrappers.test_parsers_timestringzdt_string, tz, dt_string_reprz2013-01-01 05:45+0545iY  zATimestamp('2013-01-01 05:45:00+0545', tz='pytz.FixedOffset(345)')z2013-01-01 05:30+0530iJ  zATimestamp('2013-01-01 05:30:00+0530', tz='pytz.FixedOffset(330)')c                 C   sH   t d|d}|d|}t ||d}||ks4t|t|ksDtd S )Nz2013-01-01 00:00:00r|   r   )r   rn  Z
tz_convertr9   repr)r%   r,   r  r   Zdt_string_reprr  Zdt_timer)   r)   r*   .test_parsers_timezone_minute_offsets_roundtrip  s
    zJTestDatetimeParsingWrappers.test_parsers_timezone_minute_offsets_roundtripN)r   r   r   r   r   r   r6  r   r8  r  r  r  r  r  r   r   r  r)   r)   r)   r*   r    s   
































4

W
r  r   rV   rY  rZ  r[  )paramsc                 C   s   | j S )zIDay and some time units.

    * D
    * s
    * ms
    * us
    * ns
    )param)requestr)   r)   r*   ri    s    
ri  c                   C   s   t dS )zTimestamp at 1960-01-01.
1960-01-01rB   r)   r)   r)   r*   
epoch_1960  s    r  c                   C   s   t tdS )NrA   )r6  r{  r)   r)   r)   r*   units_from_epochs  s    r  	timestamp
pydatetimer   str_1960c                 C   sL   |j dkst|j dkr| S |j dkr.|  S |j dkr@|  S t| S dS )zxTimestamp at 1960-01-01 in various forms.

    * Timestamp
    * datetime.datetime
    * numpy.datetime64
    * str
    >   r  r  r  r   r  r  r   N)r  r9   Zto_pydatetimeZto_datetime64rS   )r  r  r)   r)   r*   epochs  s    	


r  c                   C   s   t ddd jS )Nr  rd   r  )r   to_julian_dater:   r)   r)   r)   r*   julian_dates  s    r  c                
   @   s   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zej	
ddefdefdefedddefgdd Zdd Zej	
dddgdd Zdd Zej	
ddddgdddgddd gddd!ggd"d# ZdS )$
TestOriginc                 C   s   t t|ddd}t t|td  dd}t|| t tdddgddd}t td	td
tdg}t|| t tdddgdd}t td	td
tdg}t|| d S )Nr   julianr   originr   rv  r1   r2   unixz
1970-01-01rH  ry  )r   r   r   r  r#   r8   )r%   r  r'   r(   r)   r)   r*   test_to_basic  s    zTestOrigin.test_to_basicc              	   C   sN   t dddd}| dkstd}tjt|d t dddd W 5 Q R X d S )NiR|% r  r   r  r   z&1 is Out of Bounds for origin='julian'r   r1   )r   r  r9   r   r   r   )r%   r'   r   r)   r)   r*   test_julian_round_trip	  s
    z!TestOrigin.test_julian_round_tripc              	   C   s8   |dkr4d}t jt|d t||dd W 5 Q R X d S )Nr   z$unit must be 'D' for origin='julian'r   r  r  r   )r%   ri  r  r   r)   r)   r*   test_invalid_unit	  s    zTestOrigin.test_invalid_unitc              	   C   sV   d}t jt|d tddd W 5 Q R X t jt|d tdddd W 5 Q R X d S )Nz(it must be numeric with a unit specifiedr   z
2005-01-01r  )r  r   r  r   r  r)   r)   r*   test_invalid_origin'	  s
    zTestOrigin.test_invalid_originc                    s:   t  fdd|D }t t||d}t|| d S )Nc                    s   g | ]}t j|d   qS )rv  )r~  Z	TimedeltarC   r  ri  r)   r*   rF   4	  s     z)TestOrigin.test_epoch.<locals>.<listcomp>r  r!  )r%   ri  r  r  r  r(   r'   r)   r  r*   
test_epoch1	  s
    zTestOrigin.test_epochzorigin, excr  ru  z
13-24-1990r1   c              	   C   s8   d| d}t j||d t|||d W 5 Q R X d S )Nzorigin z6 (is Out of Bounds|cannot be converted to a Timestamp)r   r  )r   r   r   )r%   r  excri  r  r   r)   r)   r*   test_invalid_origins:	  s    zTestOrigin.test_invalid_originsc              
   C   s:   t jtdd" tddtdddtjdd W 5 Q R X d S )Nzmust be tz-naiver   r1   r   r_   r   r  )r   r   r   r   r   r   r   r   r)   r)   r*   test_invalid_origins_tzinfoI	  s    z&TestOrigin.test_invalid_origins_tzinfor5   Nz%Y-%m-%d %H:%M:%Sc              	   C   s.   d}t jt|d td|d W 5 Q R X d S )Nr  r   z2417-10-27 00:00:00rZ   r?  )r%   r5   r   r)   r)   r*   .test_to_datetime_out_of_bounds_with_format_argN	  s    z9TestOrigin.test_to_datetime_out_of_bounds_with_format_argc                 C   sh   t ddd}td}||ks tt dddd}td}||ksBtt dddd}td	}||ksdtd S )
Ni( r   rv  z2169-11-13 00:00:00z
1870-01-01r  z2069-11-13 00:00:00i z2169-10-20 00:00:00r#  r  r)   r)   r*   test_processing_orderU	  s    z TestOrigin.test_processing_orderzoffset,utc,expZTz2019-01-01T00:00:00.000Zz-01:00z2019-01-01T01:00:00.000Zz2019-01-01T00:00:00.000-01:00c                 C   s2   d| }t |gd|d}t |g}t|| d S )Nz2019-01-01T00:00:00.000r[  )r   r   r  )r%   r   r   rq   r   r'   r(   r)   r)   r*   test_arg_tz_ns_unite	  s    
zTestOrigin.test_arg_tz_ns_unit)r   r   r   r  r   r  r  r  r   r   r   r   r   r   r  r  r  r	  r  r)   r)   r)   r*   r    s6   	
		

	r  zlistlike,do_cachingr1   r2   rf   ra   rA   r   rU  r  r  FTc                 C   s    t j| t| dd|kstd S )Ngffffff?)check_countunique_share)r  r  r  r9   )r  Z
do_cachingr)   r)   r*   test_should_cachev	  s    r  z%unique_share,check_count, err_message)g      ?r0  z5check_count must be in next bounds: \[0; len\(arg\)\])rd   r2   z-unique_share must be in next bounds: \(0; 1\)c              	   C   s6   dgd }t jt|d t|| | W 5 Q R X d S )NrA   rd   r   )r   r   r9   r  r  )r  r  Zerr_messager   r)   r)   r*   test_should_cache_errors	  s    
r  c                  C   s|   t ddd dd g} | d} |  }t| dd}t tdtdtd	td
td	g}t|| t| | d S )Nr1   r2   l            ZInt64r[  rv  z1970-01-01 00:00:00.000000001z1970-01-01 00:00:00.000000002r   z2043-01-25 23:56:49.213693952)r   r   rg  r   r    r   r#   r8   )r%  Zser_copyr  r(   r)   r)   r*   !test_nullable_integer_to_datetime	  s    
	r  r  c              	   C   sV   t | tr4tjtdd t|| g W 5 Q R X nt|| g}|d tksRtd S )Nznot convertible to datetimer   r   )r7   r   r   r   r   r   r   r9   )Znulls_fixturer  r'   r)   r)   r*   test_na_to_datetime	  s
    
r  c               	   C   s   t dddg} d}t| |dd}t ddtgd	d
}t|| tjtdd t| |dd}W 5 Q R X t| dd}t|| d S )Nz
03/24/2016z
03/25/2016r   r3   rP   r]   z
2016-03-24z
2016-03-25r   r   zdoes not match formatr   r   r   )r   r   r   r#   r8   r   r   r   )r   r5   r'   r(   r)   r)   r*   )test_empty_string_datetime_coerce__format	  s    r  c                  C   sP   t ddgddd} tddgdd	}t||  t ddgdd
d} t||  d S )Nr1   r   rV   rP   rz  rp  r   r   r   r   r   )r'   r(   r)   r)   r*   'test_empty_string_datetime_coerce__unit	  s
    r  )M__doc__rk   collectionsr   r   r   decimalr   ri   Zdateutil.parserr   Zdateutil.tz.tzr   Znumpyr    r   r   Zpandas._libsr	   Zpandas._libs.tslibsr
   r   Zpandas.errorsr   r   Zpandas.util._test_decoratorsutilZ_test_decoratorsr   Zpandas.core.dtypes.commonr   Zpandasr~  r   r   r   r   r   r   r   r   r   Zpandas._testingZ_testingr#   Zpandas.core.arraysr   Zpandas.core.toolsr   r  Zpandas.core.tools.datetimesr   r   r   rE  r  r  r  r  r  Zfixtureri  r  r  r  r  r  r   r   r  r  r  r!   r6  r  r  r  r)   r)   r)   r*   <module>   s   ,  T     w      i3 t




x6


