U
    b͉                    @   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 ddl4m5Z5 ej6ddgddd Z7G dd dZ8G dd dZ9G dd dZ:G dd dZ;G dd dZ<G d d! d!Z=G d"d# d#Z>G d$d% d%Z?G d&d' d'Z@ej6d(d)d*d+d,gdd-d. ZAej6d/d0 ZBej6d1d2 ZCej6d3d4d5d6gdd7d8 ZDej6d9d: ZEG d;d< d<ZFG d=d> d>ZGd?d@ ZHejIJdAejKeLgdBdC ZMdDdE ZNdFdG ZOePdHdIdJ ZQejIJdddgdKdL ZRdS )Mz 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_at)VersionTF)paramsc                 C   s   | j S )z/
    cache keyword to pass to to_datetime.
    paramrequest r!   G/tmp/pip-unpacked-wheel-xg7vt6ln/pandas/tests/tools/test_to_datetime.pycache2   s    r#   c                   @   sf  e Zd Zejdddgdd Zejdeegejdde	d	e	d
e	dggde	d	e	de	dg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gdd Zdd Zdd Zdd Z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/d0 Zejd1ejgd2ed#gfejgd"ed#gfejd3gd2ed#d4gfd5ejgd6ed7d#gfd5ejgd8ed9d#gfd5ejgd"ed9d#gfd"ejejgd"ed#d#d#gfd"ejejgd:ed#d#d#gfgd;d< Zd=d> Zejd?d@edAdBdCgdDedEdFdGgdHdHgdIdIgdJdJgdKdKggdLdM ZdNdO ZejdPdQdRe	dSgdTdUe	dVgdWdXe	dYgejdZd[e	d\ejje  d] d^kd_d`daejdbd[e	dcejje  d] d^kd_d`daejdddee	dfejje  d] d^kd_d`dagdgdh Z!e"j#didj Z$ejdkdldmdndodpgdqdr Z%ejdsdtdue	dvgdwdxe	dyggdzd{ Z&ejd|d}d~gd e	dddgd gd}d~ddge	ddde	ddde	dddggddgd e	de'(ddgd gddgd e	de'(ddgd gdddge	de'(dde	de'(ddggdddge	de'(d]de	de'(d]dgggdd Z)dd Z*ejdddddddgdd Z+dd 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expectedr!   r!   r"   test_to_datetime_readonly;   s    z3TestTimeConversionFormats.test_to_datetime_readonlyboxzformat, expectedz%d/%m/%Y20000101Z20000201Z20000301%m/%d/%YZ20000102Z20000103c                 C   sL   |dddg}t |||d}||}t|tr<t|| nt|| d S )N1/1/20001/2/20001/3/2000formatr#   )r   
isinstancer   r,   assert_series_equalr-   )r.   r#   r3   r:   r1   valuesr0   r!   r!   r"   test_to_datetime_formatE   s    
z1TestTimeConversionFormats.test_to_datetime_formatzarg, expected, formatr6   r7   r8   c                 C   s&   t |||d}t|}||ks"td S Nr9   r   r   AssertionError)r.   r#   argr1   r:   r0   r!   r!   r"   test_to_datetime_format_scalar\   s    z8TestTimeConversionFormats.test_to_datetime_format_scalarc                 C   sl   t ddgdgd  }t dd |tD }t|d|d}t|| t|td|d}t|| d S )N$.9G.   c                 S   s   g | ]}t |qS r!   r   .0xr!   r!   r"   
<listcomp>n   s     zNTestTimeConversionFormats.test_to_datetime_format_YYYYMMDD.<locals>.<listcomp>%Y%m%dr9   r   applystrr   r,   r<   r.   r#   serr1   r0   r!   r!   r"    test_to_datetime_format_YYYYMMDDl   s    z:TestTimeConversionFormats.test_to_datetime_format_YYYYMMDDc                 C   s   t ddgdgd  }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|| d S )
NrD   rE   rF   19801222Z19810105   rL   r9   Znat)	r   r   r)   nanr   r,   r<   rN   rO   )r.   r#   rQ   r1   r0   Zser2r!   r!   r"   )test_to_datetime_format_YYYYMMDD_with_natv   s    


zCTestTimeConversionFormats.test_to_datetime_format_YYYYMMDD_with_natc                 C   sX   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|| d S )N3T3鿾rL   ignorer:   errorsr#             i'  r&   )r   r   r   r+   r,   r<   r.   r#   rQ   r0   r1   r!   r!   r"   'test_to_datetime_format_YYYYMMDD_ignore   s     zATestTimeConversionFormats.test_to_datetime_format_YYYYMMDD_ignorec                 C   s@   t dddg}t|dd|d}t ddd	gd
d}t|| d S )NrW   rX   rY   rL   coercer[   Z20121231Z20141231r   M8[ns]r&   r   r   r,   r<   ra   r!   r!   r"   )test_to_datetime_format_YYYYMMDD_coercion   s    zCTestTimeConversionFormats.test_to_datetime_format_YYYYMMDD_coercioninput_srS   20010112Nr   rD   iT1c                 C   s6   t tdtdtg}t t|dd}t|| d S )NrS   rh   rL   r:   )r   r   r   r   r,   r<   r.   rg   r1   r0   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 )NrL   rc   r:   r\   )r   r,   r<   rj   r!   r!   r"   )test_to_datetime_format_YYYYMMDD_overflow   s    zCTestTimeConversionFormats.test_to_datetime_format_YYYYMMDD_overflowzdata, format, expectedz%Y%m%d%H%M%SZ20210202202020z2021-02-02 20:20:20Z201010z%y%m%dz
2020-10-10z%d%m%yz
2010-10-20rL   c                 C   s   t ||d}t|| d S Nri   r   r,   r-   )r.   datar:   r1   r0   r!   r!   r"   test_to_datetime_with_NA   s    z2TestTimeConversionFormats.test_to_datetime_with_NAc                 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!   rG   rH   r!   r!   r"   rK      s     zMTestTimeConversionFormats.test_to_datetime_format_integer.<locals>.<listcomp>z%Yr9   iA i i c                 S   s,   g | ]$}t |d d d |dd   qS )N   -rG   rH   r!   r!   r"   rK      s     z%Y%mrM   rP   r!   r!   r"   test_to_datetime_format_integer   s    z9TestTimeConversionFormats.test_to_datetime_format_integerzint_date, expectedi3r]   
      i i     rt   iuwi(3iA iI  c                 C   s   t |ddd}||kstd S )NrL   rZ   rl   r   rA   )r.   Zint_dater1   r0   r!   r!   r"   .test_int_to_datetime_format_YYYYMMDD_typeerror   s    zHTestTimeConversionFormats.test_int_to_datetime_format_YYYYMMDD_typeerrorc                 C   sD   t jd }d| d}d}t|||d}t||}||ks@td S )Nrt   z01-z-2011 00:00:01.978z%d-%b-%Y %H:%M:%S.%fr9   )calendar
month_abbrr   r   strptimerA   )r.   r#   r}   valr:   r0   expr!   r!   r"   #test_to_datetime_format_microsecond  s    
z=TestTimeConversionFormats.test_to_datetime_format_microsecondzvalue, format, dtz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:01z01/10/2010 08:14 PMz%m/%d/%Y %I:%M %pz2010-01-10 20:14r   )zh_CNit_ITz4fail on a CI build with LC_ALL=zh_CN.utf8/it_IT.utf8reason)Zmarksz01/10/2010 07:40 AMz2010-01-10 07:40z01/10/2010 09:12:56 AMz%m/%d/%Y %I:%M:%S %pz2010-01-10 09:12:56c                 C   s   t |||d|kstd S r?   rz   )r.   r#   valuer:   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)r:   exactr#   z(\d+\w+\d+))expandr9   )r   r   rO   extractr,   r<   ra   r!   r!   r"   test_to_datetime_with_non_exact>  s    
  z9TestTimeConversionFormats.test_to_datetime_with_non_exactrB   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.001000000c                 C   s*   t ||d}t |d|d}||ks&td S )Nr#   %Y-%m-%d %H:%M:%S.%fr9   rz   )r.   r#   rB   r1   r0   r!   r!   r"   #test_parse_nanoseconds_with_formulaL  s    z=TestTimeConversionFormats.test_parse_nanoseconds_with_formulazvalue,fmt,expectedZ2009324z%Y%W%wz
2009-08-13Z2013020z%Y%U%wz
2013-01-13c                 C   s   t |||d|kstd S r?   rz   )r.   r   fmtr1   r#   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 UTCrT   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 Zc                 C   s$   t ||d}t|}t|| d S rn   )r   r   r,   assert_equal)r.   r   datesexpected_datesr0   r1   r!   r!   r"   )test_to_datetime_parse_tzname_or_tzoffseth  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)r:   utcr   r   r,   r-   )r.   r   r   r   r0   r1   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matchri   pytestraises
ValueErrorr   )r.   r   r   datemsgr!   r!   r"   )test_to_datetime_parse_timezone_malformed  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nameri   r   r   )r   r   )r   r   r   r,   r-   )r.   r   rB   r0   r1   r!   r!   r"   *test_to_datetime_parse_timezone_keeps_name  s
    zDTestTimeConversionFormats.test_to_datetime_parse_timezone_keeps_name)-__name__
__module____qualname__r   markparametrizer2   r   r   r   r>   rC   rR   rV   rb   rf   r)   rU   r   rk   rm   pdZNAr   rq   rv   r   r{   r   r   xfaillocale	getlocaler   tdskip_if_has_localer   r   r   pytzFixedOffsetr   r   r   r   r!   r!   r!   r"   r$   :   s  
		








			'







	 3
 
r$   c                   @   sh  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ejd.d;d<gd=d> Zejd?d@dAgdBdC ZejdDedEedFgdGdH ZejdDedIedJgdKdL ZejdMdNdOgdPdQ ZdRdS ZdTdU ZdVdW ZdXdY ZejdZeefeefejefeefgd[d\ Z ejd]d^e!d_d`dagdbe!dcd`daggddde Z"dfdg Z#dhdi Z$ejdjdkdlgdmdn Z%e&dodpdq Z'ejd?drdsgdtdu Z(dvdw Z)ejd?e*e+gdxdy Z,ejdzd{d|gejd}drdsgejd~d/dgdd Z-ejdzdgejd}drdsgejd~d/dgdd Z.ejdd{gd|gd{ddggejd}drdsgejd~d/dgdd Z/ejd`drd/gejd~dd/gejdee0ejee1gdd Z2dd Z3ejd`drd/gejd~dd/gdd Z4dd Z5ejdd/ej6fe7fe8  e7fe8d  fd/e!dfe7fe8  e7e!dfe7fe8  fde7fe8  de!df e7fe8d
  e!de!df ffdd Z9ejdddddddgdd Z:dd Z;dd Z<dd Z=dd Z>dd Z?dd Z@dd ZAdd ZBdd ZCejde!de!dddafe!dddae!dddafgdd ZDejdddddgddÄ ZEddń ZFddǄ ZGd/S )TestToDatetimezs, _format, dtz2015-1-1z%G-%V-%ur`   r^      r   z2015-1-4     z2015-1-7rt   c                 C   s   t ||d|kstd S rn   rz   )r.   s_formatr   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)r   UTF-8)r   r   r   ri   )r   r   r   r   r   r   )r.   r   r   r   r!   r!   r"   test_error_iso_week_year  s    [z'TestToDatetime.test_error_iso_week_yearr   Nz
US/Centralc                 C   s0   t ddd|d}t|}t|}||ks,td S )Nz
1965-04-03   Z2W)periodsfreqr   )r   r   r   rA   )r.   r   dtir/   r0   r!   r!   r"   test_to_datetime_dtarr8  s    z%TestToDatetime.test_to_datetime_dtarrc                 C   s(   t tddd}|tdddks$td S )N  r      r   r   rA   r.   actualr!   r!   r"   test_to_datetime_pydatetimeA  s    z*TestToDatetime.test_to_datetime_pydatetimec                 C   s    t d}|tdddkstd S )NZ20080115r   r   r   r   r   r!   r!   r"   test_to_datetime_YYYYMMDDE  s    z(TestToDatetime.test_to_datetime_YYYYMMDDc                 C   s   d}t |dd|kstd S )NzMonth 1, 1999rZ   r\   rz   )r.   rQ   r!   r!   r"   #test_to_datetime_unparseable_ignoreI  s    z2TestToDatetime.test_to_datetime_unparseable_ignorec              
   C   s   t d d}t jt|dd, tdd}td}tdgd }W 5 Q R X t|j	|tj
 dk sptt|j	|tj
 dk st|jd kst|jd kstW 5 Q R X d S )	N
US/Eastern&The parsing of 'now' in pd.to_datetimeFr   Zcheck_stacklevelnowdatetime64[ns]r       _B)r,   set_timezoneassert_produces_warningFutureWarningr)   
datetime64astyper   absr   int64rA   r   )r.   r   ZnpnowZpdnowZpdnow2r!   r!   r"   test_to_datetime_nowN  s      z#TestToDatetime.test_to_datetime_nowzPacific/AucklandzUS/Samoac              	   C   s   t | 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 d S )Ntodayr   r   r   )r,   r   r)   r   r   r   r   r   r   r   	normalizer   rA   r   )r.   r   ZnptodayZpdtodayZpdtoday2ZtstodayZtstoday2r!   r!   r"   test_to_datetime_todayd  s    	z%TestToDatetime.test_to_datetime_todayrB   r   r   c              	   C   s>   |dkrt nd }d}tj||dd t|g W 5 Q R X d S )Nr   r   Fr   )r   r,   r   r   )r.   rB   warnr   r!   r!   r"   (test_to_datetime_today_now_unicode_bytes  s    z7TestToDatetime.test_to_datetime_today_now_unicode_bytesr   
2000-01-01
2000-01-02c                 C   s   t ||dt|kstd S )Nr   r@   )r.   r#   r   r!   r!   r"   test_to_datetime_dt64s  s    z%TestToDatetime.test_to_datetime_dt64sz
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   rc   r\   r#   )r   r   r   r   r   r   rA   )r.   r#   r   r   r!   r!   r"   $test_to_datetime_dt64s_out_of_bounds  s    
z3TestToDatetime.test_to_datetime_dt64s_out_of_boundsunitr   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   rx   r   c                 S   s   g | ]}t |jqS r!   )r   asm8rH   r!   r!   r"   rK     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   rc   r   r   r   rZ   c                 S   s   g | ]}|  qS r!   )item)rI   r   r!   r!   r"   rK     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_dt64s  s2    


z.TestToDatetime.test_to_datetime_array_of_dt64sc                 C   sD   t dddt dddg}t||d}tddgdd}t|| d S )Nz2013-01-01 13:00:00-0800r   r   z2013-01-02 14:00:00-0800r   2013-01-01 13:00:002013-01-02 14:00:00)r   r   r   r,   r-   )r.   r#   r/   r0   r1   r!   r!   r"   test_to_datetime_tz  s    

 z"TestToDatetime.test_to_datetime_tzc              	   C   sF   t dddt dddg}d}tjt|d t||d W 5 Q R X d S )	Nr   r   r   r   r   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"    test_to_datetime_tz_mixed_raises  s    

z/TestToDatetime.test_to_datetime_tz_mixed_raisesc                 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+0500rF   c                 S   s   g | ]}t |qS r!   r   rH   r!   r!   r"   rK     s     zETestToDatetime.test_to_datetime_different_offsets.<locals>.<listcomp>r   r   r   r,   r-   )r.   r#   Zts_string_1Zts_string_2r/   r1   r0   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   rr   r   ry   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/   r0   r1   r!   r!   r"   test_to_datetime_tz_pytz  s$    
z'TestToDatetime.test_to_datetime_tz_pytzz!init_constructor, end_constructorc                 C   sL   ddg}t dddt dddg}t||dd|d	}||}t|| d S )
N20100102 12131420100102 1213152010-01-02 12:13:14r   r   2010-01-02 12:13:15%Y%m%d %H%M%STr:   r   r#   )r   r   r,   r   )r.   r#   Zinit_constructorZend_constructorrp   Zexpected_datar0   r1   r!   r!   r"   test_to_datetime_utc_true  s    

   z(TestToDatetime.test_to_datetime_utc_truezscalar, expectedr  r  r   r   r  r  c                 C   s    t |dd|d}||kstd S )Nr  Tr  rz   )r.   r#   scalarr1   r0   r!   r!   r"    test_to_datetime_utc_true_scalar  s    	z/TestToDatetime.test_to_datetime_utc_true_scalarc                 C   s:   d}t t|gd|d}tt|ddg}t|| d S )Ng {ѴCTr  r   r   )r   r   r   r,   r<   )r.   r#   tsr0   r1   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:00ry   Tr  r   r   r   r   r   r,   r<   )r.   r#   r  Zexpected_tsrp   r0   r1   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,   r<   )r.   r#   r   r'   r1   r0   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tjjt|j d tdkt	dd |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   z2.8.7z6psycopg2.tz is deprecated (and appears dropped) in 2.9)r   r   i)r   r   irr   r   ry   r   r  r&   rc   T)r\   r   r#   r  r  r  r	  z2000-01-01 08:00:00r   r   z2000-01-01 13:00:00)r  nodeZ
add_markerr   r   r   r   __version__splitAttributeErrorr   ZFixedOffsetTimezoner)   r*   r   r+   r   r   r,   r-   r   rA   )
r.   r    r#   r  Ztz1Ztz2r/   r0   r1   ir!   r!   r"   test_to_datetime_tz_psycopg28  sB    	z+TestToDatetime.test_to_datetime_tz_psycopg2TFc              	   C   sV   d}t jt|d t| W 5 Q R X t|d|dtks<tt|d|d|ksRtd S )Nz2dtype bool cannot be converted to datetime64\[ns\]r   rc   r   rZ   )r   r   	TypeErrorr   r   rA   r.   r#   rB   r   r!   r!   r"   test_datetime_booli  s
    z!TestToDatetime.test_datetime_boolc                 C   s   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 )Nz is not convertible to datetimer   Fr   20130101Tr   g        rc   r   )typer   r   r"  r   r   r   r,   r-   r   r   r.   r#   r   r!   r!   r"   test_datetime_bool_arrays_mixedr  s    z.TestToDatetime.test_datetime_bool_arrays_mixedc              	   C   s*   d}t jt|d t| W 5 Q R X d S )Nzis not convertible to datetimer   )r   r   r"  r   )r.   rB   r   r!   r!   r"   test_datetime_invalid_datatype  s    z-TestToDatetime.test_datetime_invalid_datatyper   az00:01:99inferr:   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 )NrZ   r\   r:   infer_datetime_formatrc   z\is a bad directive in format|second must be in 0..59|Given date string not likely a datetimer   r   )r   rA   r   r   r   r   r.   r   r:   r+  resr   r!   r!   r"   test_datetime_invalid_scalar  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 )NrZ   r,  rc   z?is a bad directive in format|Out of bounds nanosecond timestampr   r   "Out of bounds nanosecond timestamp)r   rA   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 )NrZ   r,  rc   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=   r:   r+  r/  r   r!   r!   r"   test_datetime_invalid_index  s.             z*TestToDatetime.test_datetime_invalid_indexz%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   r:   r#   Fro   )	r.   r   r:   r6  r   
test_datesrp   r0   r1   r!   r!   r"   test_to_datetime_cache  s    
z%TestToDatetime.test_to_datetime_cachec                 C   s8   t ttdgd }t tdgd }t|| d S )N2010-06-02 09:30:003   )r   r   r   r,   r-   r.   r0   r1   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 r7  re   )r.   r   r:   r   r:  rp   r0   r1   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 )Nr8  Tr   r@   )r.   r   r0   r1   r!   r!   r"   test_to_datetime_cache_scalar  s    z,TestToDatetime.test_to_datetime_cache_scalarzdatetimelikes,expected_valuesrT   z
2012-07-26Nz2012 July 26c                 C   s4   t |dd}t|dd}t |dd}t|| d S )Nr+   r&   rc   r   r   re   )r.   ZdatetimelikesZexpected_valuesrQ   Zresult_seriesZexpected_seriesr!   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)rD  z%U %A)rE  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   ri   r   )r.   r   r:   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20100240rc   r     ry   r   r^   r   i@8  r   iPF  )r   r   r   r   r   r,   r-   r.   Z
ts_stringsr0   r1   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-11rc   r   )r   r   r   r,   r-   rH  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:30rT   )r   r   rA   r   r,   r-   )r.   Zts_strr0   r1   r!   r!   r"   &test_iso_8601_strings_with_same_offsetD  s    z5TestToDatetime.test_iso_8601_strings_with_same_offsetc                 C   sj   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	|| d S )NrK  2015-11-18 16:30:00+06:30r         r   rx   iXM  r      ih[  r&   )
r   r   r)   r*   r   r   r+   r   r,   r-   rH  r!   r!   r"   ,test_iso_8601_strings_with_different_offsetsR  s    
	z;TestToDatetime.test_iso_8601_strings_with_different_offsetsc                 C   sL   ddt g}t|dd}ttddddtddddt gd	d
}t|| d S )NrK  rM  Tr   r   rN  rO  rw   r   r   )r   r   r   r   r,   r-   rH  r!   r!   r"   0test_iso_8601_strings_with_different_offsets_utcb  s    
 z?TestToDatetime.test_iso_8601_strings_with_different_offsets_utcc                 C   s<   t dddddgdd}t dddddgdd}t|| d S )N2018-11-28T00:00:002018-11-28T00:00:00+12:00z2018-11-28T00:00:00+06:00TrR  z2018-11-27T12:00:00z2018-11-27T18:00:00ro   r>  r!   r!   r"   -test_iso8601_strings_mixed_offsets_with_naivej  s&    

z<TestToDatetime.test_iso8601_strings_mixed_offsets_with_naivec                 C   sB   ddg}t |dd}t tt|ddd d d }t|| d S )NrU  rT  TrR  )r   listreversedr,   r-   )r.   itemsr0   r1   r!   r!   r"   6test_iso8601_strings_mixed_offsets_with_naive_reversed  s    zETestToDatetime.test_iso8601_strings_mixed_offsets_with_naive_reversedc              	      s   dt dddd gt t fddttD s>tt }tdt dt d t d d gtd}t	
|| tjtd	d
 t| W 5 Q R X d S )NrU   z
1990-01-01z2015-03-14T16:15:14.123-08:00z2019-03-04T21:56:32.620-07:00c                 3   s   | ]} | | kV  qd S rB  r!   )rI   r   rQ   valsr!   r"   	<genexpr>  s     zPTestToDatetime.test_mixed_offsets_with_native_datetime_raises.<locals>.<genexpr>r   r&   zTz-aware datetime.datetimer   )r   r   allranger4  rA   r   to_pydatetimer+   r,   r<   r   r   r   )r.   mixedr1   r!   r\  r"   .test_mixed_offsets_with_native_datetime_raises  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   rT   rG  ry   r   r^      r   )r   r   r   r   r   r,   r-   r>  r!   r!   r"   #test_non_iso_strings_with_tz_offset  s
    z2TestToDatetime.test_non_iso_strings_with_tz_offsetzts, expectedz
2018-01-01r   r   z2018-01-01 08:00c                 C   s   t |dd}||kstd S )NTrR  rz   )r.   r  r1   r0   r!   r!   r"   test_timestamp_utc_true  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 )Nr1  r   rL   ri   r   r   r   r   )r.   rg  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&   TrR  )	r)   r*   r   r+   r   r   r   r   rA   )r.   r/   r0   r!   r!   r"   test_to_datetime_utc  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_offrr   r   r   rT   ry   )Z-pandas.tests.indexes.datetimes.test_timezonesrk  r   r   r   rA   )r.   rk  r   r0   r!   r!   r"   test_to_datetime_fixed_offset  s    z,TestToDatetime.test_to_datetime_fixed_offset)Hr   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   rX  r*   r   r  r   r  r  r  r  
skip_if_nor!  r$  r(  boolr   r)  r0  r2  r5  tupler   r;  r?  r@  rA  rU   r   r   rC  rF  rI  rJ  rL  rQ  rS  rV  r[  rc  re  rf  ri  rj  rl  r!   r!   r!   r"   r     s  
S



 
 

%
	



0










r   c                	   @   s  e Zd Zdd Zdd Zdd Zdd Zej	d	d
ddgdd Z
ej	ddd
dgej	dddgdd Zej	ddddgdddggddddgddddgggdd Zej	ddddgedddggdddgddedgggd d! Zd"d# Zd$d% Zd&d' Zej	deegd(d) Zej	d*eejgd+d, Zd-d. Zd/d0 Zej	d1dd2gd3d4 Zej	d1dd2gd5d6 Zd7S )8TestToDatetimeUnitc              	   C   s4   d}t jt|d tdgdd|d W 5 Q R X d S )Nz#cannot specify both format and unitr   r   r   rL   )r   r:   r#   r   r'  r!   r!   r"   	test_unit  s    zTestToDatetimeUnit.test_unitc              	   C   s   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 S )NǊ r   g      ?r   r   r   rZ   r   r\   r#   
1970-01-02r&   rc   z/cannot convert input 11111111 with the unit 'D'r   r   )r
   r   r)   rU   r   r   r   r+   r,   r-   r   r   r   r   r.   r#   r=   r0   r1   r   r!   r!   r"   test_unit_array_mixed_nans  s.    
z-TestToDatetimeUnit.test_unit_array_mixed_nansc              	   C   s   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 S )Nl   _B*r   rZ   r   r\   r   r#   r&   rc   z4cannot convert input 1420043460000 with the unit 's'r   r   )r
   r   r)   rU   r   r   r+   r,   r-   r   r   r   r   ru  r!   r!   r"   $test_unit_array_mixed_nans_large_int  s    z7TestToDatetimeUnit.test_unit_array_mixed_nans_large_intc              	   C   s2   d}t jt|d tddd|d W 5 Q R X d S )Nz+non convertible value foo with the unit 's'r   r   r   r   rw  r   r'  r!   r!   r"   8test_to_datetime_invalid_str_not_out_of_bounds_valuerror  s    zKTestToDatetimeUnit.test_to_datetime_invalid_str_not_out_of_bounds_valuerrorerrorr   rc   rZ   c                 C   s6   t d}tdd||d}||ks$tt|t s2td S )Nz1970-05-09 14:25:11rr  r   rs  )r   r   rA   r;   )r.   r#   rz  r1   r0   r!   r!   r"   test_unit_consistency  s    z(TestToDatetimeUnit.test_unit_consistencyr\   r'   Zfloat64r   c                 C   s>   t ddg}tddg|}t|||d}t|| d S )N2015-06-19 05:33:202015-05-27 22:33:20@CA5Cr   )r   r)   r*   r   r   r,   r-   )r.   r#   r\   r'   r1   r/   r0   r!   r!   r"   test_unit_with_numeric  s    z)TestToDatetimeUnit.test_unit_with_numericzexp, arrr   r|  r}  r   r~  r  c                 C   s&   t |}t|d|d}t|| d S )Nrc   r   )r   r   r,   r-   )r.   r#   r   r/   r1   r0   r!   r!   r"   test_unit_with_numeric_coerce   s    z0TestToDatetimeUnit.test_unit_with_numeric_coercez
2013-01-01r%  c              	   C   sR   t |}t|d|d}t|| d}tjt|d t|d|d W 5 Q R X d S )Nrc   r   z,mixed datetimes and integers in passed arrayr   r   )r   r   r,   r-   r   r   r   )r.   r#   r   r/   r1   r0   r   r!   r!   r"   test_unit_mixed4  s    z"TestToDatetimeUnit.test_unit_mixedc                 C   s&   t dd|d}td}||ks"td S )Ng aAr   )r   r#   z2015-06-19 19:55:31.877000192r@   r.   r#   r0   r1   r!   r!   r"   test_unit_roundingL  s    z%TestToDatetimeUnit.test_unit_roundingc                 C   s2   t dgd dd}t|dd|d}t|| d S )Ng   BrT   r   r   rZ   r   rw  r   r.   r#   r1   r0   r!   r!   r"   test_unit_ignore_keeps_nameS  s    z.TestToDatetimeUnit.test_unit_ignore_keeps_namec                 C   s0   t dgdddd}tdgdd}t|| d S )	Nr   r   TrZ   )r   r   r\   1970-01-01 00:00:01r   r   r   r>  r!   r!   r"   'test_to_datetime_errors_ignore_utc_trueY  s    z:TestToDatetimeUnit.test_to_datetime_errors_ignore_utc_truec                    sV   d t  fddtdD |}t|dd}t dd tdD }t|| d S )NQc                    s   g | ]} | qS r!   r!   rI   tepochr!   r"   rK   c  s     z<TestToDatetimeUnit.test_to_datetime_unit.<locals>.<listcomp>   r   r   c                 S   s   g | ]}t d t|d qS z2013-06-09 02:42:28)secondsr   r   r  r!   r!   r"   rK   f  s     )r   r`  r   r   r,   r<   )r.   r'   rQ   r0   r1   r!   r  r"   test_to_datetime_unit`  s     z(TestToDatetimeUnit.test_to_datetime_unitnullc                    s\   d t  fddtdD |g }t|dd}t dd tdD tg }t|| d S )Nr  c                    s   g | ]} | qS r!   r!   r  r  r!   r"   rK   m  s     zGTestToDatetimeUnit.test_to_datetime_unit_with_nulls.<locals>.<listcomp>r  r   r  c                 S   s   g | ]}t d t|d qS r  r  r  r!   r!   r"   rK   p  s     )r   r`  r   r   r,   r<   )r.   r  rQ   r0   r1   r!   r  r"    test_to_datetime_unit_with_nullsj  s     z3TestToDatetimeUnit.test_to_datetime_unit_with_nullsc                    sx   d 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	
|| d S )Nr  c                    s   g | ]} | qS r!   r!   r  r  r!   r"   rK   y  s     zOTestToDatetimeUnit.test_to_datetime_unit_fractional_seconds.<locals>.<listcomp>r   rT   g      ?r   r  c                 S   s   g | ]}t d t|d qS r  r  r  r!   r!   r"   rK   |  s   ms)r   r)   Zaranger
   r   floatr   r   roundr,   r<   )r.   rQ   r0   r1   r!   r  r"   (test_to_datetime_unit_fractional_secondsu  s    ,
z;TestToDatetimeUnit.test_to_datetime_unit_fractional_secondsc                 C   sF   t dddttjgdd}ttdtdgdgd  }t|| d S )	Nr   rT   r   r   r  rt  
1970-01-03ry   )r   r   r)   rU   r   r   r,   r-   r>  r!   r!   r"   test_to_datetime_unit_na_values  s
    z2TestToDatetimeUnit.test_to_datetime_unit_na_valuesbad_valikc              	   C   s:   | d}t jt|d tdd|gdd W 5 Q R X d S )Nz with the unit 'D'r   r   rT   r   r  r   )r.   r  r   r!   r!   r"   test_to_datetime_unit_invalid  s    
z0TestToDatetimeUnit.test_to_datetime_unit_invalidc                 C   sB   t tdtdgdgd  }tdd|gddd}t|| d S )	Nrt  r  r   r   rT   r   rc   r   r\   )r   r   r   r,   r-   )r.   r  r1   r0   r!   r!   r"   test_to_timestamp_unit_coerce  s
    z0TestToDatetimeUnit.test_to_timestamp_unit_coerceN)r   r   r   rq  rv  rx  ry  r   r   r   r{  r  r  r   r  r  r  r  intr  r  r
   r)   rU   r  r  r  r  r  r!   r!   r!   r"   rp    sX   





	


rp  c                   @   s   e Zd Zejdd Zdd Zdd Zej	ddd	d
dddddddddddgdd Z
dd Zdd Zdd Zdd Zej	ddgddgdddgddgdddggd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,S )-TestToDatetimeDataFramec                 C   s@   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	S )Nr     rT   ry   rt   rF   r     :   ;   rw   rN  r   	r   r   r  r  r  secondr  usns)r   r.   r!   r!   r"   df  s    zTestToDatetimeDataFrame.dfc                 C   sj   t |d |d |d d|d}ttdtdg}t|| t |dddg  |d}t|| d S )Nr   r   r  r   r   r  r   20150204 00:00:00z20160305 00:0:00)r   r   r   r,   r<   to_dictr.   r  r#   r0   r1   r!   r!   r"   test_dataframe  s     z&TestToDatetimeDataFrame.test_dataframec                 C   sJ   |dddg   }d|d< t||d}ttdtdg}t|| d S )Nr   r   r  rT   r   r  z20160205 00:0:00)r  r   r   r   r,   r<   )r.   r  r#   df2r0   Z	expected2r!   r!   r"   &test_dataframe_dict_with_constructable  s    z>TestToDatetimeDataFrame.test_dataframe_dict_with_constructabler   Zyearsmonthsdayshoursminutesr  )r   r   r  r  r  r  r   r   r  r  r  r  c                 C   sD   t |t|  j|d|d}ttdtdg}t|| d S )Ncolumnsr   z20150204 06:58:10z20160305 07:59:11)r   rX  keysrenamer   r   r,   r<   )r.   r  r#   r   r0   r1   r!   r!   r"   *test_dataframe_field_aliases_column_subset  s
     zBTestToDatetimeDataFrame.test_dataframe_field_aliases_column_subsetc              
   C   sP   ddddddddd	d
	}t |j|d|d}ttdtdg}t|| d S )Nr   r   r  r  r  r  r  r  r  r  r  r   20150204 06:58:10.00100200320160305 07:59:11.001002003)r   r  r   r   r,   r<   )r.   r  r#   dr0   r1   r!   r!   r"   test_dataframe_field_aliases  s"    z4TestToDatetimeDataFrame.test_dataframe_field_aliasesc                 C   s6   t |t|d}ttdtdg}t|| d S )Nr   r  r  )r   r   rO   r   r   r,   r<   r  r!   r!   r"   test_dataframe_str_dtype  s    z0TestToDatetimeDataFrame.test_dataframe_str_dtypec              	   C   st   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 S )Nr   r  rT   r  rt   rF   r  zTcannot assemble the datetimes: time data .+ does not match format '%Y%m%d' \(match\)r   r   rc   r   r  )
r   r   r   r   r   r   r   r   r,   r<   )r.   r#   r  r   r0   r1   r!   r!   r"   test_dataframe_coerce  s    z-TestToDatetimeDataFrame.test_dataframe_coercec              	   C   s>   d}t jt|d" | }d|d< t||d W 5 Q R X d S )Nz?extra keys have been passed to the datetime assemblage: \[foo\]r   r   r   r   )r   r   r   copyr   )r.   r  r#   r   r  r!   r!   r"   !test_dataframe_extra_keys_raisesm  s
    z9TestToDatetimeDataFrame.test_dataframe_extra_keys_raisesmcolsc              	   C   s2   d}t jt|d t|| |d W 5 Q R X d S )Nz`to assemble mappings requires at least that \[year, month, day\] be specified: \[.+\] is missingr   r   r   )r.   r  r#   r  r   r!   r!   r"   "test_dataframe_missing_keys_raises  s    z:TestToDatetimeDataFrame.test_dataframe_missing_keys_raisesc              	   C   s   d}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d}d	dd
d
g|_tjt|d t||d W 5 Q R X d S )Nz#cannot assemble with duplicate keysr   r  rT   r  rt   rF   r  r   r  r   r   )r   r   r  r  r   )r   r  r   r   r   r   )r.   r#   r   r  r!   r!   r"   'test_dataframe_duplicate_columns_raises.  s    z?TestToDatetimeDataFrame.test_dataframe_duplicate_columns_raisesc                 C   sR   t ddgddgddgd}t|d|d	}ttd
tdg}t|| d S )Nr   r  rT   ry   rt   rF   r  Zint16r   r  20160305 00:00:00)r   r   r   r   r   r,   r<   r.   r#   r  r0   r1   r!   r!   r"   test_dataframe_int16=  s    z,TestToDatetimeDataFrame.test_dataframe_int16c                 C   sp   t ddgddgddgd}|d d	|d< |d
 d	|d
< t||d}ttdtdg}t|| d S )Nr   r  rT   ry   rt   rF   r  r   Zint8r  r   r  r  )r   r   r   r   r   r,   r<   r  r!   r!   r"   test_dataframe_mixedH  s    z,TestToDatetimeDataFrame.test_dataframe_mixedc              	   C   sJ   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 )	Nrr   rs   g      ?r   r  z:cannot assemble the datetimes: unconverted data remains: 1r   r   )r   r   r   r   r   )r.   r#   r  r   r!   r!   r"   test_dataframe_floatS  s    z,TestToDatetimeDataFrame.test_dataframe_floatc                 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   r  rT   ry   rt   rF   r  TrR  z
2015-02-04z
2016-03-05r   r&   r   )	r   r   r   r)   r*   r   tz_localizer,   r<   )r.   r  r0   r1   r!   r!   r"   test_dataframe_utc_trueZ  s    z/TestToDatetimeDataFrame.test_dataframe_utc_trueN)r   r   r   r   fixturer  r  r  r   r   r  r  r  r  r  r  r  r  r  r  r  r!   r!   r!   r"   r    sT   

	


	r  c                	   @   s^  e Zd Zdd Zejdddgddggdd Zd	d
 Zejj	dddd Z
dd Zd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d  Zejd!ed"ed"gd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Z ejd5d6d7d8d9d:d;gd<d= Z!d>d? Z"d@dA Z#dBdC Z$ejdDe%e&gdEdF Z'dGS )H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&   r1  r   )r)   r*   r+   r   r   r   r   )r.   r/   r   r!   r!   r"   %test_to_datetime_barely_out_of_boundse  s    z8TestToDatetimeMisc.test_to_datetime_barely_out_of_boundszarg, exp_strz2012-01-01 00:00:00Z20121001z
2012-10-01c                 C   s*   t |g|d}t|}|d |ks&td S )Nr   r   r@   )r.   r#   rB   Zexp_strr0   r   r!   r!   r"   test_to_datetime_iso8601o  s    z+TestToDatetimeMisc.test_to_datetime_iso8601c                 C   s(   t d|d}tddd}||ks$td S )NZ2001r   rs   r   r   )r.   r#   rsZxpr!   r!   r"   test_to_datetime_default{  s    z+TestToDatetimeMisc.test_to_datetime_defaultz1fails to enforce dayfirst=True, which would raiser   c              
   C   sJ   d}t jt|d. tjtdd tdd|d W 5 Q R X W 5 Q R X d S )NzInvalid date specifiedr   zProvide formatz
01-13-2012Tdayfirstr#   )r   r   r   r,   r   UserWarningr   r'  r!   r!   r"   "test_to_datetime_respects_dayfirst  s    z5TestToDatetimeMisc.test_to_datetime_respects_dayfirstc                 C   s4   t tddd}t||d}|d |d ks0td S )Nr6   rw   r   r   r   )r   r   r   rA   )r.   r#   rQ   r0   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   rc   i  rw   rO  r   rZ   )	r   r   r   r   r   r   r   r,   r<   )r.   r#   rQ   r   Zresult_coerceZexpected_coerceZresult_ignorer!   r!   r"   %test_to_datetime_with_space_in_series  s    z8TestToDatetimeMisc.test_to_datetime_with_space_in_seriesc                 C   sF   t dddgdddgd}t|d|d	}|jtd|d	}t|| d S )
NMay 04Jun 02zDec 11r   rT   ry   index%b %yr9   )r   r   rN   r,   r<   )r.   r#   r   r1   r0   r!   r!   r"   test_to_datetime_with_apply  s    z.TestToDatetimeMisc.test_to_datetime_with_applyc              	      s   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 )Nr  r  r   r   rT   ry   r  z4time data '' does not match format '%b %y' \(match\)r   r  r   r[   rc   c                    s   t | dd dS )Nr  rc   r[   )r   rJ   r   r!   r"   <lambda>      zOTestToDatetimeMisc.test_to_datetime_with_apply_with_empty_str.<locals>.<lambda>)r   r   r   r   r   rN   r,   r<   )r.   r#   r   r   r1   r0   r!   r   r"   *test_to_datetime_with_apply_with_empty_str  s    
z=TestToDatetimeMisc.test_to_datetime_with_apply_with_empty_strc                 C   s   t d|d}|tkstd S Nr   r   )r   r   rA   r.   r#   r0   r!   r!   r"   test_to_datetime_empty_stt  s    z-TestToDatetimeMisc.test_to_datetime_empty_sttc                 C   s$   t ddg|d}t| s td S r  )r   r   r_  rA   r  r!   r!   r"   test_to_datetime_empty_str_list  s    z2TestToDatetimeMisc.test_to_datetime_empty_str_listc                 C   s$   t d}td|d}||ks td S )Nr   r   )r   r   rA   r  r!   r!   r"   test_to_datetime_zero  s    z(TestToDatetimeMisc.test_to_datetime_zeroc                 C   s.   t dg|dd }t d|d}||ks*td S )N2012r   r   rz   r  r!   r!   r"   test_to_datetime_strings  s    z+TestToDatetimeMisc.test_to_datetime_stringsc                 C   s8   dddg}t t||d}dd |D }t|| d S )Nr  Z20120101z20120101 12:01:01r   c                 S   s   g | ]}t |qS r!   rG   )rI   date_strr!   r!   r"   rK     s     zITestToDatetimeMisc.test_to_datetime_strings_variation.<locals>.<listcomp>)rX  r   r,   assert_almost_equal)r.   r#   r*   r1   r0   r!   r!   r"   "test_to_datetime_strings_variation  s    
z5TestToDatetimeMisc.test_to_datetime_strings_variationr0   r  c                 C   s   t ddd}||kstd S )Nr]   r   )r   rA   r>  r!   r!   r"   'test_to_datetime_strings_vs_constructor  s    z:TestToDatetimeMisc.test_to_datetime_strings_vs_constructorc              	   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 )
Nr   1rZ   r   Or&   z#invalid string coercion to datetimer   r   )	r   r   r)   r*   r,   r   r   r   r"  )r.   r#   r0   r1   r   r!   r!   r"   $test_to_datetime_unprocessable_input  s    z7TestToDatetimeMisc.test_to_datetime_unprocessable_inputc                 C   s.   t dggd }t|d|d}t|| d S )Nr*  d   rZ   r   re   )r.   r#   seriesr0   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   rA   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 )Nr6   r  r  )r   r   r=   rX  Zasi8r,   r-   )r.   rngZintsr0   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Br9  )startr   r   )joinr   r   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 d S )	Nr6   r7   z1/4/2000, 12:34:56r&   rt   rd   r   r   )r)   r*   rU   r+   empty	enumerater   r
   r   r	   Zarray_to_datetimer,   r  r   r;   r   rA   Zassert_numpy_array_equalr=   )r.   r#   stringsr1   r   r   r0   result2r!   r!   r"   test_string_na_nat_conversion  s     
z0TestToDatetimeMisc.test_string_na_nat_conversionc              	   C   s   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 S )Nz
1/100/2000r&   z4Unknown string format:|day is out of range for monthr   r   r   rZ   )r)   r*   rU   r+   r   r   r   r   r   r,   r-   )r.   r#   Z	malformedr   r0   r1   r!   r!   r"   'test_string_na_nat_conversion_malformed#  s    z:TestToDatetimeMisc.test_string_na_nat_conversion_malformedc           
   	   C   s  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 ].}|| }	t|	rt||< qt|	|d||< qtj	||dd |j
d	ksttj	||dd |j
d	kstd S )Nr*  r3  cr  er6   r8   z1/5/2000r   r  r   r   rF   rd   r&   r  F)Zcheck_names)r   r)   rU   r   r   r`  r   r   r,   r<   r   rA   )
r.   r#   idxr  Zdseriesr0   Zdresultr1   r   rJ   r!   r!   r"   'test_string_na_nat_conversion_with_name3  s8      



z:TestToDatetimeMisc.test_string_na_nat_conversion_with_namer'   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_timeunitsU  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/2014r`   rT   rw   rN  r^   Tr  r  )	r   r   r)   r*   r   r   r   r,   r-   )
r.   r#   r/   r1   Zidx1Zidx2Zidx3Zidx4Zidx5Zidx6r!   r!   r"   test_dayfirsti  s     
 z TestToDatetimeMisc.test_dayfirstc           	   	   C   s   d}ddg}t ddgdd d}t ddgdd d}t|d	d
}t|| tjt|d t|dd
}W 5 Q R X t|| tjt|d t|dd
}W 5 Q R X t|| t|d	d}t|| d S )NwParsing '31/12/2014' in DD/MM/YYYY format. Provide format or specify infer_datetime_format=True for consistent parsing.
31/12/2014z
10/03/2011
2014-12-31z
2011-03-10r   r	  z
2011-10-03Tr  r   Fr-  )r   r   r,   r-   r   r  )	r.   warning_msg_day_firstr/   Zexpected_consistentZexpected_inconsistentZres1Zres2Zres3Zres4r!   r!   r"   "test_dayfirst_warnings_valid_input|  s.        z5TestToDatetimeMisc.test_dayfirst_warnings_valid_inputc           	   	   C   s   d}d}ddg}t ddgdd d}tjt|d	 t|d
d}W 5 Q R X t|| tjt|d	 t|dd}W 5 Q R X t|| tjt|d	 t|dd}W 5 Q R X t|| tjt|d	 t|d
d}W 5 Q R X t|| d S )Nr  zwParsing '03/30/2011' in MM/DD/YYYY format. Provide format or specify infer_datetime_format=True for consistent parsing.r  z
03/30/2011r  z
2011-03-30r   r	  r   Tr  Fr  )r   r,   r   r  r   r-   )	r.   r  Zwarning_msg_month_firstr/   r1   Zres5Zres6Zres7Zres8r!   r!   r"   $test_dayfirst_warnings_invalid_input  s,      z7TestToDatetimeMisc.test_dayfirst_warnings_invalid_inputklassc                 C   sH   t dddd}|d}||}||}t|dd}t|| d S )Nz
2015-04-05ry   r  r   r   TrR  )r   r  r  r   r,   r   )r.   r  r   r1   objr0   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  r  r
  r  r  r  r  r   r   r  r!   r!   r!   r"   r  d  s`   



	


"
	#'r  c                   @   sP   e Zd Zejejddddgej	ej	dgddggdd Z
ejdd ZdS )	TestGuessDatetimeFormat
test_arrayz2011-12-30 00:00:00.000000random_stringc                 C   s   d}t ||kstd S )Nr   )tools _guess_datetime_format_for_arrayrA   )r.   r  Zexpected_formatr!   r!   r"   $test_guess_datetime_format_for_array  s    z<TestGuessDatetimeFormat.test_guess_datetime_format_for_arrayc                 C   s0   t tjtjtjtjgdd}|d ks,td S )Nr  r&   )r  r  r)   r*   rU   rA   )r.   Zformat_for_string_of_nansr!   r!   r"   -test_guess_datetime_format_for_array_all_nans  s    zETestGuessDatetimeFormat.test_guess_datetime_format_for_array_all_nansN)r   r   r   r   Zskip_if_not_us_localer   r   r   r)   rU   r  r  r!   r!   r!   r"   r    s   r  c                   @   s   e Zd Zejddddgdd Zejddd	d
gdddggdd Zdd Zdd Z	ejddddgdd Z
ejdddddgdd  Zejd!d"d#gd$d% Zd"S )&TestToDatetimeInferFormattest_formatz%m-%d-%Yz%m/%d/%Y %H:%M:%S.%fz%Y-%m-%dT%H:%M:%S.%fc                    sj   t tdddd}| fdd}t| |d}t|d|d	}t|d
|d	}t|| t|| d S )Nr4   2   Hr   r   c                    s
   |   S rB  )strftimer  r!  r!   r"   r    r  zdTestToDatetimeInferFormat.test_to_datetime_infer_datetime_format_consistent_format.<locals>.<lambda>r9   Fr-  r#   T)r   r   rN   r   r,   r<   )r.   r#   r!  rQ   Z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_formatrp   01/01/2011 00:00:00z01-02-2011 00:00:00z2011-01-03T00:00:00zJan/01/2011zFeb/01/2011zMar/01/2011c                 C   s2   t t|}tt|d|dt|d|d d S )NFr'  T)r   r)   r*   r,   r<   r   )r.   r#   rp   rQ   r!   r!   r"   :test_to_datetime_infer_datetime_format_inconsistent_format  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*   rU   r+   r,   r<   r   r.   r#   rQ   r!   r!   r"   7test_to_datetime_infer_datetime_format_series_with_nans  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_nans"  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 Tr  2019-02-02 08:07:13)r   r   r   r  r   r   r,   r<   )r.   Ztz_namer   rQ   r0   r1   r!   r!   r"   "test_infer_datetime_format_tz_name5  s    z<TestToDatetimeInferFormat.test_infer_datetime_format_tz_namez
ts,zero_tz)r1  Z)r1  r   )2019-02-02 08:07:13.012345r3  )r4  r   c                 C   sN   t || g}t|dd}|dkr(tjnd }t t||dg}t|| d S )NTr  r3  r   )r   r   r   r   r   r,   r<   )r.   r  Zzero_tzrQ   r0   r   r1   r!   r!   r"   "test_infer_datetime_format_zero_tzA  s
    z<TestToDatetimeInferFormat.test_infer_datetime_format_zero_tzr:   N%Y-%m-%dc                 C   sB   t dddg}t tdtdtdg}tt|||d| d S )N2014-1-1z2014-2-2z2015-3-3z
2014-01-01z
2014-02-02z
2015-03-03r9   )r   r   r,   r<   r   )r.   r#   r:   rQ   r1   r!   r!   r"   %test_to_datetime_iso8601_noleading_0sR  s    z?TestToDatetimeInferFormat.test_to_datetime_iso8601_noleading_0s)r   r   r   r   r   r   r(  r*  r.  r/  r2  r5  r8  r!   r!   r!   r"   r     s<    


 
		
r   c                   @   s   e Zd Zejdddgddgddgddggdd Zd	d
 Zejddddgdd Zejdddgddgddgddggdd Z	dS )TestDaysInMonthzarg, format
2015-02-29Nr6  z
2015-02-32z
2015-04-31c                 C   s   t t|d||dstd S )Nrc   r\   r:   r#   )r   r   rA   )r.   r#   rB   r:   r!   r!   r"   test_day_not_in_month_coercec  s    
z,TestDaysInMonth.test_day_not_in_month_coercec              	   C   s0   d}t jt|d tdd|d W 5 Q R X d S )Nzday is out of range for monthr   r:  r   r   r   r'  r!   r!   r"   test_day_not_in_month_raiseo  s    z+TestDaysInMonth.test_day_not_in_month_raiserB   c              	   C   s:   d| d}t jt|d t|dd|d W 5 Q R X d S )Nz
time data z doesn't match format specifiedr   r   r6  r;  r   r#  r!   r!   r"   !test_day_not_in_month_raise_valuet  s    z1TestDaysInMonth.test_day_not_in_month_raise_valuezexpected, formatc                 C   s    t |d||d}||kstd S )NrZ   r;  rz   )r.   r#   r1   r:   r0   r!   r!   r"   test_day_not_in_month_ignorez  s    
z,TestDaysInMonth.test_day_not_in_month_ignore)
r   r   r   r   r   r   r<  r=  r>  r?  r!   r!   r!   r"   r9  `  s*   	

	r9  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+ dd Z	dd Z
dd  Zejd!d"d#d#ed$dd	fd"d%d#ed$d	dfd"d#d%ed&d	dfd"d%d%ed&dd	fd'd#d#ed(dd)fd'd%d#ed(dd)fd'd#d%ed
dd*fd'd%d%ed
dd*fgd+d, Zejd-d.edddddgd/edddddggd0d1 Zejd2d3ed4d5fd6ed7d8fgd9d: Zd;S )<TestDatetimeParsingWrapperszdate_str,expectedi  r   i  rt   r  rr   rw   rN  i  rF   	   r      r   i     $      r`   r  rs   r^   "   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 123456c                 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&   )rH  r#   Sr   )r   r   rH  )r   parse_time_stringr   r)   r*   r+   r   r   r   rA   r   r,   r-   r   )r.   r  r1   r#   rH  result1_r  result3result4Zresult6Zresult8Zresult9r/  r   result5Zresult7r!   r!   r"   test_parsers  s,    8  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_fixture2r1   r0   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   rJ  r   r   r   r   rA   )r.   rK  rL  r  rM  rN  r!   r!   r"   test_parsers_nat  s    z,TestDatetimeParsingWrappers.test_parsers_natz'date_str, dayfirst, yearfirst, expectedz10-11-12Fr]   Ti  z20/12/21i  r     c                 C   s   t |||d}||ksttj|||d\}}|sJ|sJt|}	|	|ksJtt||||d}
t|g||dd }||kszt|
|kst||kstd S )N)r  rH  )r  rH  r#   r   )r   rA   r   rJ  r   r   r   )r.   r#   r  r  rH  r1   Zdateutil_resultrK  rL  r  rM  rN  r!   r!   r"   test_parsers_dayfirst_yearfirst  s(    ;  
   z;TestDatetimeParsingWrappers.test_parsers_dayfirst_yearfirstzdate_str, exp_defz10:15z9:05c           
      C   s~   t |}t|\}}t|}t|g}t|}t|gd }	||ksJt||ksVt||ksbt||ksnt|	|ksztd S )Nr   )r   r   rJ  r   r   r   rA   )
r.   r  Zexp_defZexp_nowrK  rL  r  rM  rN  rO  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   r  Z
tz_convertrA   repr)r.   r#   Z	dt_stringr   Zdt_string_reprr  Zdt_timer!   r!   r"   .test_parsers_timezone_minute_offsets_roundtripV	  s
    zJTestDatetimeParsingWrappers.test_parsers_timezone_minute_offsets_roundtripN)r   r   r   r   r   r   rX  r   rZ  rP  rQ  rR  rT  rU  r   r   rW  r!   r!   r!   r"   r@    s   
































4

D&
r@  r   r   r  r  r  c                 C   s   | j S )zIDay and some time units.

    * D
    * s
    * ms
    * us
    * ns
    r   r   r!   r!   r"   unitsp	  s    
rX  c                   C   s   t dS )zTimestamp at 1960-01-01.
1960-01-01rG   r!   r!   r!   r"   
epoch_1960}	  s    rZ  c                   C   s   t tdS )NrF   )rX  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   rA   ra  Zto_datetime64rO   )rZ  r    r!   r!   r"   epochs	  s    	


r_  c                   C   s   t ddd jS )Nr7  rw   r  )r   to_julian_dater=   r!   r!   r!   r"   julian_dates	  s    ra  c                
   @   s
  e Zd Zdd Zdd Zdd Zdd Zej	d	d
dg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ej	ddd d!gdd"d#g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gd/d0 ZdS )1
TestOriginc                 C   s>   t t|ddd}t t|td  dd}t|| d S )Nr   julianr   originr   r  )r   r   r   r`  r,   r<   )r.   ra  r0   r1   r!   r!   r"   test_julian	  s
    zTestOrigin.test_julianc                 C   sB   t tdddgddd}t tdtdtd	g}t|| d S )
Nr   r   rT   r   unixrd  z
1970-01-01rt  r  r  r>  r!   r!   r"   	test_unix	  s
    zTestOrigin.test_unixc              	   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|% rc  r   re  r   z&1 is Out of Bounds for origin='julian'r   r   )r   r`  rA   r   r   r   )r.   r0   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   rc  rd  r   )r.   rX  ra  r   r!   r!   r"   test_invalid_unit	  s    zTestOrigin.test_invalid_unitr   r  r   c              	   C   s0   d}t jt|d tdd|d W 5 Q R X d S )Nz(it must be numeric with a unit specifiedr   z
2005-01-01rY  ri  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 )r  )r   Z	TimedeltarH   rZ  rX  r!   r"   rK   	  s     z)TestOrigin.test_epoch.<locals>.<listcomp>rd  re   )r.   rX  r_  rZ  r[  r1   r0   r!   rm  r"   
test_epoch	  s
    zTestOrigin.test_epochzorigin, excr  r  z
13-24-1990r   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   rd  )r   r   r   )r.   re  excrX  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   r   r   rr   r   rd  )r   r   r   r   r   r   r   r  r!   r!   r"   test_invalid_origins_tzinfo	  s    z&TestOrigin.test_invalid_origins_tzinfor:   Nz%Y-%m-%d %H:%M:%Sc              	   C   s.   d}t jt|d td|d W 5 Q R X d S )Nr1  r   z2417-10-27 00:00:00ri   rh  )r.   r:   r   r!   r!   r"   .test_to_datetime_out_of_bounds_with_format_arg	  s    z9TestOrigin.test_to_datetime_out_of_bounds_with_format_argzarg, origin, expected_str( rg  z2169-11-13 00:00:00
1870-01-012069-11-13 00:00:00鼫 2169-10-20 00:00:00c                 C   sj   t |d|d}t|}||ks"tt dddd}td}||ksDtt dddd}td}||ksftd S )Nr   rd  rs  rt  ru  rv  rw  r@   )r.   rB   re  Zexpected_strr0   r1   r!   r!   r"   test_processing_order	  s    z TestOrigin.test_processing_orderzoffset,utc,expr3  Tz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   ro   )r.   r   r   r   rB   r0   r1   r!   r!   r"   test_arg_tz_ns_unit
  s    
zTestOrigin.test_arg_tz_ns_unit)r   r   r   rf  rh  rj  rk  r   r   r   rl  rn  r   r   r   rp  rq  rr  rx  ry  r!   r!   r!   r"   rb  	  sH   
	
		


	rb  c                   @   s   e Zd Zejddddddddd	d
dg
dfddddddddd	d
g
dfgdd Zejdddgdd Zejdee	dgd e	dgd e
e	dgd gdd ZdS )TestShouldCachezlistlike,do_cachingr   rT   ry   rt   rF   r  r  rB  rA  r   FTc                 C   s    t j|t|dd|kstd S )Ngffffff?)check_countunique_share)r  should_cacher4  rA   )r.   listlikeZ
do_cachingr!   r!   r"   test_should_cache
  s    	z!TestShouldCache.test_should_cachez%unique_share,check_count, err_message)g      ?rN  z5check_count must be in next bounds: \[0; len\(arg\)\])rw   rT   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 )NrF   rw   r   )r   r   rA   r  r}  )r.   r|  r{  Zerr_messagerB   r!   r!   r"   test_should_cache_errors'
  s    
z(TestShouldCache.test_should_cache_errorsr~  r<  r=  c                 C   s   t |dkstd S )NT)r  r}  rA   )r.   r~  r!   r!   r"   &test_no_slicing_errors_in_should_cache4
  s    
z6TestShouldCache.test_no_slicing_errors_in_should_cacheN)r   r   r   r   r   r   r  r  r   r   ro  r  r!   r!   r!   r"   rz  
  s,   

rz  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 )Nr   rT   l            ZInt64r  r  1970-01-01 00:00:00.0000000011970-01-01 00:00:00.000000002r   z2043-01-25 23:56:49.213693952)r   r   r  r   r)   r   r,   r<   )rQ   Zser_copyr/  r1   r!   r!   r"   !test_nullable_integer_to_datetimeA
  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   )r;   r   r   r   r"  r   r   rA   )Znulls_fixturer  r0   r!   r!   r"   test_na_to_datetimeW
  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   r5   rc   rl   z
2016-03-24z
2016-03-25r   r&   zdoes not match formatr   r   r   )r   r   r   r,   r<   r   r   r   )r   r:   r0   r1   r!   r!   r"   (test_empty_string_datetime_coerce_formatd
  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 )Nr   r   r   rc   r  r  r   r   r&   r   r   )r0   r1   r!   r!   r"   'test_empty_string_datetime_coerce__unitw
  s
    r  xarrayc                  C   sH   dd l } | dddg}t|dd}tddd	gd
d d}t|| d S )Nr   r   rT   ry   r  r  r  r  z1970-01-01 00:00:00.000000003r   r	  )r  Z	DataArrayr   r   r,   r-   )Zxrr/   r0   r1   r!   r!   r"   test_xarray_coerce_unit
  s    	r  c                 C   s   t }ttd|dd}|jdddj|dd}|j td	 |_t	|j
d d d
f | d}|j
d d d
f }t|| d S )NZ1980ZYSr$  FZDTr  r   )nZrandom_statei  r   r   )r   r   r   Zto_framesampler  Z	to_seriesr   r  r   Zilocr,   r<   )r#   Zcstarttimesr0   r1   r!   r!   r"   +test_to_datetime_monotonic_increasing_index
  s    r  )S__doc__r|   collectionsr   r   r   decimalr   r   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   Zpandas.util.versionr   r  r#   r$   r   rp  r  r  r  r   r9  r@  rX  rZ  r[  r_  ra  rb  rz  r  r   r   r*   rX  r  r  r  rm  r  r  r!   r!   r!   r"   <module>   s   ,
          J H  qs( i




x(

