U
    sVc                    @   s:  d Z ddlZddlmZ ddlmZ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l0m1Z2 ddl3m4Z4 ddl5m6Z6 ej7ddg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@G d&d' d'ZAej7d(d)d*d+d,gdd-d. ZBej7d/d0 ZCej7d1d2 ZDej7d3d4d5d6gdd7d8 ZEej7d9d: ZFG d;d< d<ZGG d=d> d>ZHd?d@ ZIejJKdAejLeMgdBdC ZNdDdE ZOdFdG ZPeQdHdIdJ ZRejJKdddgdKdL ZSejJKdMdNe4e4dO e4dP gdQdR ZTejJjKdSdTdUge'dTe'dUgedVdWdXdXdXdXejUdYedZdOdOggd[d\d]gd^ejJKd_ddgd`da ZVdbdc ZWdS )dz test to_datetime     N)deque)datetime	timedeltatimezone)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-xj8nt62q/pandas/tests/tools/test_to_datetime.pycache3   s    r$   c                   @   sl  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d`daejdbd[e	dcejje  d] d^kd_dd`daejdddee	dfejje  d] d^kd_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$   r4   r;   r2   valuesr1   r"   r"   r#   test_to_datetime_formatF   s    
z1TestTimeConversionFormats.test_to_datetime_formatzarg, expected, formatr7   r8   r9   c                 C   s&   t |||d}t|}||ks"td S Nr:   r   r   AssertionError)r/   r$   argr2   r;   r1   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>o   s     zNTestTimeConversionFormats.test_to_datetime_format_YYYYMMDD.<locals>.<listcomp>%Y%m%dr:   r   applystrr   r-   r=   r/   r$   serr2   r1   r"   r"   r#    test_to_datetime_format_YYYYMMDDm   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 )
NrE   rF   rG   19801222Z19810105   rM   r:   Znat)	r   r   r*   nanr   r-   r=   rO   rP   )r/   r$   rR   r2   r1   Zser2r"   r"   r#   )test_to_datetime_format_YYYYMMDD_with_natw   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鿾rM   ignorer;   errorsr$             i'  r'   )r   r   r   r,   r-   r=   r/   r$   rR   r1   r2   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 )NrX   rY   rZ   rM   coercer\   Z20121231Z20141231r   M8[ns]r'   r   r   r-   r=   rb   r"   r"   r#   )test_to_datetime_format_YYYYMMDD_coercion   s    zCTestTimeConversionFormats.test_to_datetime_format_YYYYMMDD_coercioninput_srT   20010112Nr   rE   iT1c                 C   s6   t tdtdtg}t t|dd}t|| d S )NrT   ri   rM   r;   )r   r   r   r   r-   r=   r/   rh   r2   r1   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 )NrM   rd   r;   r]   r   r-   r=   rk   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-20rM   c                 C   s   t ||d}t|| d S Nrj   r   r-   r.   )r/   datar;   r2   r1   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"   rH   rI   r"   r"   r#   rL      s     zMTestTimeConversionFormats.test_to_datetime_format_integer.<locals>.<listcomp>z%Yr:   iA i i c                 S   s,   g | ]$}t |d d d |dd   qS )N   -rH   rI   r"   r"   r#   rL      s     z%Y%mrN   rQ   r"   r"   r#   test_to_datetime_format_integer   s    z9TestTimeConversionFormats.test_to_datetime_format_integerzint_date, expectedi3r^   
      i i     rv   iuwi(3iA iI  c                 C   s   t |ddd}||kstd S )NrM   r[   rm   r   rB   )r/   Zint_dater2   r1   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 )Nrv   z01-z-2011 00:00:01.978z%d-%b-%Y %H:%M:%S.%fr:   )calendar
month_abbrr   r   strptimerB   )r/   r$   r   valr;   r1   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strict)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@   r|   )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+))expandr:   )r   r   rP   extractr-   r=   rb   r"   r"   r#   test_to_datetime_with_non_exactD  s    
  z9TestTimeConversionFormats.test_to_datetime_with_non_exactrC   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.%fr:   r|   )r/   r$   rC   r2   r1   r"   r"   r#   #test_parse_nanoseconds_with_formulaR  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@   r|   )r/   r   fmtr2   r$   r"   r"   r#   test_to_datetime_format_weeksd  s    z7TestTimeConversionFormats.test_to_datetime_format_weekszfmt,dates,expected_datesz%Y-%m-%d %H:%M:%S %Zz2010-01-01 12:00:00 UTCrU   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 -01002010-01-01 12:00:00 Zc                 C   s$   t ||d}t|}t|| d S rp   )r   r   r-   assert_equal)r/   r   datesexpected_datesr1   r2   r"   r"   r#   )test_to_datetime_parse_tzname_or_tzoffsetn  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   r1   r2   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matchrj   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namerj   r   r   )r   r   )r   r   r   r-   r.   )r/   r   rC   r1   r2   r"   r"   r#   *test_to_datetime_parse_timezone_keeps_name  s
    zDTestTimeConversionFormats.test_to_datetime_parse_timezone_keeps_name)-__name__
__module____qualname__r   markparametrizer3   r   r   r   r?   rD   rS   rW   rc   rg   r*   rV   r   rl   ro   pdNAr   rs   rx   r   r}   r   r   xfaillocale	getlocaler   tdskip_if_not_us_localer   r   r   pytzFixedOffsetr   r   r   r   r"   r"   r"   r#   r%   ;   s  
		








	

,







	 3
 
r%   c                   @   s  e Zd Zdd Zd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d0d1 Z
ejd2d3d4gd5d6 Zd7d8 Zd9d: Zd;d< Zejd=d> Zejejd2d?d@gdAdB ZejdCdDdEgdFdG ZejdHedIedJgdKdL ZejdHedMedNgdOdP ZejdQdRdSgdTdU ZdVdW ZdXdY ZdZd[ Zd\d] Zejd^eefeefej efe!e!fgd_d` Z"ejdadbe#dcdddegdfe#dgdddeggdhdi Z$djdk Z%dldm Z&ejdndodpgdqdr Z'e(dsdtdu Z)ejdCdvdwgdxdy Z*dzd{ Z+ejdCe,e-gd|d} Z.ejd~ddgejddvdwgejdd3dgdd Z/ejd~dgejddvdwgejdd3dgdd Z0ejddgdgdddggejddvdwgejdd3dgdd Z1ejdddvd3gejddd3gejdee2ej ee3gdd Z4dd Z5ejdddvd3gejddd3gdd Z6dd Z7ejdd3ej8fe9fe:  e9fe:d  fd3e#dfe9fe:  e9e#dfe9fe:  fde9fe:  de#df e9fe:d  e#de#df ffdd Z;ejddvdwgejde!e9gd d3gd  dde!e9gd ddfe!e9gd d3gd  dde!e9gd ddfe!d3gd e!e9gd ddfe!d3gd e!e9gd ddfe!dgd e!e9gd ddfe!dgd e!e9gd ddfe!e<j=gd e!e9gd ddfe!e<j=gd e!e9gd ddfe!ej>gd e!e9gd ddfe!ej>gd e!e9gd ddff
dd Z?ejdddddddgdd Z@dd ZAdd ZBdd ZCdd ZDdd ZEdd ZFdd ZGddÄ ZHddń ZIejde#dǃe#dddefe#dddee#dddefgdd̄ ZJejdddddgddӄ ZKddՄ ZLddׄ ZMd3S )TestToDatetimec              	   C   sp   t ddddttdd d}t ddddttdd d}td|g}t||gtd}t|| d S )	N        )hoursr      z2020-01-01 17:00 -0100r   )	r   r   r   r   
tz_convertr   r   r-   r.   )r/   d1Zd2resr2   r"   r"   r#   *test_to_datetime_mixed_datetime_and_string  s
    z9TestToDatetime.test_to_datetime_mixed_datetime_and_stringc                 C   s   t d}t|g}tddd}t||ks0tt|jd |ksFtt|g}t|g}t	|| t|}t|}t
|| d S )Nz2019-02-04 10:18:46.297000+0000z2019-02-04 10:18:46.297000r   r   r   )r*   Zstr_r   r   r   rB   ilocr   r-   r.   r=   )r/   r   rR   r   r   r2   r"   r"   r#   test_to_datetime_np_str  s    



z&TestToDatetime.test_to_datetime_np_strzs, _format, dtz2015-1-1z%G-%V-%ura   r_      r   z2015-1-4  r   z2015-1-7rv   c                 C   s   t ||d|kstd S rp   r|   )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   rj   )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   rB   )r/   r   dtir0   r1   r"   r"   r#   test_to_datetime_dtarrY  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   rB   r/   actualr"   r"   r#   test_to_datetime_pydatetimeb  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_YYYYMMDDf  s    z(TestToDatetime.test_to_datetime_YYYYMMDDc                 C   s   d}t |dd|kstd S )NzMonth 1, 1999r[   r]   r|   )r/   rR   r"   r"   r#   "test_to_datetime_unparsable_ignorej  s    z1TestToDatetime.test_to_datetime_unparsable_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   int64rB   r   )r/   r   ZnpnowZpdnowZpdnow2r"   r"   r#   test_to_datetime_nowo  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   rB   r   )r/   r   ZnptodayZpdtodayZpdtoday2ZtstodayZtstoday2r"   r"   r#   test_to_datetime_today  s    	z%TestToDatetime.test_to_datetime_todayrC   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/   rC   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   rA   )r/   r$   r   r"   r"   r#   test_to_datetime_dt64s  s    z%TestToDatetime.test_to_datetime_dt64sz
1000-01-01z
5000-01-02c              	   C   sp   d}t jt|d t|dd W 5 Q R X d| }t jt|d t| W 5 Q R X t|d|dtksltd S )N&Out of bounds .* present at position 0r   raiser   z$Out of bounds nanosecond timestamp: rd   r]   r$   )r   r   r   r   r   r   rB   )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   rz   r   c                 S   s   g | ]}t |jqS r"   )r   asm8rI   r"   r"   r#   rL     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   rd   r   r   r   r[   c                 S   s   g | ]}|  qS r"   )item)rJ   r   r"   r"   r#   rL     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$   r0   r1   r2   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$   r0   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+0500rG   c                 S   s   g | ]}t |qS r"   r   rI   r"   r"   r#   rL     s     zETestToDatetime.test_to_datetime_different_offsets.<locals>.<listcomp>r   r   r   r-   r.   )r/   r$   Zts_string_1Zts_string_2r0   r2   r1   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   rt   r   r{   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   r   r*   r+   Zlocalizer   r,   r   r   r-   r.   )r/   r$   Z
us_easternr0   r1   r2   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_constructorrr   Zexpected_datar1   r2   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   r|   )r/   r$   scalarr2   r1   r"   r"   r#    test_to_datetime_utc_true_scalar3  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$   tsr1   r2   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:00r{   Tr  r   r   r   r   r   r-   r=   )r/   r$   r$  Zexpected_tsrr   r1   r2   r"   r"   r#   4test_to_datetime_utc_true_with_series_tzaware_stringF  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(   r2   r1   r"   r"   r#   1test_to_datetime_utc_true_with_series_datetime_nsN  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rt   r   r{   r   r  r'   rd   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   rB   )
r/   r!   r$   r*  Ztz1Ztz2r0   r1   r2   ir"   r"   r#   test_to_datetime_tz_psycopg2Z  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   rd   r   r[   )r   r   	TypeErrorr   r   rB   r/   r$   rC   r   r"   r"   r#   test_datetime_bool  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        rd   r   )typer   r   r1  r   r   r   r-   r.   r   r   r/   r$   r   r"   r"   r#   test_datetime_bool_arrays_mixed  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   r1  r   )r/   rC   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   sr   t |d||d}||kstt |d||d}|tks8td| d}tjt|d t |d||d W 5 Q R X d S )Nr[   r]   r;   infer_datetime_formatrd   zGis a bad directive in format|second must be in 0..59|Given date string z not likely a datetimer   r   )r   rB   r   r   r   r   r/   r   r;   r:  r   r   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 )Nr[   r;  rd   zCis a bad directive in format|Out of bounds .* present at position 0r   r   r   )r   rB   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|d  d}tjt	|d t |d||d W 5 Q R X d S )	Nr[   r;  rd   z/is a bad directive in format|Given date string r   z. 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$   Frq   )	r/   r   r;   rC  r   
test_datesrr   r1   r2   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/   r1   r2   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 rD  rf   )r/   r   r;   r   rG  rr   r1   r2   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 )NrE  Tr   rA   )r/   r   r1   r2   r"   r"   r#   test_to_datetime_cache_scalar  s    z,TestToDatetime.test_to_datetime_cache_scalarzdatetimelikes,expected_valuesrU   z
2012-07-26Nz2012 July 26c                 C   s4   t |dd}t|dd}t |dd}t|| d S )Nr,   r'   rd   r   r   rf   )r/   ZdatetimelikesZexpected_valuesrR   Zresult_seriesZexpected_seriesr"   r"   r#   *test_convert_object_to_datetime_with_cache  s    z9TestToDatetime.test_convert_object_to_datetime_with_cacher$   )inputr2      r,   r'   (   r   r   x   r   c                 C   s   t ||d}t|| d S r   rn   )r/   r$   rQ  r2   r1   r"   r"   r#   *test_to_datetime_converts_null_like_to_nat<  s    z9TestToDatetime.test_to_datetime_converts_null_like_to_natzdate, format)z2017-20z%Y-%W)	20 Sundayz%W %A)20 Sunz%W %a)z2017-21z%Y-%U)rV  z%U %A)rW  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   rj   r   )r/   r   r;   r   r"   r"   r#   'test_week_without_day_and_calendar_yearW  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20100240rd   r     r{   r   r_   r   i@8  r   iPF  )r   r   r   r	   r   r-   r.   r/   Z
ts_stringsr1   r2   r"   r"   r#   test_to_datetime_coercei  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-11rd   r   )r   r   r   r-   r.   rZ  r"   r"   r#   !test_to_datetime_coerce_malformedz  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:30rU   )r   r   rB   r   r-   r.   )r/   Zts_strr1   r2   r"   r"   r#   &test_iso_8601_strings_with_same_offset  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 )Nr]  2015-11-18 16:30:00+06:30r      r   r   rz   iXM  r      ih[  r'   )
r   r   r*   r+   r   r	   r,   r   r-   r.   rZ  r"   r"   r#   ,test_iso_8601_strings_with_different_offsets  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 )Nr]  r_  Tr   r   r`  r   ry   r   r   )r   r   r   r   r-   r.   rZ  r"   r"   r#   0test_iso_8601_strings_with_different_offsets_utc  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:00Trc  z2018-11-27T12:00:00z2018-11-27T18:00:00rq   rK  r"   r"   r#   -test_iso8601_strings_mixed_offsets_with_naive  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 )Nrf  re  Trc  )r   listreversedr-   r.   )r/   itemsr1   r2   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 )NrV   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 rO  r"   )rJ   r/  rR   valsr"   r#   	<genexpr>  s     zPTestToDatetime.test_mixed_offsets_with_native_datetime_raises.<locals>.<genexpr>r   r'   zTz-aware datetime.datetimer   )r   r   allrangerA  rB   r   to_pydatetimer,   r-   r=   r   r   r   )r/   mixedr2   r"   rm  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  rU   rY  r{   r   r_      r   )r   r   r   r   r   r-   r.   rK  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 )NTrc  r|   )r/   r$  r2   r1   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 )N"Out of bounds nanosecond timestampr   rM   rj   r   r   r   r   )r/   rx  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'   Trc  )	r*   r+   r   r,   r   r   r   r   rB   )r/   r0   r1   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_offrt   r   r   rU   r{   )Z-pandas.tests.indexes.datetimes.test_timezonesr}  r   r   r   rB   )r/   r}  r   r1   r"   r"   r#   test_to_datetime_fixed_offset  s    z,TestToDatetime.test_to_datetime_fixed_offset)Nr   r   r   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   ri  r+   r   r!  r   r#  r%  r(  r)  
skip_if_nor0  r3  r7  boolr   r8  r>  r?  rB  tupler   rH  rL  rM  rN  rV   r   r   rP  r   r   NaNrU  rX  r[  r\  r^  rb  rd  rg  rl  rt  rv  rw  r{  r|  r~  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  rM   )r  r;   r$   r   r6  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  r[   r  r]   r$   
1970-01-02r'   rd   z/cannot convert input 11111111 with the unit 'D'r   r   )r   r   r*   rV   r   r   r   r,   r-   r.   r   r   r   r   r/   r$   r>   r1   r2   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   r[   r   r]   r  r$   r'   rd   z4cannot convert input 1420043460000 with the unit 's'r   r   )r   r   r*   rV   r   r   r,   r-   r.   r   r   r   r   r  r"   r"   r#   $test_unit_array_mixed_nans_large_int5  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   r  r   r6  r"   r"   r#   8test_to_datetime_invalid_str_not_out_of_bounds_valuerrorD  s    zKTestToDatetimeUnit.test_to_datetime_invalid_str_not_out_of_bounds_valuerrorerrorr   rd   r[   c                 C   s6   t d}tdd||d}||ks$tt|t s2td S )Nz1970-05-09 14:25:11r  r   r  )r   r   rB   r<   )r/   r$   r  r2   r1   r"   r"   r#   test_unit_consistencyK  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(   r2   r0   r1   r"   r"   r#   test_unit_with_numericS  s    z)TestToDatetimeUnit.test_unit_with_numericzexp, arrr   r  r  r   r  r  c                 C   s&   t |}t|d|d}t|| d S )Nrd   r   )r   r   r-   r.   )r/   r$   r   r0   r2   r1   r"   r"   r#   test_unit_with_numeric_coerce]  s    z0TestToDatetimeUnit.test_unit_with_numeric_coercez
2013-01-01r4  c              	   C   sR   t |}t|d|d}t|| d}tjt|d t|d|d W 5 Q R X d S )Nrd   r   z,mixed datetimes and integers in passed arrayr   r   )r   r   r-   r.   r   r   r   )r/   r$   r   r0   r2   r1   r   r"   r"   r#   test_unit_mixedq  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.877000192rA   r/   r$   r1   r2   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   BrU   r   r   r[   r   r  r  r/   r$   r2   r1   r"   r"   r#   test_unit_ignore_keeps_name  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   Tr[   )r  r   r]   1970-01-01 00:00:01r   r   r   rK  r"   r"   r#   'test_to_datetime_errors_ignore_utc_true  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"   rJ   tepochr"   r#   rL     s     z<TestToDatetimeUnit.test_to_datetime_unit.<locals>.<listcomp>rR  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#   rL     s     )r   rq  r   r   r-   r=   )r/   r(   rR   r1   r2   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#   rL     s     zGTestToDatetimeUnit.test_to_datetime_unit_with_nulls.<locals>.<listcomp>rR  r   r  c                 S   s   g | ]}t d t|d qS r  r  r  r"   r"   r#   rL     s     )r   rq  r   r   r-   r=   )r/   r  rR   r1   r2   r"   r  r#    test_to_datetime_unit_with_nulls  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#   rL     s     zOTestToDatetimeUnit.test_to_datetime_unit_fractional_seconds.<locals>.<listcomp>r   rU   g      ?r   r  c                 S   s   g | ]}t d t|d qS r  r  r  r"   r"   r#   rL     s   ms)r   r*   Zaranger   r   floatr   r   roundr-   r=   )r/   rR   r1   r2   r"   r  r#   (test_to_datetime_unit_fractional_seconds  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   rU   r   r  r  r  
1970-01-03r{   )r   r   r*   rV   r   r   r-   r.   rK  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   rU   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 )	Nr  r  r   r   rU   r  rd   r  r]   )r   r   r   r-   r.   )r/   r  r2   r1   r"   r"   r#   test_to_timestamp_unit_coerce  s
    z0TestToDatetimeUnit.test_to_timestamp_unit_coerceN)r   r   r   r  r  r  r  r   r   r   r  r  r  r   r  r  r  r  intr  r  r   r*   rV   r  r  r  r  r  r"   r"   r"   r#   r    sX   





	


r  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     rU   r{   rv   rG   r     :   ;   ry   r`  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$   r1   r2   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  rU   r   r  z20160205 00:0:00)r  r   r   r   r-   r=   )r/   r  r$   df2r1   	expected2r"   r"   r#   &test_dataframe_dict_with_constructable  s    z>TestToDatetimeDataFrame.test_dataframe_dict_with_constructabler  Zyearsmonthsdaysr   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   ri  keysrenamer   r   r-   r=   )r/   r  r$   r  r1   r2   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$   dr1   r2   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   rP   r   r   r-   r=   r  r"   r"   r#   test_dataframe_str_dtype6  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  rU   rR  rv   rG   r  zTcannot assemble the datetimes: time data .+ does not match format '%Y%m%d' \(match\)r   r   rd   r   r  )
r   r   r   r   r   r   r   r   r-   r=   )r/   r$   r  r   r1   r2   r"   r"   r#   test_dataframe_coerceA  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_raisesmP  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_raisesX  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  rU   rR  rv   rG   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_raisesk  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  rU   r{   rv   rG   r  Zint16r   r  20160305 00:00:00)r   r   r   r   r   r-   r=   r/   r$   r  r1   r2   r"   r"   r#   test_dataframe_int16z  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  rU   r{   rv   rG   r  r  Zint8r  r   r  r  )r   r   r   r   r   r-   r=   r  r"   r"   r#   test_dataframe_mixed  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 )	Nrt   ru   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_float  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  rU   r{   rv   rG   r  Trc  z
2015-02-04z
2016-03-05r   r'   r   )	r   r   r   r*   r+   r   tz_localizer-   r=   )r/   r  r1   r2   r"   r"   r#   test_dataframe_utc_true  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'   r   r   )r*   r+   r,   r   r   r   r   )r/   r0   r   r"   r"   r#   %test_to_datetime_barely_out_of_bounds  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   rA   )r/   r$   rC   Zexp_strr1   r   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   ru   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 raise)r   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   r6  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 )Nr7   ry   r   r   r   )r   r   r   rB   )r/   r$   rR   r1   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   rd   i  ry   r   r   r[   )	r   r   r   r   r   r   r   r-   r=   )r/   r$   rR   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   rU   r{   index%b %yr:   )r   r   rO   r-   r=   )r/   r$   r   r2   r1   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   rU   r{   r  z4time data '' does not match format '%b %y' \(match\)r   r  r   r\   rd   c                    s   t | dd dS )Nr  rd   r\   )r   rK   r   r"   r#   <lambda>      zOTestToDatetimeMisc.test_to_datetime_with_apply_with_empty_str.<locals>.<lambda>)r   r   r   r   r   rO   r-   r=   )r/   r$   r   r   r2   r1   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   rB   r/   r$   r1   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   rp  rB   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   rB   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   r|   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"   rH   )rJ   date_strr"   r"   r#   rL     s     zITestToDatetimeMisc.test_to_datetime_strings_variation.<locals>.<listcomp>)ri  r   r-   assert_almost_equal)r/   r$   r+   r2   r1   r"   r"   r#   "test_to_datetime_strings_variation  s    
z5TestToDatetimeMisc.test_to_datetime_strings_variationr1   r  c                 C   s   t ddd}||kstd S )Nr^   r   )r   rB   rK  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   1r[   r   Or'   z#invalid string coercion to datetimer   r   )	r   r   r*   r+   r-   r   r   r   r1  )r/   r$   r1   r2   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 )Nr9  d   r[   r   rf   )r/   r$   seriesr1   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   rB   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 )Nr7   rR  r  )r   r   r>   ri  Zasi8r-   r.   )r/   rngZintsr1   r"   r"   r#   !test_to_datetime_list_of_integers3  s
    

z4TestToDatetimeMisc.test_to_datetime_list_of_integersc              	   C   s0   d}t jt|d tdddd W 5 Q R X d S )Nz<Cannot cast 139999 days, 0:00:00 to unit=ns without overflowr   z1/1/1700BrF  )startr   r   )r   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 )	Nr7   r8   z1/4/2000, 12:34:56r'   rv   re   r   r   )r*   r+   rV   r,   empty	enumerater   r   r   r
   Zarray_to_datetimer-   r   r   r<   r   rB   Zassert_numpy_array_equalr>   )r/   r$   stringsr2   r/  r   r1   result2r"   r"   r#   test_string_na_nat_conversionD  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   r[   )r*   r+   rV   r,   r   r   r   r   r   r-   r.   )r/   r$   Z	malformedr   r1   r2   r"   r"   r#   'test_string_na_nat_conversion_malformedY  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 )Nr9  r@  cr  er7   r9   z1/5/2000r   r  r   r   rG   re   r'   r  F)Zcheck_names)r   r*   rV   r   r  rq  r   r   r-   r=   r   rB   )
r/   r$   idxr  Zdseriesr1   Zdresultr2   r/  rK   r"   r"   r#   'test_string_na_nat_conversion_with_namei  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_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/2014ra   rU   ry   r`  r_   Tr  r  )	r   r   r*   r+   r   r   r   r-   r.   )
r/   r$   r0   r2   Zidx1Zidx2Zidx3Zidx4Zidx5Zidx6r"   r"   r#   test_dayfirst  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 )NParsing dates in DD/MM/YYYY format when dayfirst=False \(the default\) was specified. This may lead to inconsistently parsed dates! Specify a format to ensure 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_firstr0   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  zParsing dates in MM/DD/YYYY format when dayfirst=True was specified. This may lead to inconsistently parsed dates! Specify a format to ensure 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_firstr0   r2   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-05r{   r  r   r   Trc  )r   r  r  r   r-   r   )r/   r&  r   r2   objr1   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    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_arrayrB   )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+   rV   rB   )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   r   r   r   r   r*   rV   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 )Nr5   2   Hr   r   c                    s
   |   S rO  )strftimer  r1  r"   r#   r  /  r  zdTestToDatetimeInferFormat.test_to_datetime_infer_datetime_format_consistent_format.<locals>.<lambda>r:   Fr<  r$   T)r   r   rO   r   r-   r=   )r/   r$   r1  rR   Zs_as_dt_stringsZwith_formatZno_inferZ	yes_inferr"   r6  r#   8test_to_datetime_infer_datetime_format_consistent_format'  s        zRTestToDatetimeInferFormat.test_to_datetime_infer_datetime_format_consistent_formatrr   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 )NFr7  T)r   r*   r+   r-   r=   r   )r/   r$   rr   rR   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 )Nr9  01/03/2011 00:00:00r'   Fr7  Tr   r*   r+   rV   r,   r-   r=   r   r/   r$   rR   r"   r"   r#   7test_to_datetime_infer_datetime_format_series_with_nansO  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 )Nr9  z01/02/2011 00:00:00r;  r'   Fr7  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   rR   r1   r2   r"   r"   r#   "test_infer_datetime_format_tz_namen  s    z<TestToDatetimeInferFormat.test_infer_datetime_format_tz_namez
ts,zero_tz)rA  Z)rA  r   )2019-02-02 08:07:13.012345rC  )rD  r   c                 C   sN   t || g}t|dd}|dkr(tjnd }t t||dg}t|| d S )NTr"  rC  r   )r   r   r   r   r   r-   r=   )r/   r$  Zzero_tzrR   r1   r   r2   r"   r"   r#   "test_infer_datetime_format_zero_tzz  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-03r:   )r   r   r-   r=   r   )r/   r$   r;   rR   r2   r"   r"   r#   %test_to_datetime_iso8601_noleading_0s  s    z?TestToDatetimeInferFormat.test_to_datetime_iso8601_noleading_0s)r   r   r   r   r   r   r8  r:  r>  r?  rB  rE  rH  r"   r"   r"   r#   r0  &  s<    


 
		
r0  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-29NrF  z
2015-02-32z
2015-04-31c                 C   s   t t|d||dstd S )Nrd   r]   r;   r$   )r   r   rB   )r/   r$   rC   r;   r"   r"   r#   test_day_not_in_month_coerce  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   rJ  r   r   r   r6  r"   r"   r#   test_day_not_in_month_raise  s    z+TestDaysInMonth.test_day_not_in_month_raiserC   c              	   C   s:   d| d}t jt|d t|dd|d W 5 Q R X d S )Nztime data "z." at position 0 doesn't match format specifiedr   r   rF  rK  r   r2  r"   r"   r#   !test_day_not_in_month_raise_value  s    z1TestDaysInMonth.test_day_not_in_month_raise_valuezexpected, formatc                 C   s    t |d||d}||kstd S )Nr[   rK  r|   )r/   r$   r2   r;   r1   r"   r"   r#   test_day_not_in_month_ignore  s    
z,TestDaysInMonth.test_day_not_in_month_ignore)
r   r   r   r   r   r   rL  rM  rN  rO  r"   r"   r"   r#   rI    s*   	

	rI  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  rv   r  rt   ry   r`  r   rG   	   r      r   i     $      ra   r  ru   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'   )rX  r$   Sr   )r   r   rX  )r   parse_time_stringr   r*   r+   r,   r   r   r   rB   r   r-   r.   r   )r/   r  r2   r$   rX  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_fixture2r2   r1   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   rZ  r   r   r   r   rB   )r/   r[  r\  r  r]  r^  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  rR     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  rX  )r  rX  r$   r   )r   rB   r   rZ  r   r   r   )r/   r$   r  r  rX  r2   Zdateutil_resultr[  r\  r  r]  r^  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   rZ  r   r   r   rB   )
r/   r  Zexp_defZexp_nowr[  r\  r  r]  r^  r_  r"   r"   r#   test_parsers_timestringy	  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  r   rB   repr)r/   r$   Z	dt_stringr   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   ri  r   rk  r`  ra  rb  rd  re  r   r   rg  r"   r"   r"   r#   rP    s   
































4

D&
rP  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#   units	  s    
rh  c                   C   s   t dS )zTimestamp at 1960-01-01.
1960-01-01rH   r"   r"   r"   r#   
epoch_1960	  s    rj  c                   C   s   t tdS )NrG   )ri  rq  r"   r"   r"   r#   units_from_epochs	  s    rk  	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
    >   rl  rn  rm  r   rl  rm  r   N)r   rB   rr  Zto_datetime64rP   )rj  r!   r"   r"   r#   epochs	  s    	


ro  c                   C   s   t ddd jS )NrG  ry   r  )r   to_julian_dater>   r"   r"   r"   r#   julian_dates	  s    rq  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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d0ggd1d2 ZdS )3
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   rp  r-   r=   )r/   rq  r1   r2   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   rU   r  unixrt  z
1970-01-01r  r  r'  rK  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|% rs  r  ru  r  z&1 is Out of Bounds for origin='julian'r   r   )r   rp  rB   r   r   r   )r/   r1   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   rs  rt  r   )r/   rh  rq  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-01ri  ry  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	TimedeltarI   rj  rh  r"   r#   rL   
  s     z)TestOrigin.test_epoch.<locals>.<listcomp>rt  rf   )r/   rh  ro  rj  rk  r2   r1   r"   r}  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   rt  )r   r   r   )r/   ru  excrh  rk  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  rt   r   rt  )r   r   r   r   r   r   r   r  r"   r"   r#   test_invalid_origins_tzinfo
  s    z&TestOrigin.test_invalid_origins_tzinfoc              	   C   s*   t jtdd tddg W 5 Q R X d S )Nz6Unknown string format: yesterday present at position 1r   r   Z	yesterdayr   r  r"   r"   r#   test_incorrect_value_exception"
  s
     z)TestOrigin.test_incorrect_value_exceptionr;   Nz%Y-%m-%d %H:%M:%Sc              	   C   s.   d}t jt|d td|d W 5 Q R X d S )NzMOut of bounds nanosecond timestamp: 2417-10-27 00:00:00 present at position 0r   z2417-10-27 00:00:00rj   rz  )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( rw  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  rt  r  r  r  r  r  rA   )r/   rC   ru  Zexpected_strr1   r2   r"   r"   r#   test_processing_order3
  s    z TestOrigin.test_processing_orderzoffset,utc,exprC  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   rq   )r/   r   r   r   rC   r1   r2   r"   r"   r#   test_arg_tz_ns_unitK
  s    
zTestOrigin.test_arg_tz_ns_unit)r   r   r   rv  rx  rz  r{  r   r   r   r|  r~  r   r   r   r  r  r  r  r  r  r"   r"   r"   r#   rr  	  sJ   
	
		

	
	rr  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   rU   r{   rv   rG   r  r  rR  rQ  r   FTc                 C   s    t j|t|dd|kstd S )Ngffffff?)check_countunique_share)r,  should_cacherA  rB   )r/   listlikeZ
do_cachingr"   r"   r#   test_should_cache]
  s    	z!TestShouldCache.test_should_cachez%unique_share,check_count, err_message)g      ?r`  z5check_count must be in next bounds: \[0; len\(arg\)\])ry   rU   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 )NrG   ry   r   )r   r   rB   r,  r  )r/   r  r  Zerr_messagerC   r"   r"   r#   test_should_cache_errorsj
  s    
z(TestShouldCache.test_should_cache_errorsr  rI  rJ  c                 C   s   t |dkstd S )NT)r,  r  rB   )r/   r  r"   r"   r#   &test_no_slicing_errors_in_should_cachew
  s    
z6TestShouldCache.test_no_slicing_errors_in_should_cacheN)r   r   r   r   r   r   r  r  r   r   r  r  r"   r"   r"   r#   r  \
  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 )Nr   rU   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=   )rR   Zser_copyr   r2   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   )r<   r   r   r   r1  r   r   rB   )Znulls_fixturer&  r1   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   r6   rd   rm   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;   r1   r2   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 )Nr   r   r   rd   r  r  r   r   r'   r   r   )r1   r2   r"   r"   r#   'test_empty_string_datetime_coerce__unit
  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   rU   r{   r  r  r  r  z1970-01-01 00:00:00.000000003r   r  )r  Z	DataArrayr   r   r-   r.   )Zxrr0   r1   r2   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YSr4  FZDTr  r   )nZrandom_statei  r   r   )r   r   r   Zto_framesampler  Z	to_seriesr   r  r   r   r-   r=   )r$   Zcstarttimesr1   r2   r"   r"   r#   +test_to_datetime_monotonic_increasing_index
  s    r  series_lengthrS  r   rG   c              	   C   s   t tdgtdg|   }t|ddd}t tgtdg|   }t|| t|ddd}t tdgtdg|   }t|| tj	t
dd t|d	dd W 5 Q R X d S )
Nz1446-04-12 00:00:00+00:00z1991-10-20 00:00:00+00:00rd   T)r]   r   r[   ry  r   r   )r   r   fromisoformatr   r   r   r-   r=   r   r   r   )r  r   r[  Z	expected1r  r  r"   r"   r#   2test_to_datetime_cache_coerce_50_lines_outofbounds
  s&    

r  rC   z1724-12-20 20:20:20+00:002022-01-01 00:00:00i  r_   rR  r   i  stringzpd.Timestampzdatetime.datetime)idstz_aware_firstc                 C   sF   ddg}|s|    |   t| dd}t|d}t|| d S )Nz1724-12-20 20:20:20r  Trc  r   )reverser   r   r  r-   r.   )rC   r  Zexp_argr1   r2   r"   r"   r#   1test_to_datetime_mixed_tzaware_timestamp_utc_true  s    r  c               
   C   s<   d} d}t | |d}tddddddd	d
d}||ks8td S )Nz15/02/2020 02:03:04.123456789z%d/%m/%Y %H:%M:%S.%frj   r   rU   r   r{   rv   i@ i  )r  r  r  r  r  r  microsecondZ
nanosecondrA   )rl  Ztimestamp_formatr1   r2   r"   r"   r#   %test_to_datetime_format_f_parse_nanos  s    
r  )X__doc__r~   collectionsr   r   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   r  r  r  r)  r0  rI  rP  rh  rj  rk  ro  rq  rr  r  r  r   r   r+   ri  r  r  r  r  r  r  r  r   r  r  r"   r"   r"   r#   <module>   s   ,
         H J H  ms( i




 (



"