o
    i                    @   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j7g d(dd)d* ZBej7d+d, ZCej7d-d. ZDej7g d/dd0d1 ZEej7d2d3 ZFG d4d5 d5ZGG d6d7 d7ZHd8d9 ZIejJKd:ejLeMgd;d< ZNd=d> ZOd?d@ ZPeQdAdBdC ZRejJKdddgdDdE ZSejJKdFdGe4e4dH e4dI gdJdK ZTejJjKdLdMdNge'dMe'dNgedOdPdQdQdQdQejUdRedSdHdHggg dTdUejJKdVddgdWdX ZVdYdZ ZWdS )[z 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      | j S )z/
    cache keyword to pass to to_datetime.
    paramrequest r#   ^/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/pandas/tests/tools/test_to_datetime.pycache3   s   r%   c                   @   sD  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g dg dg dg dg dg dgdd Zdd Zdd Zdd Zd d! Zejd"g d#d$d%ejgd$d%egg d&g d'd(d)ejgd(d)egg d*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d0ejd1d2gee	d3ejejejgged0d1ejd2gee	d3ejejejgggd4d5 Zejd6ejgd7ed8gfejgd9ed8gfejd:gd7ed8d;gfd<ejgd=ed>d8gfd<ejgd?ed@d8gfd<ejgd9ed@d8gfd9ejejgd9eg dAfd9ejejgdBeg dAfgdCdD ZdEdF ZejdGdHedIdJdKgdLedMdNdOgdPdPgdQdQgdRdRgdSdSggdTdU ZdVdW ZejdXdYdZe	d[gd\d]e	d^gd_d`e	dagejdbdce	ddejje  de dfv dgddhdiejdjdce	dkejje  de dfv dgddhdiejdldme	dnejje  de dfv dgddhdigdodp Z!e"j#dqdr Z$ejdsg dtdudv Z%ejdwdxdye	dzgd{d|e	d}ggd~d Z&ejdddgd e	dddgd gdg d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'(dede	de'(dedgggdd Z)dd Z*ejdg ddd Z+dd Z,d9S )TestTimeConversionFormatsreadonlyTFc                 C   s>   t jg td}|r|jdd t|}tg }t|| d S )NdtypeF)write)nparrayobjectsetflagsr   tmassert_index_equal)selfr'   arrresultexpectedr#   r#   r$   test_to_datetime_readonly<   s   z3TestTimeConversionFormats.test_to_datetime_readonlyboxzformat, expected%d/%m/%Y200001012000020120000301%m/%d/%Y2000010220000103c                 C   sL   |g d}t |||d}||}t|trt|| d S t|| d S )N)1/1/20001/2/20001/3/2000formatr%   )r   
isinstancer   r/   assert_series_equalr0   )r1   r%   r6   rB   r4   valuesr3   r#   r#   r$   test_to_datetime_formatF   s   
z1TestTimeConversionFormats.test_to_datetime_formatzarg, expected, format)r>   r8   r7   )r>   r8   r;   )r?   r9   r7   )r?   r<   r;   )r@   r:   r7   )r@   r=   r;   c                 C   s&   t |||d}t|}||ksJ d S NrA   r   r   )r1   r%   argr4   rB   r3   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      g | ]}t |qS r#   r   .0xr#   r#   r$   
<listcomp>o       zNTestTimeConversionFormats.test_to_datetime_format_YYYYMMDD.<locals>.<listcomp>%Y%m%drA   r   applystrr   r/   rD   r1   r%   serr4   r3   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 )
NrK   rL   rM   1980122219810105   rU   rA   nat)	r   r   r+   nanr   r/   rD   rW   rX   )r1   r%   rZ   r4   r3   ser2r#   r#   r$   )test_to_datetime_format_YYYYMMDD_with_natw   s   


zCTestTimeConversionFormats.test_to_datetime_format_YYYYMMDD_with_natc                 C   sV   t g d}t|dd|d}t tdddtdddtd	ddgtd
}t|| d S )Ni3iT3irU   ignorerB   errorsr%             i'  r(   )r   r   r   r-   r/   rD   r1   r%   rZ   r3   r4   r#   r#   r$   'test_to_datetime_format_YYYYMMDD_ignore   s    zATestTimeConversionFormats.test_to_datetime_format_YYYYMMDD_ignorec                 C   s<   t g d}t|dd|d}t g ddd}t|| d S )Nrc   rU   coercere   )2012123120141231r   M8[ns]r(   r   r   r/   rD   rk   r#   r#   r$   )test_to_datetime_format_YYYYMMDD_coercion   s   zCTestTimeConversionFormats.test_to_datetime_format_YYYYMMDD_coercioninput_s)r\   20010112Nr\   rt   )r\   rt   r   )rK   T1NrK   ru   )rK   ru   r   c                 C   s6   t tdtdtg}t t|dd}t|| d S )Nr\   rt   rU   rB   )r   r   r   r   r/   rD   r1   rs   r4   r3   r#   r#   r$   *test_to_datetime_format_YYYYMMDD_with_none   s   zDTestTimeConversionFormats.test_to_datetime_format_YYYYMMDD_with_nonezinput_s, expected2001001210019999i]4iT1i{120190813c                 C   s   t |ddd}t|| d S )NrU   rm   rB   rf   r   r/   rD   rw   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%Sr   N20210202202020z2021-02-02 20:20:20201010z%y%m%dz
2020-10-10z%d%m%yz
2010-10-20)r   r   r   rU   c                 C   s   t ||d}t|| d S Nrv   r   r/   r0   )r1   datarB   r4   r3   r#   r#   r$   test_to_datetime_with_NA   s   z2TestTimeConversionFormats.test_to_datetime_with_NAc                 C   s   t g d}t dd |tD }t|d|d}t|| t g d}t dd |tD }t|d|d}t|| d S )	N)    i  c                 S   rN   r#   rO   rP   r#   r#   r$   rS      rT   zMTestTimeConversionFormats.test_to_datetime_format_integer.<locals>.<listcomp>z%YrA   )iA i i c                 S   s,   g | ]}t |d d d |dd   qS )N   -rO   rP   r#   r#   r$   rS      s   , z%Y%mrV   rY   r#   r#   r$   test_to_datetime_format_integer   s   z9TestTimeConversionFormats.test_to_datetime_format_integerzint_date, expectedi3rg   
      i i     r   iuwi(3iA iI  c                 C   s   t |ddd}||ksJ d S )NrU   rd   r|   r   )r1   int_dater4   r3   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 J d S )Nr   z01-z-2011 00:00:01.978z%d-%b-%Y %H:%M:%S.%frA   )calendar
month_abbrr   r   strptime)r1   r%   r   valrB   r3   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)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J d S rG   r   )r1   r%   valuerB   dtr#   r#   r$   test_to_datetime_format_time  s   -z6TestTimeConversionFormats.test_to_datetime_format_timec                 C   sF   t g d}t|dd|d}t|jjdddd|d}t|| d S )N)19MAY11foobar19MAY11z19MAY11:00:00:00z19MAY11 00:00:00Zz%d%b%yF)rB   exactr%   z(\d+\w+\d+))expandrA   )r   r   rX   extractr/   rD   rk   r#   r#   r$   test_to_datetime_with_non_exactD  s   z9TestTimeConversionFormats.test_to_datetime_with_non_exactrI   )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J d S )Nr%   %Y-%m-%d %H:%M:%S.%frA   r   )r1   r%   rI   r4   r3   r#   r#   r$   #test_parse_nanoseconds_with_formulaR  s   z=TestTimeConversionFormats.test_parse_nanoseconds_with_formulazvalue,fmt,expected2009324z%Y%W%wz
2009-08-132013020z%Y%U%wz
2013-01-13c                 C   s   t |||d|ksJ d S rG   r   )r1   r   fmtr4   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 %Z2010-01-01 12:00:00 UTCr^   2010-01-01 12:00:00UTCtz)r   z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 r   )r   r   r/   assert_equal)r1   r   datesexpected_datesr3   r4   r#   r#   r$   )test_to_datetime_parse_tzname_or_tzoffsetn  s   5zCTestTimeConversionFormats.test_to_datetime_parse_tzname_or_tzoffsetc                 C   s:   g d}g d}d}t ||dd}t|}t|| d S )N)r   r   z2010-01-01 12:00:00 +0300z2010-01-01 12:00:00 +0400)z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)rB   utcr   r   r/   r0   )r1   r   r   r   r3   r4   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offset)z+0z-1fooUTCbarz:10z
+01:000:01 c                 C   sR   d}d| }d}t jt|d t|g|d W d    d S 1 s"w   Y  d S )Nr   z2010-01-01 12:00:00 z.does not match format|unconverted data remainsmatchrv   pytestraises
ValueErrorr   )r1   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namerv   r   r   )r   r   )r   r   r   r/   r0   )r1   r   rI   r3   r4   r#   r#   r$   *test_to_datetime_parse_timezone_keeps_name  s
   zDTestTimeConversionFormats.test_to_datetime_parse_timezone_keeps_name)-__name__
__module____qualname__r   markparametrizer5   r   r   r   rF   rJ   r[   rb   rl   rr   r+   r`   r   rx   r~   pdNAr   r   r   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&   ;   sx   
		








	


,






	

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g dg dg dg dg dg dg dg dg dg dg dg dg d gd!d" Z
ejd#d$d%gd&d' Zd(d) Zd*d+ Zd,d- Zejd.d/ Zejejd#d0d1gd2d3 Zejd4d5d6gd7d8 Zejd9ed:ed;gd<d= Zejd9ed>ed?gd@dA ZejdBdCdDgdEdF ZdGdH ZdIdJ ZdKdL ZdMdN ZejdOeefeefej efe!e!fgdPdQ Z"ejdRdSe#dTdUdVgdWe#dXdUdVggdYdZ Z$d[d\ Z%d]d^ Z&ejd_d`dagdbdc Z'e(dddedf Z)ejd4dgdhgdidj Z*dkdl Z+ejd4e,e-gdmdn Z.ejdodpdqgejdrdgdhgejdsd$dtgdudv Z/ejdodwgejdrdgdhgejdsd$dtgdxdy Z0ejdzdpgdqgg d{gejdrdgdhgejdsd$dtgd|d} Z1ejdUdgd$gejdsd~d$gejdee2ej ee3gdd Z4dd Z5ejdUdgd$gejdsd~d$gdd Z6dd Z7ejdd$ej8fe9fe:  e9fe:d  fd$e#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ddgdhgejde!e9gd d$gd  dde!e9gd ddfe!e9gd d$gd  dde!e9gd ddfe!d$gd e!e9gd ddfe!d$g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dg ddd Z@dd ZAdd ZBdd ZCdd ZDdd ZEdd ZFdd ZGdd ZHdd ZIejde#de#dddVfe#dddVe#dddVfgdd ZJejdg ddd ZKdd ZLdd ZMd$S )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/   r0   )r1   d1d2resr4   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sJ t|jd |ks#J 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+   str_r   r   r   ilocr   r/   r0   rD   )r1   r   rZ   r   r   r4   r#   r#   r$   test_to_datetime_np_str  s   



z&TestToDatetime.test_to_datetime_np_strzs, _format, dtz2015-1-1z%G-%V-%urj   rh      r   z2015-1-4  r   z2015-1-7r   c                 C   s   t ||d|ks
J d S r   r   )r1   s_formatr   r#   r#   r$   %test_to_datetime_iso_week_year_format  s   
z4TestToDatetime.test_to_datetime_iso_week_year_formatzmsg, s, _format)xISO 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 %V)xISO 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 %V)r   z1999 Mondayz%G %A)r   z1999 Monz%G %a)r   1999 6z%G %w)r   r   z%G %u)r   2051z%G)z`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 %j)dISO week directive '%V' is incompatible with the year directive '%Y'. Use the ISO year '%G' instead.z1999 51 Sundayz%Y %V %A)r   z1999 51 Sunz%Y %V %a)r   	1999 51 1z%Y %V %w)r   r   z%Y %V %u)r   20z%Vc                 C   s`   t  dkr,t  dkr.tjt|d t||d W d    d S 1 s%w   Y  d S d S d S )N)r   UTF-8)r   r   r   rv   )r   r   r   r   r   r   )r1   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|}||u sJ d S )Nz
1965-04-03   2W)periodsfreqr   )r   r   r   )r1   r   dtir2   r3   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J d S )N  r      r   r   r1   actualr#   r#   r$   test_to_datetime_pydatetimeb  s   z*TestToDatetime.test_to_datetime_pydatetimec                 C   s    t d}|tdddksJ d S )N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J d S )NzMonth 1, 1999rd   rf   r   )r1   rZ   r#   r#   r$   "test_to_datetime_unparsable_ignorej  s   z1TestToDatetime.test_to_datetime_unparsable_ignorec              	   C   s   t db d}t jt|dd tdd}td}tdgd }W d    n1 s.w   Y  t|j	|tj
 dk sBJ t|j	|tj
 dk sQJ |jd u sXJ |jd u s_J W d    d S 1 sjw   Y  d S )	N
US/Eastern&The parsing of 'now' in pd.to_datetimeFr   check_stacklevelnowdatetime64[ns]r       _B)r/   set_timezoneassert_produces_warningFutureWarningr+   
datetime64astyper   absr   int64r   )r1   r   npnowpdnowpdnow2r#   r#   r$   test_to_datetime_nowo  s   "z#TestToDatetime.test_to_datetime_nowzPacific/AucklandzUS/Samoac                 C   s   t |h tddtj}td}tdgd }td}t }t	|
 j| dk s2J t	|
 j| dk s?J t	|j|j dk sKJ t	|j|j dk sWJ |jd u s^J |jd u seJ W d    d S 1 spw   Y  d S )Ntodayr  r   r  )r/   r  r+   r  r  r  r   r   r  r  	normalizer   r   )r1   r   nptodaypdtodaypdtoday2tstodaytstoday2r#   r#   r$   test_to_datetime_today  s   	"z%TestToDatetime.test_to_datetime_todayrI   r  r  c                 C   sT   |dkrt nd }d}tj||dd t|g W d    d S 1 s#w   Y  d S )Nr  r  Fr  )r  r/   r  r   )r1   rI   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J d S Nr   rH   )r1   r%   r   r#   r#   r$   test_to_datetime_dt64s  s   z%TestToDatetime.test_to_datetime_dt64sz
1000-01-01z
5000-01-02c                 C   s   d}t jt|d t|dd W d    n1 sw   Y  d| }t jt|d t| W d    n1 s:w   Y  t|d|dtu sJJ d S )N&Out of bounds .* present at position 0r   raiser	  z$Out of bounds nanosecond timestamp: rm   rf   r%   )r   r   r   r   r   r   )r1   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 d    n1 sAw   Y  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(  r   r   c                 S   s   g | ]}t |jqS r#   )r   asm8rP   r#   r#   r$   rS     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	  rm   r-  r   r   rd   c                 S   s   g | ]}|  qS r#   )item)rQ   r   r#   r#   r$   rS     rT   )r+   r  r/   r0   r   r   r   r   r   r   r1  r   r   )r1   r%   r/  dtsdts_with_oobr   r#   r#   r$   test_to_datetime_array_of_dt64s  s4   


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/   r0   )r1   r%   r2   r3   r4   r#   r#   r$   test_to_datetime_tz  s   

z"TestToDatetime.test_to_datetime_tzc                 C   s\   t dddt dddg}d}tjt|d t||d W d    d S 1 s'w   Y  d S )	Nr6  r   r   r7  r  zLTz-aware datetime.datetime cannot be converted to datetime64 unless utc=Truer   r   )r   r   r   r   r   )r1   r%   r2   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+0500rM   c                 S   rN   r#   r   rP   r#   r#   r$   rS     rT   zETestToDatetime.test_to_datetime_different_offsets.<locals>.<listcomp>r   r   r   r/   r0   )r1   r%   ts_string_1ts_string_2r2   r4   r3   r#   r#   r$   "test_to_datetime_different_offsets  s   z1TestToDatetime.test_to_datetime_different_offsetsc                 C   st   t d}tj|tdddddd|tddddddgtd}t|d	|d
}tddgdd d}t	
|| d S )Nr  r   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,   localizer   r-   r   r   r/   r0   )r1   r%   
us_easternr2   r3   r4   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rB   r   r%   )r   r   r/   r   )r1   r%   init_constructorend_constructorr   expected_datar3   r4   r#   r#   r$   test_to_datetime_utc_true  s   

z(TestToDatetime.test_to_datetime_utc_truezscalar, expectedrN  rP  r   r   rO  rQ  c                 C   s    t |dd|d}||ksJ d S )NrR  TrS  r   )r1   r%   scalarr4   r3   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 {ѴCTrF  r   r   )r   r   r   r/   rD   )r1   r%   tsr3   r4   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   TrF  r   r   r   r   r   r/   rD   )r1   r%   rZ  expected_tsr   r3   r4   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\  rI  c                 C   s:   t tdddg}tt |g|dd|d}t|| d S )Nr\  r   r   r(   TrF  )r   r   r   r/   rD   )r1   r%   r   r)   r4   r3   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|	soJ 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r   r   r   r   rE  r(   rm   T)rf   r   r%   rG  rH  rI  rJ  z2000-01-01 08:00:00r   r-  z2000-01-01 13:00:00)ra  node
add_markerr   r   r   r   __version__splitAttributeErrorr   FixedOffsetTimezoner+   r,   r   r-   r   r   r/   r0   r   )
r1   r"   r%   ra  tz1tz2r2   r3   r4   ir#   r#   r$   test_to_datetime_tz_psycopg2Z  sB   	z+TestToDatetime.test_to_datetime_tz_psycopg2TFc                 C   sj   d}t jt|d t| W d    n1 sw   Y  t|d|dtu s(J t|d|d|u s3J d S )Nz2dtype bool cannot be converted to datetime64\[ns\]r   rm   r-  rd   )r   r   	TypeErrorr   r   r1   r%   rI   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 d    n1 s#w   Y  tjt|d tddg|d W d    n1 sBw   Y  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        rm   r-  )typer   r   rl  r   r   r  r/   r0   r   r   r1   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 d    d S 1 sw   Y  d S )Nzis not convertible to datetimer   )r   r   rl  r   )r1   rI   r   r#   r#   r$   test_datetime_invalid_datatype  s   
"z-TestToDatetime.test_datetime_invalid_datatyper   az00:01:99inferrB   zH%:M%:S%c                 C   s   t |d||d}||ksJ t |d||d}|tu sJ d| d}tjt|d t |d||d W d    d S 1 s=w   Y  d S )Nrd   rf   rB   infer_datetime_formatrm   zGis a bad directive in format|second must be in 0..59|Given date string z not likely a datetimer   r,  )r   r   r   r   r   r1   r   rB   ru  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J t |d||d}|tu sJ |d urDd}tjt|d t |d||d W d    d S 1 s=w   Y  d S d}tjt|d t |d||d W d    d S 1 saw   Y  d S )Nrd   rv  rm   zCis a bad directive in format|Out of bounds .* present at position 0r   r,  r+  )r   r   r   r   r   r   rx  r#   r#   r$    test_datetime_outofbounds_scalar  s*   ""z/TestToDatetime.test_datetime_outofbounds_scalarrE   )rt  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 d    d S 1 sHw   Y  d S )	Nrd   rv  rm   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/   r0   r   r   r   lenr   r   r   )r1   rE   rB   ru  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   rB   r%   Fr   )	r1   r   rB   r~  r   
test_datesr   r3   r4   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/   r0   r1   r3   r4   r#   r#   r$   test_to_datetime_from_deque  s   z*TestToDatetime.test_to_datetime_from_dequec                 C   sF   d}|gd }t |}t|||dd}t|||dd}t|| d S r  rq   )r1   r   rB   r   r  r   r3   r4   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J d S )Nr  Tr   rH   )r1   r   r3   r4   r#   r#   r$   test_to_datetime_cache_scalar  s   z,TestToDatetime.test_to_datetime_cache_scalarzdatetimelikes,expected_valuesr^   z
2012-07-26Nz2012 July 26c                 C   s4   t |dd}t|dd}t |dd}t|| d S )Nr-   r(   rm   r	  r  rq   )r1   datetimelikesexpected_valuesrZ   result_seriesexpected_seriesr#   r#   r$   *test_convert_object_to_datetime_with_cache  s   z9TestToDatetime.test_convert_object_to_datetime_with_cacher%   )inputr4      r-   r(   (   r  r   x   r   c                 C   s   t ||d}t|| d S r)  r}   )r1   r%   r  r4   r3   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)r  z%U %A)r  z%U %ac                 C   sD   d}t jt|d t||d W d    d S 1 sw   Y  d S )Nz,Cannot use '%W' or '%U' without day and yearr   rv   r   )r1   r   rB   r   r#   r#   r$   'test_week_without_day_and_calendar_yearW  s   "z6TestToDatetime.test_week_without_day_and_calendar_yearc                 C   s^   g d}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 )N)r:  r;  20100240rm   r	    r   r   rh   r   i@8  r   iPF  )r   r   r   r	   r   r/   r0   r1   
ts_stringsr3   r4   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-11rm   r	  )r   r   r   r/   r0   r  r#   r#   r$   !test_to_datetime_coerce_malformedz  s   z0TestToDatetime.test_to_datetime_coerce_malformedc                 C   sj   d}t |}t|}||ksJ tt|gd }t |gd }t|| t|gd }t|| d S )N2015-11-18 15:30:00+05:30r^   )r   r   r   r/   r0   )r1   ts_strr3   r4   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  r   iXM  r      ih[  r(   )
r   r   r+   r,   r   r	   r-   r   r/   r0   r  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   r   r   r   )r   r   r   r   r/   r0   r  r#   r#   r$   0test_iso_8601_strings_with_different_offsets_utc  s   
z?TestToDatetime.test_iso_8601_strings_with_different_offsets_utcc                 C   s0   t g ddd}t g ddd}t|| d S )N)2018-11-28T00:00:002018-11-28T00:00:00+12:00r  z2018-11-28T00:00:00+06:00r  Tr  )r  z2018-11-27T12:00:00r  z2018-11-27T18:00:00r  r   r  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 )Nr  r  Tr  )r   listreversedr/   r0   )r1   itemsr3   r4   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J t }tdt dt d t d d gtd}t	|| t
jtd	d
 t| W d    d S 1 sUw   Y  d S )Nr`   z
1990-01-01z2015-03-14T16:15:14.123-08:00z2019-03-04T21:56:32.620-07:00c                 3   s     | ]} | | u V  qd S r  r#   )rQ   rj  rZ   valsr#   r$   	<genexpr>  s    zPTestToDatetime.test_mixed_offsets_with_native_datetime_raises.<locals>.<genexpr>r   r(   zTz-aware datetime.datetimer   )r   r   allranger|  r   to_pydatetimer-   r/   rD   r   r   r   )r1   mixedr4   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:  r^   r  r   r   rh      r   )r   r   r   r   r   r/   r0   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J d S )NTr  r   )r1   rZ  r4   r3   r#   r#   r$   test_timestamp_utc_true  s   z&TestToDatetime.test_timestamp_utc_truedt_str)00010101130001013000010199990101c                 C   sD   d}t jt|d t|dd W d    d S 1 sw   Y  d S )N"Out of bounds nanosecond timestampr   rU   rv   r   r   r   r   )r1   r  r   r#   r#   r$   *test_to_datetime_with_format_out_of_bounds  s   "z9TestToDatetime.test_to_datetime_with_format_out_of_boundsc                 C   s4   t jtdgtd}t|dd}|jtju sJ d S )Nz2012-06-13T01:39:00Zr(   Tr  )r+   r,   r   r-   r   r   r   r   )r1   r2   r3   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s(J d S )Nr   )	fixed_offr   r   r   r^   r   )-pandas.tests.indexes.datetimes.test_timezonesr  r   r   r   )r1   r  r   r3   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   skip_if_windowsr  r$  r&  r+   r  r*  r.  r5  r8  r9  r?  rM  r   r   r  r,   r   rW  r   rY  r[  r_  r`  
skip_if_nork  rn  rr  boolr   rs  ry  rz  r}  tupler   r  r  r  r  r`   r   r   r  r   r   NaNr  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r#   r#   r#   r$   r     s^   

S




	
%

	


0




    





r   c                	   @   st  e Zd Zdd Zdd Zdd Zdd Zej	d	g d
dd Z
ej	dg dej	dddgdd Zej	dg dg dgg dg dggdd Zej	dg dedddggg d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	d1d2d3gd4d5 Zej	d1d2d3gd6d7 Zd8S )9TestToDatetimeUnitc                 C   sJ   d}t jt|d tdgdd|d W d    d S 1 sw   Y  d S )Nz#cannot specify both format and unitr   r   r0  rU   )r/  rB   r%   r   rq  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
g d}t	|| d}tjt|d t|dd|d W d    d S 1 s\w   Y  d S )NǊ r   g      ?r   r   r0  rd   r/  rf   r%   
1970-01-02r(   rm   )r   r  r  r   r   r   r   r   z/cannot convert input 11111111 with the unit 'D'r   r,  )r   r   r+   r`   r   r   r   r-   r/   r0   r   r   r   r   r1   r%   rE   r3   r4   r   r#   r#   r$   test_unit_array_mixed_nans  s0   
"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	g d}t|| d	}t
jt|d
 t|dd|d W d    d S 1 sRw   Y  d S )Nl   _B*r   rd   r   rf   r/  r%   r(   rm   )r   r   r   r   r   z4cannot convert input 1420043460000 with the unit 's'r   r,  )r   r   r+   r`   r   r   r-   r/   r0   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   sH   d}t jt|d tddd|d W d    d S 1 sw   Y  d S )Nz+non convertible value foo with the unit 's'r   r   r,  r   r  r   rq  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error)r,  rm   rd   c                 C   s6   t d}tdd||d}||ksJ t|t sJ d S )Nz1970-05-09 14:25:11r  r   r  )r   r   rC   )r1   r%   r  r4   r3   r#   r#   r$   test_unit_consistencyK  s   z(TestToDatetimeUnit.test_unit_consistencyrf   )rd   r,  rm   r)   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/   r0   )r1   r%   rf   r)   r4   r2   r3   r#   r#   r$   test_unit_with_numericS  s   z)TestToDatetimeUnit.test_unit_with_numericzexp, arr)r   r  r  )r   r  r  )r  r  r   r   )r  r  r   r   c                 C   s&   t |}t|d|d}t|| d S )Nrm   r-  )r   r   r/   r0   )r1   r%   r   r2   r4   r3   r#   r#   r$   test_unit_with_numeric_coerce]  s   z0TestToDatetimeUnit.test_unit_with_numeric_coerce)
2013-01-01r   r   ro  r  r  )r   r   r  c                 C   sh   t |}t|d|d}t|| d}tjt|d t|d|d W d    d S 1 s-w   Y  d S )Nrm   r-  z,mixed datetimes and integers in passed arrayr   r,  )r   r   r/   r0   r   r   r   )r1   r%   r   r2   r4   r3   r   r#   r#   r$   test_unit_mixedq  s   "z"TestToDatetimeUnit.test_unit_mixedc                 C   s&   t dd|d}td}||ksJ d S )Ng aAr   )r/  r%   z2015-06-19 19:55:31.877000192rH   r1   r%   r3   r4   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   Br^   r   r   rd   r   r  r<  r1   r%   r4   r3   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   Trd   )r/  r   rf   1970-01-01 00:00:01r   r   r   r  r#   r#   r$   'test_to_datetime_errors_ignore_utc_true  s   z:TestToDatetimeUnit.test_to_datetime_errors_ignore_utc_truec                    sV   d t  fddtdD |}t|dd}t dd tdD }t|| d S )NQc                       g | ]} | qS r#   r#   rQ   tepochr#   r$   rS     rT   z<TestToDatetimeUnit.test_to_datetime_unit.<locals>.<listcomp>r  r   r/  c                 S      g | ]}t d t|d qS z2013-06-09 02:42:28)secondsr   r   r  r#   r#   r$   rS         )r   r  r  r   r/   rD   )r1   r)   rZ   r3   r4   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                    r  r#   r#   r  r  r#   r$   rS     rT   zGTestToDatetimeUnit.test_to_datetime_unit_with_nulls.<locals>.<listcomp>r  r   r  c                 S   r  r  r  r  r#   r#   r$   rS     r  )r   r  r   r   r/   rD   )r1   r  rZ   r3   r4   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                    r  r#   r#   r  r  r#   r$   rS     rT   zOTestToDatetimeUnit.test_to_datetime_unit_fractional_seconds.<locals>.<listcomp>r   r^   g      ?r   r  c                 S   r  r  r  r  r#   r#   r$   rS     s    ms)r   r+   aranger   r  floatr   r   roundr/   rD   )r1   rZ   r3   r4   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   r^   r   r0  r  r  
1970-01-03r   )r   r   r+   r`   r   r   r/   r0   r  r#   r#   r$   test_to_datetime_unit_na_values  s
   z2TestToDatetimeUnit.test_to_datetime_unit_na_valuesbad_valr   ikc                 C   sP   | d}t jt|d tdd|gdd W d    d S 1 s!w   Y  d S )Nz with the unit 'D'r   r   r^   r0  r  r   )r1   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   r^   r0  rm   r/  rf   )r   r   r   r/   r0   )r1   r  r4   r3   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+   r`   r  r  r  r  r  r#   r#   r#   r$   r    sZ    



	


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g d ddgg d!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     r^   r   r   rM   rE     :   ;   r   r  r   	r@  rA  rB  rC  rD  secondr  usns)r   r1   r#   r#   r$   df  s   zTestToDatetimeDataFrame.dfc                 C   sh   t |d |d |d d|d}ttdtdg}t|| t |g d  |d}t|| d S )Nr@  rA  rB  r@  rA  rB  r   20150204 00:00:00z20160305 00:0:00)r   r   r   r/   rD   to_dictr1   r  r%   r3   r4   r#   r#   r$   test_dataframe  s   z&TestToDatetimeDataFrame.test_dataframec                 C   sH   |g d   }d|d< t||d}ttdtdg}t|| d S )Nr  r^   rA  r   r  z20160205 00:0:00)r  r   r   r   r/   rD   )r1   r  r%   df2r3   	expected2r#   r#   r$   &test_dataframe_dict_with_constructable  s   z>TestToDatetimeDataFrame.test_dataframe_dict_with_constructabler/  yearsmonthsdaysr   minutesr  )r@  rA  rB  rC  rD  r  r@  rA  rB  rC  rD  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   r  keysrenamer   r   r/   rD   )r1   r  r%   r/  r3   r4   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@  rA  rB  rC  rD  r  r  r  r	  r  r  r   20150204 06:58:10.00100200320160305 07:59:11.001002003)r   r  r   r   r/   rD   )r1   r  r%   dr3   r4   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  rX   r   r   r/   rD   r  r#   r#   r$   test_dataframe_str_dtype6  s   z0TestToDatetimeDataFrame.test_dataframe_str_dtypec                 C   s   t ddgddgddgd}d}tjt|d	 t||d
 W d    n1 s(w   Y  t|d|d}ttdtg}t	|| d S )Nr   r  r^   r  r   rM   r  zTcannot assemble the datetimes: time data .+ does not match format '%Y%m%d' \(match\)r   r   rm   r-  r  )
r   r   r   r   r   r   r   r   r/   rD   )r1   r%   r  r   r3   r4   r#   r#   r$   test_dataframe_coerceA  s   z-TestToDatetimeDataFrame.test_dataframe_coercec                 C   sT   d}t jt|d | }d|d< t||d W d    d S 1 s#w   Y  d S )Nz?extra keys have been passed to the datetime assemblage: \[foo\]r   r   r   r   )r   r   r   copyr   )r1   r  r%   r   r  r#   r#   r$   !test_dataframe_extra_keys_raisesmP  s   "z9TestToDatetimeDataFrame.test_dataframe_extra_keys_raisesmcols)r@  rA  r  )r@  rB  r  c                 C   sH   d}t jt|d t|| |d W d    d S 1 sw   Y  d S )Nz`to assemble mappings requires at least that \[year, month, day\] be specified: \[.+\] is missingr   r   r   )r1   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}g d	|_tjt|d
 t||d W d    n1 s-w   Y  t ddgddgddgddgd}g d|_tjt|d
 t||d W d    d S 1 saw   Y  d S )Nz#cannot assemble with duplicate keysr   r  r^   r  r   rM   r  )r@  r@  rB  r   r   )r@  rA  rB  rC  )r@  rA  rB  rB  )r   r  r   r   r   r   )r1   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  r^   r   r   rM   r  int16r   r  20160305 00:00:00)r   r   r  r   r   r/   rD   r1   r%   r  r3   r4   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  r^   r   r   rM   r  rA  int8rB  r   r  r)  )r   r  r   r   r   r/   rD   r*  r#   r#   r$   test_dataframe_mixed  s   z,TestToDatetimeDataFrame.test_dataframe_mixedc                 C   s`   t ddgddgddgd}d}tjt|d t||d W d    d S 1 s)w   Y  d S )	Nr   r   g      ?r   r  z:cannot assemble the datetimes: unconverted data remains: 1r   r   )r   r   r   r   r   )r1   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  r^   r   r   rM   r  Tr  z
2015-02-04z
2016-03-05r  r(   r   )	r   r   r   r+   r,   r   tz_localizer/   rD   )r1   r  r3   r4   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.  r0  r#   r#   r#   r$   r    sV    

	


	r  c                   @   sV  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d5g d6d7d8 Z!d9d: Z"d;d< Z#d=d> Z$ejd?e%e&gd@dA Z'dBS )CTestToDatetimeMiscc                 C   sP   t jdgtd}d}tjt|d t| W d    d S 1 s!w   Y  d S )Nz2262-04-11 23:47:16.854775808r(   r+  r   )r+   r,   r-   r   r   r   r   )r1   r2   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:0020121001z
2012-10-01c                 C   s*   t |g|d}t|}|d |ksJ d S )Nr   r   rH   )r1   r%   rI   exp_strr3   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J d S )N2001r   r   r   r  )r1   r%   rsxpr#   r#   r$   test_to_datetime_default  s   z+TestToDatetimeMisc.test_to_datetime_defaultz1fails to enforce dayfirst=True, which would raise)r   c              	   C   s   d}t jt|d/ tjtdd tdd|d W d    n1 s#w   Y  W d    d S W d    d S 1 s;w   Y  d S )NzInvalid date specifiedr   zProvide formatz
01-13-2012Tdayfirstr%   )r   r   r   r/   r  UserWarningr   rq  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sJ d S )Nr>   r   r   r   r   )r   r   r   )r1   r%   rZ   r3   r#   r#   r$   %test_to_datetime_on_datetime64_series  s   z8TestToDatetimeMisc.test_to_datetime_on_datetime64_seriesc                 C   s   t g d}d}tjt|d t|d|d W d    n1 s!w   Y  t|d|d}t tddd	td
dd	tg}t|| t|d|d}t|| d S )N)z
10/18/2006z
10/18/2008 z0(\(')?String does not contain a date(:', ' '\))?r   r,  r-  rm   i  r   r   r  rd   )	r   r   r   r   r   r   r   r/   rD   )r1   r%   rZ   r   result_coerceexpected_coerceresult_ignorer#   r#   r$   %test_to_datetime_with_space_in_series  s   z8TestToDatetimeMisc.test_to_datetime_with_space_in_seriesc                 C   sB   t g dg dd}t|d|d}|jtd|d}t|| d S )N)May 04Jun 02zDec 11r   r^   r   index%b %yrA   )r   r   rW   r/   rD   )r1   r%   r   r4   r3   r#   r#   r$   test_to_datetime_with_apply  s   z.TestToDatetimeMisc.test_to_datetime_with_applyc                    s   t g dg dd}d}tjt|d t|dd d W d    n1 s&w   Y  tjt|d |jtdd d W d    n1 sFw   Y  t|dd	 d}| fd
d}t|| d S )N)rF  rG  r   rH  rI  z4time data '' does not match format '%b %y' \(match\)r   rK  r,  re   rm   c                    s   t | dd dS )NrK  rm   re   r   rR   r   r#   r$   <lambda>  s    zOTestToDatetimeMisc.test_to_datetime_with_apply_with_empty_str.<locals>.<lambda>)r   r   r   r   r   rW   r/   rD   )r1   r%   r   r   r4   r3   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u sJ d S Nr   r   )r   r   r1   r%   r3   r#   r#   r$   test_to_datetime_empty_stt     z-TestToDatetimeMisc.test_to_datetime_empty_sttc                 C   s$   t ddg|d}t| sJ d S rP  )r   r   r  rQ  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J d S )Nr   r   )r   r   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J d S )N2012r   r   r   r  r#   r#   r$   test_to_datetime_strings  s   z+TestToDatetimeMisc.test_to_datetime_stringsc                 C   s6   g d}t t||d}dd |D }t|| d S )N)rV  20120101z20120101 12:01:01r   c                 S   rN   r#   rO   )rQ   date_strr#   r#   r$   rS     rT   zITestToDatetimeMisc.test_to_datetime_strings_variation.<locals>.<listcomp>)r  r   r/   assert_almost_equal)r1   r%   r,   r4   r3   r#   r#   r$   "test_to_datetime_strings_variation  s   z5TestToDatetimeMisc.test_to_datetime_strings_variationr3   rV  c                 C   s   t ddd}||ksJ d S )Nrg   r   rO   r  r#   r#   r$   'test_to_datetime_strings_vs_constructor  rS  z:TestToDatetimeMisc.test_to_datetime_strings_vs_constructorc                 C   s~   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 d    d S 1 s8w   Y  d S )
Nr   1rd   r-  Or(   z#invalid string coercion to datetimer   r,  )	r   r   r+   r,   r/   r   r   r   rl  )r1   r%   r3   r4   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 )Nrt  d   rd   r-  rq   )r1   r%   seriesr3   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J t|}||ks'J d S )Nl    `SD& zM8[us]r^  r   )r+   r  viewr  r   r   )r1   rX  as_objrJ  r   r#   r#   r$   'test_to_datetime_other_datetime64_units(  s   

z:TestToDatetimeMisc.test_to_datetime_other_datetime64_unitsc                 C   s8   t ddd}t|j}t|j}t|}t|| d S )Nr>   r  r?  )r   r   rE   r  asi8r/   r0   )r1   rngintsr3   r#   r#   r$   !test_to_datetime_list_of_integers3  s
   

z4TestToDatetimeMisc.test_to_datetime_list_of_integersc                 C   sF   d}t jt|d tdddd W d    d S 1 sw   Y  d S )Nz<Cannot cast 139999 days, 0:00:00 to unit=ns without overflowr   z1/1/1700Br  )startr   r   )r   r   r   r   )r1   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|r$t||< qt|||< qt	
|d }t|| t||d}t|tsEJ t||j d S )	Nr>   r?   z1/4/2000, 12:34:56r(   r   rp   r   r   )r+   r,   r`   r-   empty	enumerater   r   r   r
   array_to_datetimer/   rZ  r   rC   r   assert_numpy_array_equalrE   )r1   r%   stringsr4   rj  r   r3   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 d    n1 s%w   Y  t|d|d}t|}t	
|| tjt|d t|d|d W d    d S 1 sUw   Y  d S )Nz
1/100/2000r(   z4Unknown string format:|day is out of range for monthr   r,  r-  rd   )r+   r,   r`   r-   r   r   r   r   r   r/   r0   )r1   r%   	malformedr   r3   r4   r#   r#   r$   'test_string_na_nat_conversion_malformedY  s   "z:TestToDatetimeMisc.test_string_na_nat_conversion_malformedc           
   	   C   s   g d}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|	rVt||< qGt|	|d||< qGtj	||dd |j
dksnJ tj	||dd |j
dks}J d S )N)rt  r{  cr  er>   r@   z1/5/2000r   rJ  r   r   rM   rp   r(   rI  F)check_names)r   r+   r`   r   rm  r  r   r   r/   rD   r   )
r1   r%   idxra  dseriesr3   dresultr4   rj  rR   r#   r#   r$   'test_string_na_nat_conversion_with_namei  s4   



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   sD   t g d|d}|j|}tt|| tt ||d| d S )N)z2000-01-01T00:00z2000-01-02T00:00r   r   )r   rE   r  r/   r0   r   )r1   r%   r)   baserE   r#   r#   r$   $test_dti_constructor_numpy_timeunits  s   z7TestToDatetimeMisc.test_dti_constructor_numpy_timeunitsc           
      C   s   g d}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 )
N)z
10/02/2014z
11/02/2014z
12/02/2014rj   r^   r   r  rh   Tr<  r;  )	r   r   r+   r,   r   r   r   r/   r0   )
r1   r%   r2   r4   idx1idx2idx3idx4idx5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 d    n1 s<w   Y  t|| tjt|d t|dd
}W d    n1 s_w   Y  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  rJ  z
2011-10-03Tr  r   Frw  )r   r   r/   r0   r  r=  )	r1   warning_msg_day_firstr2   expected_consistentexpected_inconsistentres1res2res3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 d    n1 s)w   Y  t|| tjt|d	 t|dd}W d    n1 sLw   Y  t|| tjt|d	 t|dd}W d    n1 sow   Y  t|| tjt|d	 t|d
d}W d    n1 sw   Y  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  rJ  r   Tr  Fr  )r   r/   r  r=  r   r0   )	r1   r  warning_msg_month_firstr2   r4   res5res6res7res8r#   r#   r$   $test_dayfirst_warnings_invalid_input  s0   
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   Tr  )r   r  r/  r   r/   r   )r1   r  r   r4   objr3   r#   r#   r$   test_to_datetime_dta_tz  s   
z*TestToDatetimeMisc.test_to_datetime_dta_tzN)(r   r   r   r3  r   r   r   r6  r:  r   r>  r@  rE  r   r   rL  rO  rR  rT  rU  rW  r[  r   r   r\  r_  rb  re  ri  rl  rs  ru  r}  r  r  r  r  r   r   r  r#   r#   r#   r$   r2    sV    



	


"
	$)r2  c                   @   sN   e Zd Zejejdg dej	ej	dgddggdd Z
ejdd Zd	S )
TestGuessDatetimeFormat
test_array)2011-12-30 00:00:00.000000r  r  r  random_stringc                 C   s   d}t ||ksJ d S )Nr   )tools _guess_datetime_format_for_array)r1   r  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 u sJ d S )Nr^  r(   )r  r  r+   r,   r`   )r1   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+   r`   r  r  r#   r#   r#   r$   r    s    r  c                   @   s   e Zd Zejdg ddd Zejdg dg dgdd	 Zd
d Zdd Z	ejdg ddd Z
ejdg ddd Zejdddgdd ZdS )TestToDatetimeInferFormattest_format)z%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 )Nr8   2   Hr   r   c                    s
   |   S r  )strftimerM  r  r#   r$   rN  /  s   
 zdTestToDatetimeInferFormat.test_to_datetime_infer_datetime_format_consistent_format.<locals>.<lambda>rA   Frw  r%   T)r   r   rW   r   r/   rD   )r1   r%   r  rZ   s_as_dt_stringswith_formatno_infer	yes_inferr#   r  r$   8test_to_datetime_infer_datetime_format_consistent_format'  s   zRTestToDatetimeInferFormat.test_to_datetime_infer_datetime_format_consistent_formatr   )01/01/2011 00:00:00z01-02-2011 00:00:00z2011-01-03T00:00:00)z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/   rD   r   )r1   r%   r   rZ   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,   r`   r-   r/   rD   r   r1   r%   rZ   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 )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/   rD   )r1   tz_namer   rZ   r3   r4   r#   r#   r$   "test_infer_datetime_format_tz_namen  s   z<TestToDatetimeInferFormat.test_infer_datetime_format_tz_namez
ts,zero_tz))r  Z)r  r   )2019-02-02 08:07:13.012345r  )r  r   c                 C   sN   t || g}t|dd}|dkrtjnd }t t||dg}t|| d S )NTr  r  r   )r   r   r   r   r   r/   rD   )r1   rZ  zero_tzrZ   r3   r   r4   r#   r#   r$   "test_infer_datetime_format_zero_tzz  s
   z<TestToDatetimeInferFormat.test_infer_datetime_format_zero_tzrB   N%Y-%m-%dc                 C   s@   t g d}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-03rA   )r   r   r/   rD   r   )r1   r%   rB   rZ   r4   r#   r#   r$   %test_to_datetime_iso8601_noleading_0s  s   z?TestToDatetimeInferFormat.test_to_datetime_iso8601_noleading_0s)r   r   r   r   r   r   r  r  r  r  r  r  r  r#   r#   r#   r$   r  &  s2    



	
	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g d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-29Nr  
2015-02-32
2015-04-31c                 C   s   t t|d||dsJ d S )Nrm   rf   rB   r%   )r   r   )r1   r%   rI   rB   r#   r#   r$   test_day_not_in_month_coerce  s   
z,TestDaysInMonth.test_day_not_in_month_coercec                 C   F   d}t jt|d tdd|d W d    d S 1 sw   Y  d S )Nzday is out of range for monthr   r  r,  r-  r   rq  r#   r#   r$   test_day_not_in_month_raise  s   "z+TestDaysInMonth.test_day_not_in_month_raiserI   )r  r  r  c                 C   sP   d| d}t jt|d t|dd|d W d    d S 1 s!w   Y  d S )Nztime data "z." at position 0 doesn't match format specifiedr   r,  r  r  r   rm  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J d S )Nrd   r  r   )r1   r%   r4   rB   r3   r#   r#   r$   test_day_not_in_month_ignore  s   
z,TestDaysInMonth.test_day_not_in_month_ignore)
r   r   r   r   r   r   r  r  r  r  r#   r#   r#   r$   r    s,    
	
	r  c                   @   s  e Zd Zejdei deddddeddddedddd	edddd
eddddeddddeddddeddddeddddeddddeddddeddddeddddeddddeddddeddddedddi deddddeddddeddddeddddedddd edddd!edddd"ed#d$dd%eddd&d'eddd&dd(d)eddd&d*d+d,eddd&dd(d-eddd&d*d+d.eddd&dd(d/eddd&d*d+d0ed1d&d2dd3d4d5ed1d&d2ed1d&d2ed6dded6d7ded6d7ded6d7ded6d7ded8ddd9ed8ddd9d:ed8ddd9d:d;d<	 d=d> Z	d?d@ Z
dAdB ZejdCdDdEdEedFddfdDdGdEedFddfdDdEdGedHdd9fdDdGdGedHd9dfdIdEdEedJd9dKfdIdGdEedJd9dKfdIdEdGed#d9dLfdIdGdGed#d9dLfgdMdN ZejdOdPeddddd(gdQedddd&d$ggdRdS ZejdTdUedVdWfdXedYdZfgd[d\ Zd]S )^TestDatetimeParsingWrapperszdate_str,expectedz
2011-01-01i  r   2Q2005i  r   2Q052005Q105Q12011Q3r  11Q33Q20113Q112000Q4r   r   00Q44Q20004Q002000q4z2000-Q4z00-Q4z4Q-2000z4Q-0000q42005z2005-11r  z2005 11z11-2005z11 2005200511r   rM   20051109	   z20051109 10:15r  z20051109 08H   r   z2005-11-09 10:15z2005-11-09 08Hz2005/11/09 10:15z2005/11/09 08HzThu Sep 25 10:36:28 2003i     $      zThu Sep 25 2003rj   rE  r   rh   "   8   )	z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sJJ qB||	|
||fD ]}tt	|g}t
|| qR|s|t	|}||ksnJ t|dd|d}||ks~J d S d S )NT)	yearfirstr(   )r  r%   Sr   )r   r   r  )r   parse_time_stringr   r+   r,   r-   r   r   r   r   r/   r0   r   )r1   rY  r4   r%   r  result1_rr  result3result4result6result8result9r   r   result5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/   r0   )r1   r%   unique_nulls_fixtureunique_nulls_fixture2r4   r3   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u sJ |tu s"J |tu s(J |tu s.J d S )Nr   r   )r   r  r   r   r   r   )r1   r  r  rr  r  r  r#   r#   r$   test_parsers_nat	  s   z,TestDatetimeParsingWrappers.test_parsers_natz'date_str, dayfirst, yearfirst, expectedz10-11-12Frg   Ti  z20/12/21i  r     c                 C   s   t |||d}||ksJ tj|||d\}}|s%|s%t|}	|	|ks%J t||||d}
t|g||dd }||ks=J |
|ksCJ ||ksIJ d S )N)r<  r  )r<  r  r%   r   )r   r   r  r   r   r   )r1   r%   rY  r<  r  r4   dateutil_resultr  r  rr  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s%J ||ks+J ||ks1J ||ks7J |	|ks=J d S )Nr   )r   r   r  r   r   r   )
r1   rY  exp_defexp_nowr  r  rr  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sJ |t|ks"J d S )Nz2013-01-01 00:00:00r   r   )r   r/  r   repr)r1   r%   	dt_stringr   dt_string_reprr~  dt_timer#   r#   r$   .test_parsers_timezone_minute_offsets_roundtrip	  s
   zJTestDatetimeParsingWrappers.test_parsers_timezone_minute_offsets_roundtripN)r   r   r   r   r   r   r  r   r  r  r  r  r  r  r   r   r  r#   r#   r#   r$   r    s    	 !"#
$




.
4
D&
r  )r0  r   r  r  r	  c                 C   r   )zIDay and some time units.

    * D
    * s
    * ms
    * us
    * ns
    r   r!   r#   r#   r$   units	  s   
r  c                   C   s   t dS )zTimestamp at 1960-01-01.
1960-01-01rO   r#   r#   r#   r$   
epoch_1960	  s   r  c                   C   s   t tdS )NrM   )r  r  r#   r#   r#   r$   units_from_epochs	  s   r  )	timestamp
pydatetimer  str_1960c                 C   sH   |j dv sJ |j dkr| S |j dkr|  S |j dkr |  S t| S )zxTimestamp at 1960-01-01 in various forms.

    * Timestamp
    * datetime.datetime
    * numpy.datetime64
    * str
    >   r  r	  r  r
  r	  r
  r  )r    r  to_datetime64rX   )r  r"   r#   r#   r$   epochs	  s   	


r  c                   C   s   t ddd jS )Nr  r   r?  )r   to_julian_daterE   r#   r#   r#   r$   julian_dates	  s   r  c                
   @   s  e Zd Zdd Zdd Zdd Zdd Z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 g d!g d"g d#gd$d% Zej	d&g d'g d(g d)g d*gd+d, ZdS )-
TestOriginc                 C   s>   t t|ddd}t t|td  dd}t|| d S )Nr0  julianr/  originr   r  )r   r   r   r  r/   rD   )r1   r  r3   r4   r#   r#   r$   test_julian	  s
   zTestOrigin.test_julianc                 C   s@   t tg dddd}t tdtdtdg}t|| d S )N)r   r   r^   r0  unixr  z
1970-01-01r  r  r]  r  r#   r#   r$   	test_unix	  s
   zTestOrigin.test_unixc                 C   sd   t dddd}| dksJ d}tjt|d t dddd W d    d S 1 s+w   Y  d S )NiR|% r  r0  r  r/  z&1 is Out of Bounds for origin='julian'r   r   )r   r  r   r   r   )r1   r3   r   r#   r#   r$   test_julian_round_trip	  s   "z!TestOrigin.test_julian_round_tripc                 C   sR   |dkr'd}t jt|d t||dd W d    d S 1 s w   Y  d S d S )Nr0  z$unit must be 'D' for origin='julian'r   r  r  r   )r1   r  r  r   r#   r#   r$   test_invalid_unit	  s   "zTestOrigin.test_invalid_unitr/  r	  r0  c                 C   r  )Nz(it must be numeric with a unit specifiedr   z
2005-01-01r  r  r   )r1   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   	TimedeltarP   r  r  r#   r$   rS   
  r  z)TestOrigin.test_epoch.<locals>.<listcomp>r  rq   )r1   r  r  r  r  r4   r3   r#   r  r$   
test_epoch
  s
   zTestOrigin.test_epochzorigin, excr  r  z
13-24-1990r   c                 C   sN   d| d}t j||d t|||d W d    d S 1 s w   Y  d S )Nzorigin z6 (is Out of Bounds|cannot be converted to a Timestamp)r   r  )r   r   r   )r1   r  excr  r  r   r#   r#   r$   test_invalid_origins
  s   "zTestOrigin.test_invalid_originsc              
   C   sP   t jtdd tddtdddtjdd W d    d S 1 s!w   Y  d S )Nzmust be tz-naiver   r   r0  r   r   r  )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 d    d S 1 sw   Y  d S )Nz6Unknown string format: yesterday present at position 1r   r  	yesterdayr   r
  r#   r#   r$   test_incorrect_value_exception"
  s
   "z)TestOrigin.test_incorrect_value_exceptionrB   Nz%Y-%m-%d %H:%M:%Sc                 C   sD   d}t jt|d td|d W d    d S 1 sw   Y  d S )NzMOut of bounds nanosecond timestamp: 2417-10-27 00:00:00 present at position 0r   z2417-10-27 00:00:00rv   r  )r1   rB   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)( r  z2169-11-13 00:00:00)r$  
1870-01-012069-11-13 00:00:00)鼫 r%  2169-10-20 00:00:00c                 C   sj   t |d|d}t|}||ksJ t dddd}td}||ks"J t dddd}td}||ks3J d S )Nr0  r  r$  r%  r&  r'  r(  rH   )r1   rI   r  expected_strr3   r4   r#   r#   r$   test_processing_order3
  s   z TestOrigin.test_processing_orderzoffset,utc,exp)r  T2019-01-01T00:00:00.000Z)r  Nr+  )-01:00Tz2019-01-01T01:00:00.000Z)r,  Nz2019-01-01T00:00:00.000-01:00c                 C   s2   d| }t |gd|d}t |g}t|| d S )Nz2019-01-01T00:00:00.000r	  )r/  r   r   )r1   r   r   r   rI   r3   r4   r#   r#   r$   test_arg_tz_ns_unitK
  s   
zTestOrigin.test_arg_tz_ns_unit)r   r   r   r  r  r  r  r   r   r   r  r  r   r   r   r  r   r"  r#  r*  r-  r#   r#   r#   r$   r  	  sL    
	
	
	
	
	r  c                   @   s   e Zd Zejdg ddfg d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_caching)
r   r^   r   r   rM   rE  r  r  r  r   F)
r   r   r   r   r   rM   rE  r  r  r  Tc                 C   s    t j|t|dd|ksJ d S )Ngffffff?)check_countunique_share)r  should_cacher|  )r1   listlike
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\)\])r   r^   z-unique_share must be in next bounds: \(0; 1\)c                 C   sL   dgd }t jt|d t||| W d    d S 1 sw   Y  d S )NrM   r   r   )r   r   AssertionErrorr  r1  )r1   r0  r/  err_messagerI   r#   r#   r$   test_should_cache_errorsj
  s   
"z(TestShouldCache.test_should_cache_errorsr2  r  r  c                 C   s   t |du s	J d S )NT)r  r1  )r1   r2  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   r4  r7  r   r   r  r8  r#   r#   r#   r$   r.  \
  s.    



r.  c                  C   sv   t g d} | d} |  }t| dd}t tdtdtdtdtdg}t|| t| | d S )	N)r   r^   Nl            N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/   rD   )rZ   ser_copyr   r4   r#   r#   r$   !test_nullable_integer_to_datetime
  s   
	r=  r  c                 C   sn   t | tr&tjtdd t|| g W d    d S 1 sw   Y  d S t|| g}|d tu s5J d S )Nznot convertible to datetimer   r   )rC   r   r   r   rl  r   r   )nulls_fixturer  r3   r#   r#   r$   test_na_to_datetime
  s   
"r?  c                  C   s   t g d} d}t| |dd}t ddtgdd}t|| tjtd	d
 t| |dd W d    n1 s7w   Y  t| dd}t|| d S )N)z
03/24/2016z
03/25/2016r   r;   rm   r|   z
2016-03-24z
2016-03-25r  r(   zdoes not match formatr   r,  r	  )r   r   r   r/   rD   r   r   r   )r   rB   r3   r4   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   rm   r  r  r   r  r(   r,  r   )r3   r4   r#   r#   r$   'test_empty_string_datetime_coerce__unit
  s
   rA  xarrayc                  C   sD   dd l } | g d}t|dd}tg ddd d}t|| d S )Nr   rH  r	  r  )r:  r;  z1970-01-01 00:00:00.000000003r  rJ  )rB  	DataArrayr   r   r/   r0   )xrr2   r3   r4   r#   r#   r$   test_xarray_coerce_unit
  s   	rE  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 )N1980YSr  FDTrx  r   )nrandom_statei  r   r   )r   r   r   to_framesamplerJ  	to_seriesr  r  r   r   r/   rD   )r%   cstarttimesr3   r4   r#   r#   r$   +test_to_datetime_monotonic_increasing_index
  s   rP  series_lengthr  r   rM   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 d    d S 1 s`w   Y  d S )
Nz1446-04-12 00:00:00+00:00z1991-10-20 00:00:00+00:00rm   T)rf   r   rd   r  r   r,  )r   r   fromisoformatr   r   r   r/   rD   r   r   r   )rQ  r   r  	expected1rr  r  r#   r#   r$   2test_to_datetime_cache_coerce_50_lines_outofbounds
  s(   

"rT  rI   z1724-12-20 20:20:20+00:002022-01-01 00:00:00i  rh   r  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:20rU  Tr  r   )reverser   r   r/  r/   r0   )rI   rX  exp_argr3   r4   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sJ d S )Nz15/02/2020 02:03:04.123456789z%d/%m/%Y %H:%M:%S.%frv   r   r^   r  r   r   i@ i  )r@  rA  rB  rC  rD  r  microsecond
nanosecondrH   )r	  timestamp_formatr3   r4   r#   r#   r$   %test_to_datetime_format_f_parse_nanos  s   
r_  )X__doc__r   collectionsr   r   r   r   decimalr   r   dateutil.parserr   dateutil.tz.tzr	   numpyr+   r   r   pandas._libsr
   pandas._libs.tslibsr   r   pandas.errorsr   r   pandas.util._test_decoratorsutil_test_decoratorsr   pandas.core.dtypes.commonr   pandasr   r   r   r   r   r   r   r   r   r   pandas._testing_testingr/   pandas.core.arraysr   pandas.core.toolsr   r  pandas.core.tools.datetimesr   pandas.util.versionr   r1  r%   r&   r   r  r  r2  r  r  r  r  r  r  r  r  r  r  r.  r=  r   r   r,   r  r?  r@  rA  r  rE  rP  rT  r   r[  r_  r#   r#   r#   r$   <module>   s    ,
         H J H  ms( i




 (



"