U
    -e                    @   s  d Z ddlZddlmZ ddlmZ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/m0Z0 ddl1m2Z3 ddl4m5Z5 ddl6m7Z7 dZ8ej9dd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"Z@G d#d$ d$ZAG d%d& d&ZBG d'd( d(ZCej9d)d*d+d,d-gdd.d/ ZDej9d0d1 ZEej9d2d3 ZFej9d4d5d6d7gdd8d9 ZGej9d:d; ZHG d<d= d=ZIG d>d? d?ZJd@dA ZKejLMdBejNeOgdCdD ZPejLMdEdFdGdHgejLjMdIdJdKdLgdMfdNdOdLgdPfgdQdRgdSdTdU ZQdVdW ZReSdXdYdZ ZTejLMdddgd[d\ ZUejLMd]d^e5e5d_ e5d` gdadb ZVdcdd ZWdedf ZXdgdh ZYejLMdiddgejLMdjdRdkgdldm ZZdndo Z[ejLMdpdGe$dqe&gfdHe%drdsgfgdtdu Z\dvdw Z]dS )xz test to_datetime     N)deque)date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)Versiona_  You might want to try:\n    - passing `format` if your strings have a consistent format;\n    - passing `format=\'ISO8601\'` if your strings are all ISO8601 but not necessarily in exactly the same format;\n    - passing `format=\'mixed\'`, and the format will be inferred for each element individually. You might want to use `dayfirst` alongside this.TF)paramsc                 C   s   | j S )z/
    cache keyword to pass to to_datetime.
    paramrequest r#   d/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/pandas/tests/tools/test_to_datetime.pycache>   s    r%   c                   @   sj  e Zd Zejdddgdd Z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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/d0geed1ejejejgged.d/ejd0geed1ejejejgggd2d3 Zejd4ejgd5ed&gfejgd%ed&gfejd6gd5ed&d7gfd8ejgd9ed:d&gfd8ejgd;ed<d&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@dA ZdBdC ZejdDdEedFdGdHgdIedJdKdLgdMdMgdNdNgdOdOgdPdPggdQdR ZdSdT ZejdUdVdWedXgdYdZed[gd\d]ed^gejd_d`edaejj e!" db dckddddedfejdgd`edhejj e!" db dckddddedfejdidjedkejj e!" db dckddddedfgdldm Z#e$j%dndo Z&ejddpedqdrdKfdsedqdKdrfdtedqdrdKdufdvedqdKdrdufdwedqdrdKdudxfdyedqdKdrdudxfdzedqdrdKdudxd{fd|edqdKdrdudxd{fd}edqdrdKdudxd{d~fdedqdKdrdudxd{d~fdedqdrdKdudxd{d~ddfdedqdKdrdudxd{d~ddfgdd Z'ejddddddgdd Z(ejdddedgddedggdd Z)ejdddgd edddgd gddddgedddedddedddggddgd ede*e+dddgd gddgd ede*e+dddgd gdddgede*e+dddede*e+dddggdddgede,-dbdede,-dbdgggdd Z.dd Z/ejdddddddgdd Z0dd Z1d%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_readonlyG   s    z3TestTimeConversionFormats.test_to_datetime_readonlyz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/   )r0   r%   Zindex_or_seriesr;   r3   valuesr2   r#   r#   r$   test_to_datetime_formatQ   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)r0   r%   argr3   r;   r2   r#   r#   r$   test_to_datetime_format_scalarg   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>y   s     zNTestTimeConversionFormats.test_to_datetime_format_YYYYMMDD.<locals>.<listcomp>%Y%m%dr:   r   applystrr   r.   r=   r0   r%   serr3   r2   r#   r#   r$    test_to_datetime_format_YYYYMMDDw   s    z:TestTimeConversionFormats.test_to_datetime_format_YYYYMMDDc              	   C   s   t ddgdgd  d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	j
tdd t|d	|d
 W 5 Q R X d S )NrE   rF   rG   floatr(   19801222Z19810105   rM   r:   ZnatzOunconverted data remains when parsing with format "%Y%m%d": ".0", at position 0match)r   r   r+   nanr   r.   r=   rO   rP   pytestraises
ValueError)r0   r%   rR   r3   r2   Zser2r#   r#   r$   )test_to_datetime_format_YYYYMMDD_with_nat   s    


zCTestTimeConversionFormats.test_to_datetime_format_YYYYMMDD_with_natc                 C   sn   t ddgdgd  dd}t tdtdgtdgd  }tj|d< tj|d< t|d	|d
}t|| d S )Ni| i rG   rT   r(   Z19801201Z19810101rV   %Y%mr:   )r   r   r+   rY   r   r.   r=   rQ   r#   r#   r$   'test_to_datetime_format_YYYYMM_with_nat   s    

zATestTimeConversionFormats.test_to_datetime_format_YYYYMM_with_natc                 C   s@   t dddg}t|dd|d}t dddgtd}t|| d S )N3T3鿾rM   ignorer;   errorsr%   r(   )r   r   r-   r.   r=   r0   r%   rR   r2   r3   r#   r#   r$   'test_to_datetime_format_YYYYMMDD_ignore   s    zATestTimeConversionFormats.test_to_datetime_format_YYYYMMDD_ignorec                 C   s8   t ddtjgdd|d}tddtjg}t|| d S )NZ15010101Z20150101rM   rc   rd   )r   r+   rY   r   r.   r/   r0   r%   r2   r3   r#   r#   r$   8test_to_datetime_format_YYYYMMDD_ignore_with_outofbounds   s    
zRTestTimeConversionFormats.test_to_datetime_format_YYYYMMDD_ignore_with_outofboundsc                 C   s@   t dddg}t|dd|d}t ddd	gd
d}t|| d S )Nr`   ra   rb   rM   coercerd   Z20121231Z20141231r   M8[ns]r(   r   r   r.   r=   rf   r#   r#   r$   )test_to_datetime_format_YYYYMMDD_coercion   s    zCTestTimeConversionFormats.test_to_datetime_format_YYYYMMDD_coercioninput_srU   20010112Nr   rE   iT1c                 C   s6   t tdtdtg}t t|dd}t|| d S )NrU   ro   rM   r;   )r   r   r   r   r.   r=   r0   rn   r3   r2   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   rj   r;   re   r   r.   r=   rq   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:20201010z%y%m%dz
2020-10-10z%d%m%y
2010-10-20rM   c                 C   s   t ||d}t|| d S Nrp   r   r.   r/   )r0   datar;   r3   r2   r#   r#   r$   test_to_datetime_with_NA   s    z2TestTimeConversionFormats.test_to_datetime_with_NAc                 C   s*   t dtjg}tddg}t|| d S )Nrv   rw   r   )r   pdNAr   r.   r/   r0   r2   r3   r#   r#   r$   %test_to_datetime_with_NA_with_warning  s    z?TestTimeConversionFormats.test_to_datetime_with_NA_with_warningc                 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     r^   rN   rQ   r#   r#   r$   test_to_datetime_format_integer  s    z9TestTimeConversionFormats.test_to_datetime_format_integerzint_date, expectedi3  
      i i     r   iuwi(3iA iI  c                 C   s   t |ddd}||kstd S )NrM   rc   rs   r   rB   )r0   Zint_dater3   r2   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 )Nr   z01-z-2011 00:00:01.978z%d-%b-%Y %H:%M:%S.%fr:   )calendar
month_abbrr   r   strptimerB   )r0   r%   r   valr;   r2   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   )r0   r%   valuer;   dtr#   r#   r$   test_to_datetime_format_timeC  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=   rf   r#   r#   r$   test_to_datetime_with_non_exactr  s    
  z9TestTimeConversionFormats.test_to_datetime_with_non_exact%Y-%m-%dr      %Y-%d-%m%Y-%m-%d %H   z%Y-%d-%m %H%Y-%m-%d %H:%M"   z%Y-%d-%m %H:%M%Y-%m-%d %H:%M:%S8   %Y-%d-%m %H:%M:%S%Y-%m-%d %H:%M:%S.%f@ z%Y-%d-%m %H:%M:%S.%f%Y-%m-%d %H:%M:%S.%f%z	UTC+01:00tzz%Y-%d-%m %H:%M:%S.%f%zc                 C   s   t d|dd}||kstd S )Nz 2000-01-03 12:34:56.123456+01:00Fr;   r   r   )r0   r%   r;   r3   r2   r#   r#   r$   (test_non_exact_doesnt_parse_whole_string  s      zBTestTimeConversionFormats.test_non_exact_doesnt_parse_whole_stringrC   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%   r   r:   r   )r0   r%   rC   r3   r2   r#   r#   r$   #test_parse_nanoseconds_with_formula  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   )r0   r   fmtr3   r%   r#   r#   r$   test_to_datetime_format_weeks  s    z7TestTimeConversionFormats.test_to_datetime_format_weekszfmt,dates,expected_datesz%Y-%m-%d %H:%M:%S %Zz2010-01-01 12:00:00 UTCrV   2010-01-01 12:00:00UTCz2010-01-01 12:00:00 GMTz2010-01-01 12:00:00 US/PacificGMT
US/Pacific%Y-%m-%d %H:%M:%S%zz2010-01-01 12:00:00+0100<   minutes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 rx   )r   r   r.   assert_equal)r0   r   datesexpected_datesr2   r3   r#   r#   r$   )test_to_datetime_parse_tzname_or_tzoffset  s    C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/   )r0   r   r   r   r2   r3   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   sV   d}d| }d dt ddt dg}tjt|d t|g|d W 5 Q R X d S )	Nr   z2010-01-01 12:00:00 |z;^time data ".*" doesn\'t match format ".*", at position 0. $N^unconverted data remains when parsing with format ".*": ".*", at position 0. rW   rp   joinPARSING_ERR_MSGrZ   r[   r\   r   )r0   r   r   r   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namerp   r   r   )r   r   )r   r   r   r.   r/   )r0   r   rC   r2   r3   r#   r#   r$   *test_to_datetime_parse_timezone_keeps_name'  s
    zDTestTimeConversionFormats.test_to_datetime_parse_timezone_keeps_name)2__name__
__module____qualname__rZ   markparametrizer4   r   r?   rD   rS   r]   r_   rg   ri   rm   r+   rY   r   rr   r   ru   r|   r}   r   r{   r   r   r   r   r   r    xfaillocale	getlocaler   tdskip_if_not_us_localer   r   r   r   r   r   pytzZFixedOffsetr   r   r   r   r#   r#   r#   r$   r&   F   s  
	
	








	

,








     A
 
r&   c                   @   s
  e Zd Zejddd Zdd Zejjdddgd	d
gddd Z	ejjdddgddgdejdej
dddgeddgddddej
dddgeddgd dej
dddgeddgddd!dej
dd"dgeed"ed#d$d%gd&dej
dd"dgeddgddd'dgejd(ed)d* gd+d, Zejd-ej
dded.d/d0gddd1dej
ddeed2d3d%ed4d5d%egd6dej
dded.d7d0gddd8dej
ddeed2d3d%ed9d5d%egd:dgd;d< Zejjdddgddgdejd=ej
dd>gd?dgejd(ed@d* gdAdB ZdCdD ZejdEdFdGedHdIdJdKdKgdLdGedMdNdNdKdKgdOdGedMdNdPdKdKggdQdR ZejdSdTdUdVgdWdXdYgdWdZd[gdWd\d]gdWd^d_gdWd^d`gdWdadbgdcdddegdTdfdggdTdhdigdTdjdkgdTdjdlgdmdndogdmdfdpgdmdhdqgdmdjdrgdmdjdsgdcdUdtgdmdudpggejdvdwdxdygdzd{ Zejd|d}d~gdd Zdd Zdd Zdd Zejdd Zejejd|ddgdd Zejdddgdd Zejddddgejdddgdd Zejde !de !dgdd Z"ejdddgdd Z#ejde !de !dgejdvdwdydxgdd Z$dd Z%ejdddgdd Z&dd Z'dd Z(dd Z)dd Z*dd Z+ejdeefe,efe j-efe.e.fgdd Z/ejddeddd%gdeddd%ggddĄ Z0ddƄ Z1ddȄ Z2ejdddgdd̈́ Z3e4dΡddЄ Z5ejdddgdd҄ Z6ddԄ Z7ejde8e9gddք Z:ejdvdxdwdygdd؄ Z;ejdddgejdd}dgddބ Z<ejddgejdd}dgdd Z=ejddgdgdddggejdd}dgdd Z>ejddd}gejddd}gejd(e,e?e j-ee@gdd ZAdd ZBejddd}gejddd}gdd ZCdd ZDejdd}e jEfefeF  efeFd  fd}edfefeF  eedfefeF  fdefeF  dedf efeFdN  ededf ffdd ZGejdddgejde.egd d}gd  dde.egd ddfe.egd d}gd  dde.egd ddfe.d}gd e.egd ddfe.d}gd e.egd ddfe.dgd e.egd ddfe.dgd e.egd ddfe.eHjIgd e.egd ddfe.eHjIgd e.egd ddfe.e jJgd e.egd ddfe.e jJgd e.egd ddff
d d ZKejdddddddgd	d
 ZLdd ZMejdddgejdeddNdNeNddNdNe !dddgdd ZOejddxeeegfdyeddgfgdd ZPdd ZQdd ZRdd  ZSd!d" ZTd#d$ ZUd%d& ZVejd'ed(ed(d$d%fed(d)d%ed*d$d%fgd+d, ZWejd-d.d/d0d1gd2d3 ZXd4d5 ZYd6d7 ZZd}S (8  TestToDatetimezignore:Could not infer formatc              	   C   s   d}d}t jt|d t| W 5 Q R X t jt|d t|g W 5 Q R X t|dd}|tksftt|gdd}t|ttg t|dd}t	|t
r||kstt|gdd}t|t|gtd d S )NZ08335394550z:Parsing "08335394550" to datetime overflows, at position 0rW   rj   re   rc   r(   )rZ   r[   r   r   r   rB   r.   r/   r   r<   rP   r-   )r0   rC   r   resr#   r#   r$   test_to_datetime_overflow1  s    z(TestToDatetime.test_to_datetime_overflowc              	   C   st   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tdd	}t|| d S )
N  r      )hoursr      z2020-01-01 17:00 -0100r   r   )r   r   r   r   
tz_convertr.   r/   )r0   d1Zd2r   r3   r#   r#   r$   *test_to_datetime_mixed_datetime_and_stringH  s
    z9TestToDatetime.test_to_datetime_mixed_datetime_and_stringr;   r   r   ISO8601non-ISO8601Zidsc                 C   s8   t ddd}td|g|d}tddg}t|| d S )Nr   r   rV   
2020-01-01rp   z
2020-01-02)r   r   r   r.   r/   )r0   r;   r   r   r3   r#   r#   r$   &test_to_datetime_mixed_date_and_stringP  s    z5TestToDatetime.test_to_datetime_mixed_date_and_stringr   %Y-%d-%m %H:%M:%S%zr   znon-ISO8601 formatzISO8601 formatzutc, args, expectedTz2000-01-01 01:00:00-08:00z2000-01-01 02:00:00-08:00z2000-01-01 09:00:00+00:00z2000-01-01 10:00:00+00:00datetime64[ns, UTC]r(   zall tz-aware, with utc)idFz2000-01-01 01:00:00+00:00z2000-01-01 02:00:00+00:00zall tz-aware, without utcz%all tz-aware, mixed offsets, with utcz2000-01-01 01:00:00z2000-01-01 02:00:00+0000r   r   z.tz-aware string, naive pydatetime, without utcz+tz-aware string, naive pydatetime, with utcconstructorc                 C   s   t |  S Nr   to_pydatetimerK   r#   r#   r$   <lambda>      zTestToDatetime.<lambda>c           	      C   s6   ||d }|d }t ||g||d}t|| d S )Nr   r   r   ry   )	r0   r   r   argsr3   r   ts1ts2r2   r#   r#   r$   6test_to_datetime_mixed_datetime_and_string_with_formatZ  s    CzETestToDatetime.test_to_datetime_mixed_datetime_and_string_with_formatzfmt, utc, expected2000-01-01 08:00:00+00:00z2000-01-02 00:00:00+00:00r   zISO8601, UTCz2000-01-01 09:00:00+0100r   z2000-01-02 02:00:00+0200z	UTC+02:00zISO8601, non-UTCz2000-02-01 00:00:00+00:00znon-ISO8601, UTCz2000-02-01 02:00:00+0200znon-ISO8601, non-UTCc                 C   s$   t ddd g||d}t|| d S )Nz2000-01-01 09:00:00+01:00z2000-01-02 02:00:00+02:00r   ry   )r0   r   r   r3   r2   r#   r#   r$   (test_to_datetime_mixed_offsets_with_none  s    1z7TestToDatetime.test_to_datetime_mixed_offsets_with_noner   z2000-01-01 02:00:00-07:00z*all tz-aware, mixed timezones, without utcc                 C   s   t |  S r   r   r   r#   r#   r$   r     r   c              	   C   sH   ||d }||d }t jtdd t||g|dd W 5 Q R X d S )Nr   r   z1cannot be converted to datetime64 unless utc=TruerW   Fr   rZ   r[   r\   r   )r0   r   r   r   r   r   r#   r#   r$   =test_to_datetime_mixed_datetime_and_string_with_format_raises  s     zLTestToDatetime.test_to_datetime_mixed_datetime_and_string_with_format_raisesc                 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=   )r0   r   rR   r   r   r3   r#   r#   r$   test_to_datetime_np_str  s    



z&TestToDatetime.test_to_datetime_np_strzs, _format, dtz2015-1-1z%G-%V-%u  r      r   z2015-1-4  r   z2015-1-7r   c                 C   s   t ||d|kstd S rx   r   )r0   s_formatr   r#   r#   r$   %test_to_datetime_iso_week_year_format  s    
z4TestToDatetime.test_to_datetime_iso_week_year_formatzmsg, s, _formatzdISO week directive '%V' is incompatible with the year directive '%Y'. Use the ISO year '%G' instead.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 %jz1999 51 Sundayz%Y %V %Az1999 51 Sunz%Y %V %az	1999 51 1z%Y %V %wz%Y %V %uzxISO week directive '%V' must be used with the ISO year directive '%G' and a weekday directive '%A', '%a', '%w', or '%u'.Z20z%Vz%V %Az%V %az%V %wz%V %uz%G %jz	20 Mondayre   raiserj   rc   c              	   C   sD   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  rW   rs   )r   r   rZ   r[   r\   r   )r0   r   r	  r
  re   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   )r0   r   dtir1   r2   r#   r#   r$   test_to_datetime_dtarr  s    z%TestToDatetime.test_to_datetime_dtarrc                 C   s(   t tddd}|tdddks$td S )N  r      r   r   rB   r0   actualr#   r#   r$   test_to_datetime_pydatetime  s    z*TestToDatetime.test_to_datetime_pydatetimec                 C   s    t d}|tdddkstd S )NZ20080115r  r   r  r  r  r#   r#   r$   test_to_datetime_YYYYMMDD  s    z(TestToDatetime.test_to_datetime_YYYYMMDDc                 C   s   d}t |dd|kstd S )NzMonth 1, 1999rc   r   r   )r0   rR   r#   r#   r$   "test_to_datetime_unparsable_ignore  s    z1TestToDatetime.test_to_datetime_unparsable_ignorec              	   C   s   t dp td}td}tdgd }t|j|j dk sBtt|j|j dk sZt|jd ksht|jd ksvtW 5 Q R X d S )N
US/Easternnowr       _B)r.   set_timezoner   r   abs_valuerB   r   )r0   r  ZpdnowZpdnow2r#   r#   r$   test_to_datetime_now  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 	d}t
| j| dk sjtt
| j| dk st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todaydatetime64[ns]r   nsr  )r.   r  r+   
datetime64astypeint64r   r   r#  Zas_unitr   	normalizer!  rB   r   )r0   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   t |g d S r   r   )r0   rC   r#   r#   r$   (test_to_datetime_today_now_unicode_bytes  s    z7TestToDatetime.test_to_datetime_today_now_unicode_byteszformat, expected_ds)r   
2020-01-03)r   z
2020-03-01)Nr-  zstring, attribute)r  utcnow)r#  r#  c                 C   sF   t d|g|dd}t|tt| gdd}||   dk sBtd S )Nz2020-01-03 00:00:00ZTr   r   r(   r   )r   r   getattrr   maxtotal_secondsrB   )r0   r;   Zexpected_dsstring	attributer2   r3   r#   r#   r$    test_to_datetime_now_with_format  s     z/TestToDatetime.test_to_datetime_now_with_formatr   
2000-01-01
2000-01-02c                 C   s   t ||dt|kstd S Nr   rA   )r0   r%   r   r#   r#   r$   test_to_datetime_dt64s  s    z%TestToDatetime.test_to_datetime_dt64sarg, format)
2001-01-01r   )z
01-01-2001z%d-%m-%Yc                 C   s2   t |tdg|d}tddg}t|| d S )Nr   rp   r:  )r   r+   r&  r   r.   r/   )r0   rC   r;   r2   r3   r#   r#   r$   test_to_datetime_dt64s_and_str  s    	z-TestToDatetime.test_to_datetime_dt64s_and_strz
1000-01-01z
5000-01-02c                 C   s`   t |||d}t|tst|jdks*t|j|ks8tt|}|jdksNt|j|ks\td S )Nre   r%   r	  )r   r<   r   rB   unitasm8)r0   r%   r   re   tsr#   r#   r$   'test_to_datetime_dt64s_out_of_ns_bounds  s    z6TestToDatetime.test_to_datetime_dt64s_out_of_ns_boundsc              	   C   s~   t t t jjd}d}tjt|d t| W 5 Q R X tjt|d t	|d|d W 5 Q R X t	|d|dt
ksztd S )ND"Out of bounds nanosecond timestamprW   r  r<  rj   )r+   r&  Ziinfor(  r0  rZ   r[   r   r   r   r   rB   )r0   r%   Zdt64r   r#   r#   r$   $test_to_datetime_dt64d_out_of_bounds  s    z3TestToDatetime.test_to_datetime_dt64d_out_of_boundsr=  r	  rA  c                 C   s  t d|t d|gd }t||d}|rDtdd |D dd}ntd	d |D d
d}t|| |t dg }t|dd t|d|d}|stt|d jt|d jgd tg }ntt j	|dd}t|| t|d|d}|st
|}t|| d S )Nr5  r6  r   r   c                 S   s   g | ]}t |jqS r#   r   r>  rI   r#   r#   r$   rL   7  s     zBTestToDatetime.test_to_datetime_array_of_dt64s.<locals>.<listcomp>zM8[s]r(   c                 S   s   g | ]}t |jqS r#   rD  rI   r#   r#   r$   rL   9  s     rk   
9999-01-01r  r   rj   r<  r   r   rc   )r+   r&  r   r   r.   r/   r   r>  r   r,   r   )r0   r%   r=  dtsr2   r3   Zdts_with_oobr#   r#   r$   test_to_datetime_array_of_dt64s*  s2    

z.TestToDatetime.test_to_datetime_array_of_dt64sc                 C   s,   t tddd}td}||ks(td S )NrE  rc   r   )r   r+   r&  rB   r~   r#   r#   r$    test_out_of_bounds_errors_ignoreW  s    
z/TestToDatetime.test_out_of_bounds_errors_ignorec                 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/   )r0   r%   r1   r2   r3   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 5 Q R X t||d	d
}tt dt dgdd}t|| t||dd
}tddgdd}t|| d S )NrI  r   r   rJ  r  zLTz-aware datetime.datetime cannot be converted to datetime64 unless utc=TruerW   r   rc   )r%   re   z2013-01-01 13:00:00-08:00z2013-01-02 14:00:00-05:00r-   r(   rj   r   zdatetime64[ns, US/Pacific])	r   rZ   r[   r\   r   r   r.   r/   r   )r0   r%   r1   r   r2   r3   r#   r#   r$   test_to_datetime_tz_mixedj  s*    

 z(TestToDatetime.test_to_datetime_tz_mixedc                 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/   )r0   r%   Zts_string_1Zts_string_2r1   r3   r2   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%   r   2000-06-01 07:00:00+00:00r   r)   r  )r   r   r+   r,   Zlocalizer   r-   r   r   r.   r/   )r0   r%   Z
us_easternr1   r2   r3   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   )r0   r%   Zinit_constructorZend_constructorrz   Zexpected_datar2   r3   r#   r#   r$   test_to_datetime_utc_true  s    

   z(TestToDatetime.test_to_datetime_utc_truezscalar, expectedr[  r]  r   r\  r^  c                 C   s    t |dd|d}||kstd S )Nr_  Tr`  r   )r0   r%   scalarr3   r2   r#   r#   r$    test_to_datetime_utc_true_scalar  s    	z/TestToDatetime.test_to_datetime_utc_true_scalarc                 C   s:   d}t t|gd|d}tt|ddg}t|| d S )Ng {ѴCTrW  r   r   )r   r   r   r.   r=   )r0   r%   r?  r2   r3   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   TrW  r   r   r   r   r   r.   r=   )r0   r%   r?  Zexpected_tsrz   r2   r3   r#   r#   r$   4test_to_datetime_utc_true_with_series_tzaware_string  s    zCTestToDatetime.test_to_datetime_utc_true_with_series_tzaware_stringzdate, dtype)re  r$  )re  r   c                 C   s:   t tdddg}tt |g|dd|d}t|| d S )Nre  r   r   r(   TrW  )r   r   r   r.   r=   )r0   r%   r   r)   r3   r2   r#   r#   r$   1test_to_datetime_utc_true_with_series_datetime_ns  s    z@TestToDatetime.test_to_datetime_utc_true_with_series_datetime_nspsycopg2c           
   
   C   s&  dd l }|jtjjt|j d tdkt	dd |j
jdd d}|j
jdd d}tjtdd	d	d
d|dtddd	d
d|dgtd}t|dd|d}tddgdd d}t|| tdg|j
jdd dd}	t|	stt|	d|d}t||	 t|	dd|d}tdgdd}t|| d S )Nr   z2.8.7z6psycopg2.tz is deprecated (and appears dropped) in 2.9)r[   r   i)r   r   ir   r   r   r   rV  r(   rj   T)re   r   r%   r   rX  r   rY  z2000-01-01 08:00:00r   r<  z2000-01-01 13:00:00)ri  nodeZ
add_markerrZ   r   r   r   __version__splitAttributeErrorr   ZFixedOffsetTimezoner+   r,   r   r-   r   r   r.   r/   r   rB   )
r0   r"   r%   ri  Ztz1Ztz2r1   r2   r3   ir#   r#   r$   test_to_datetime_tz_psycopg2  sB    	z+TestToDatetime.test_to_datetime_tz_psycopg2c              	   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\]rW   rj   r<  rc   )rZ   r[   	TypeErrorr   r   rB   )r0   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 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 datetimerW   Fr   zA^time data "True" doesn\'t match format "%Y%m%d", at position 1. r   20130101Tr   g        rj   r<  )typerZ   r[   rp  r   r   r#  r\   r   r.   r/   r   r   r0   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 datetimerW   )rZ   r[   rp  r   )r0   rC   r   r#   r#   r$   test_datetime_invalid_datatype1  s    z-TestToDatetime.test_datetime_invalid_datatypec              	   C   s.   t jtdd tdgd|d W 5 Q R X d S )Nz*':' is a bad directive in format 'H%:M%:S%rW   z00:00:00zH%:M%:S%rs   r  )r0   re   r#   r#   r$   test_invalid_format_raises8  s
     z)TestToDatetime.test_invalid_format_raisesr   az00:01:99z%H:%M:%Sc              	   C   s   t |d|d}||kstt |d|d}|tks4tddt dddt dd	g}tjt|d
 t |d|d W 5 Q R X d S )Nrc   re   r;   rj   r   @^time data "a" doesn\'t match format "%H:%M:%S", at position 0. r   <^Given date string "a" not likely a datetime, at position 0$S^unconverted data remains when parsing with format "%H:%M:%S": "9", at position 0. 2^second must be in 0..59: 00:01:99, at position 0$rW   r  )r   rB   r   r   r   rZ   r[   r\   r0   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s4t|d k	rjd}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 )Nrc   ry  rj   z:^time data ".*" doesn\'t match format ".*", at position 0.rW   r  z!^Out of bounds .*, at position 0$)r   rB   r   rZ   r[   r\   r   r~  r#   r#   r$    test_datetime_outofbounds_scalarW  s    z/TestToDatetime.test_datetime_outofbounds_scalarr>   bz99:00:00c              
   C   s   |d krt |dkrt}nd }tj|dd t|d|d}W 5 Q R X t|t| tj|dd t|d|d}W 5 Q R X t|ttgt |  d	dd	t
 d
dt
 d
dg}tjt|d. tj|dd t|d|d W 5 Q R X W 5 Q R X d S )Nr   Could not infer formatrW   rc   ry  rj   r   r{  rz  r   r|  r}  r  )lenUserWarningr.   assert_produces_warningr   r/   r   r   r   r   r   rZ   r[   r\   )r0   r>   r;   warnr   r   r#   r#   r$   test_datetime_invalid_indexj  s&    


z*TestToDatetime.test_datetime_invalid_indexz%Y%m%d %H:%M:%Sc           	      C   sF   d}|gd }||}t |||dd}t |||dd}t|| d S N20130101 00:00:00順 T)r   r;   r%   Fry   )	r0   r   r;   r   r   
test_datesrz   r2   r3   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~   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  rl   )r0   r   r;   r   r  rz   r2   r3   r#   r#   r$   test_to_datetime_cache_series  s    
z,TestToDatetime.test_to_datetime_cache_seriesc                 C   s(   d}t |dd}td}||ks$td S )Nr  Tr   rA   )r0   r   r2   r3   r#   r#   r$   test_to_datetime_cache_scalar  s    z,TestToDatetime.test_to_datetime_cache_scalarzdatetimelikes,expected_valuesrV   z
2012-07-26r   z2012 July 26c                 C   s4   t |dd}t|dd}t |dd}t|| d S )Nr-   r(   rj   r   r$  rl   )r0   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%   )inputr3      r-   (   r$  r   x   r   c                 C   s   t ||d}t|| d S r7  rt   )r0   r%   r  r3   r2   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   s.   d}t jt|d t||d W 5 Q R X d S )Nz,Cannot use '%W' or '%U' without day and yearrW   rp   r  )r0   r   r;   r   r#   r#   r$   'test_week_without_day_and_calendar_year  s    z6TestToDatetime.test_week_without_day_and_calendar_yearc                 C   s`   dddg}t |dd}ttdddd	d
td ddtdddd	d
td ddtg}t|| d S )NrM  rN  Z20100240rj   r     r   r   r   r   i@8  r   iPF  )r   r   r   r
   r   r.   r/   r0   
ts_stringsr2   r3   r#   r#   r$   test_to_datetime_coerce  s    z&TestToDatetime.test_to_datetime_coercezstring_arg, format)zMarch 1, 2018z	%B %d, %Y)z
2018-03-01r   outofboundsi'  rE  zJanuary 1, 9999c                 C   s:   ||g}t |d|d}ttdddtg}t|| d S )Nrj   ry  r  r   r   )r   r   r   r   r.   r/   )r0   Z
string_argr;   r  r  r2   r3   r#   r#   r$   test_to_datetime_coerce_oob  s    z*TestToDatetime.test_to_datetime_coerce_oobzerrors, expected200622-12-31111111-24-11c              	   C   s>   ddg}t jtdd t||d}W 5 Q R X t || d S )Nr  r  r  rW   r   )r.   r  r  r   r/   )r0   re   r3   r  r2   r#   r#   r$   #test_to_datetime_malformed_no_raise%  s    
z2TestToDatetime.test_to_datetime_malformed_no_raisec              
   C   sP   ddg}d}t jt|d, tjtdd t|dd W 5 Q R X W 5 Q R X d S )Nr  r  zParsed string "200622-12-31" gives an invalid tzoffset, which must be between -timedelta\(hours=24\) and timedelta\(hours=24\), at position 0rW   r  r  r   rZ   r[   r\   r.   r  r  r   )r0   r  r   r#   r#   r$    test_to_datetime_malformed_raise4  s     z/TestToDatetime.test_to_datetime_malformed_raisec                 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:30rV   )r   r   rB   r   r.   r/   )r0   Zts_strr2   r3   r#   r#   r$   &test_iso_8601_strings_with_same_offsetH  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.   r/   r  r#   r#   r$   ,test_iso_8601_strings_with_different_offsetsV  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.   r/   r  r#   r#   r$   0test_iso_8601_strings_with_different_offsets_utcf  s    
 z?TestToDatetime.test_iso_8601_strings_with_different_offsets_utcc              	      s   dt dddd ddgt t fddttD sBtt d}t d}t }td	t dt d t d d gtd
}t	
|d d | ||jd   dkst||jd   dksttjtdd t| W 5 Q R X d S )NrY   z
1990-01-01z2015-03-14T16:15:14.123-08:00z2019-03-04T21:56:32.620-07:00r#  r  c                 3   s   | ]} | | kV  qd S r   r#   )rJ   rn  rR   valsr#   r$   	<genexpr>{  s     zPTestToDatetime.test_mixed_offsets_with_native_datetime_raises.<locals>.<genexpr>r   r(   g?zTz-aware datetime.datetimerW   )r   r   allranger  rB   r   r   r-   r.   r=   r  r1  rZ   r[   r\   )r0   r  r#  mixedr3   r#   r  r$   .test_mixed_offsets_with_native_datetime_raisesn  s6    	$


z=TestToDatetime.test_mixed_offsets_with_native_datetime_raisesc              
   C   sD   t dgd }ttddddttddd	gd }t|| d S )
NrM  rV   r  r   r   r      r   r   )r   r   r   r   r   r.   r/   r~   r#   r#   r$   #test_non_iso_strings_with_tz_offset  s
     z2TestToDatetime.test_non_iso_strings_with_tz_offsetzts, expectedz
2018-01-01r   z2018-01-01 08:00c                 C   s   t |dd}||kstd S )NTr  r   )r0   r?  r3   r2   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 )NrB  rW   rM   rp   rZ   r[   r   r   )r0   r  r   r#   r#   r$   *test_to_datetime_with_format_out_of_bounds  s    z9TestToDatetime.test_to_datetime_with_format_out_of_boundsc                 C   s4   t jtdgtd}t|dd}|jtjks0td S )Nz2012-06-13T01:39:00Zr(   Tr  )	r+   r,   r	   r-   r   r   r   r   rB   )r0   r1   r2   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_offr   r   r   rV   r   )Z-pandas.tests.indexes.datetimes.test_timezonesr  r   r   r   rB   )r0   r  r   r2   r#   r#   r$   test_to_datetime_fixed_offset  s    z,TestToDatetime.test_to_datetime_fixed_offset)[r   r   r   rZ   r   filterwarningsr   r   r   r   r    r   r   r   r   r   r  r  r  r   r  r  r  r  r  r  r   Zskip_if_windowsr"  r*  r,  r4  r+   r&  r8  r;  r@  rC  rG  rH  rK  rL  rP  rZ  listr,   r   ra  rc  rd  rg  rh  
skip_if_noro  rq  ru  boolr   rv  rw  r  r  r  tupler   r  r  r  r  rY   r   r  r|   r}   NaNr  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r#   r#   r#   r$   r   0  sJ  

  
		
3
	

	

/
		

w


 

 
,
	



/


 


    


%
r   c                	   @   s  e Zd Zejdddgejddedgdd Zejddd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 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egd d!ddgd#d$d"dgd%ggd&d' Zejd(ed)d#d$gd#d$ed)ggd*d+ Zd,d- Zd.d/ Zd0d1 Zejdeegd2d3 Zejd4eejgd5d6 Zd7d8 Zd9d: Zejd;d"d<gd=d> Zejd;d"d<gd?d@ ZdAdB Z d%S )CTestToDatetimeUnitr=  YMitem   c                 C   s\   t ||d}t|g}t|g||d}t|| ttj|gtd||d}t|| d S )Nr=  r=  r%   r(   )r   r   r   r.   r/   r+   r,   r-   )r0   r%   r=  r  r?  r3   r2   r#   r#   r$   'test_to_datetime_month_or_year_unit_int  s    
z:TestToDatetimeUnit.test_to_datetime_month_or_year_unit_intc              
   C   s4  d}d| d}t jt|d tdg|dd W 5 Q R X t jt|d0 tjt|d tdg|dd W 5 Q R X W 5 Q R X t jt|d tdg|d	d W 5 Q R X tdg|d
d}ttgdd}t	|| tjt|d tdg|d
d}W 5 Q R X t	|| tdg|d}tdg|d}t	|| d S )Nz*strings will be parsed as datetime stringsz(Conversion of non-round float with unit=z is ambiguousrW         ?r  r=  re   z1.5rc   rj   rk   r(         ?r  r   )
rZ   r[   r\   r   r.   r  FutureWarningr   r   r/   )r0   r%   r=  Zwarn_msgr   r   r3   r#   r#   r$   3test_to_datetime_month_or_year_unit_non_round_float  s$    $zFTestToDatetimeUnit.test_to_datetime_month_or_year_unit_non_round_floatc              	   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 unitrW   r   rA  rM   )r=  r;   r%   r  rt  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 )Nl   qMe;r   r  r   r   rA  rc   r=  re   r%   
1970-01-02r(   rj   z8cannot convert input 11111111111111111 with the unit 'D'rW   r  )r   r   r+   rY   r   r   r   r-   r.   r/   r   rZ   r[   r   r0   r%   r>   r2   r3   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     #0U.KK% r   rc   r	  re   r=  r%   r(   rj   z@cannot convert input 1420043460000000000000000 with the unit 's'rW   r  )r   r   r+   rY   r   r   r-   r.   r/   r   rZ   r[   r   r  r#   r#   r$   $test_unit_array_mixed_nans_large_int  s    z7TestToDatetimeUnit.test_unit_array_mixed_nans_large_intc              	   C   s2   d}t jt|d tddd|d W 5 Q R X d S )Nz+non convertible value foo with the unit 's'rW   r   r  r	  r  r  rt  r#   r#   r$   8test_to_datetime_invalid_str_not_out_of_bounds_valuerror)  s    zKTestToDatetimeUnit.test_to_datetime_invalid_str_not_out_of_bounds_valuerrorerrorr  rj   rc   c                 C   s6   t d}tdd||d}||ks$tt|t s2td S )Nz1970-05-09 14:25:11iǊ r	  r  )r   r   rB   r<   )r0   r%   r  r3   r2   r#   r#   r$   test_unit_consistency0  s    z(TestToDatetimeUnit.test_unit_consistencyre   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/   )r0   r%   re   r)   r3   r1   r2   r#   r#   r$   test_unit_with_numeric8  s    z)TestToDatetimeUnit.test_unit_with_numericzexp, arr, warningr   r  r  r   r  r  Nc              	   C   s@   t |}tj|dd t|d|d}W 5 Q R X t|| d S )Nr  rW   rj   r<  )r   r.   r  r   r/   )r0   r%   r   r1   warningr3   r2   r#   r#   r$   test_unit_with_numeric_coerceB  s    z0TestToDatetimeUnit.test_unit_with_numeric_coercer1   rr  c                 C   sb   t dd |D dd}t|d|d}t|| t|d|d}t|| t|}t|| d S )Nc                 S   s   g | ]}t |qS r#   rH   rI   r#   r#   r$   rL   e  s     z6TestToDatetimeUnit.test_unit_mixed.<locals>.<listcomp>rk   r(   rj   r<  r  )r   r   r.   r/   r   )r0   r%   r1   r3   r2   r#   r#   r$   test_unit_mixedY  s    z"TestToDatetimeUnit.test_unit_mixedc                 C   s&   t dd|d}td}||ks"td S )Ng aAr	  r  z2015-06-19 19:55:31.877000192rA   rh   r#   r#   r$   test_unit_roundingq  s    z%TestToDatetimeUnit.test_unit_roundingc                 C   s2   t dgd dd}t|dd|d}t|| d S )Ng   BrV   r   r   rc   r	  r  rO  r0   r%   r3   r2   r#   r#   r$   test_unit_ignore_keeps_namex  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	  Trc   )r=  r   re   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                    s   g | ]} | qS r#   r#   rJ   tepochr#   r$   rL     s     z<TestToDatetimeUnit.test_to_datetime_unit.<locals>.<listcomp>r  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   r  r'  r   r.   r=   )r0   r)   rR   r2   r3   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>r  r	  r  c                 S   s   g | ]}t d t|d qS r  r  r  r#   r#   r$   rL     s     )r   r  r   r   r.   r=   )r0   r  rR   r2   r3   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   rV   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'  rT   r   r   roundr.   r=   )r0   rR   r2   r3   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   rV   r   rA  r  r  
1970-01-03r   )r   r   r+   rY   r   r   r.   r/   r~   r#   r#   r$   test_to_datetime_unit_na_values  s
    z2TestToDatetimeUnit.test_to_datetime_unit_na_valuesbad_valikc              	   C   s:   | d}t jt|d tdd|gdd W 5 Q R X d S )Nz with the unit 'D'rW   r   rV   rA  r  r  )r0   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   rV   rA  rj   r  )r   r   r   r.   r/   )r0   r  r3   r2   r#   r#   r$   test_to_timestamp_unit_coerce  s
    z0TestToDatetimeUnit.test_to_timestamp_unit_coercec           
   	   C   s   d}d}d| }t d|d | d gtd}|| tj}dD ]*}t|d|d	}tj|tj|d
d q@t d|d gtd}t d| d gtd}	tj	t
|d t|ddd	 W 5 Q R X tj	t
|d t|	ddd	 W 5 Q R X d S )Nz"cannot convert input with unit 'D'g  S$Bl            r   g{Gzt?r(   )r  rj   rc   rA  r  g|=)ZrtolrW   r  )r   rT   r'  r+   r(  r   r.   assert_almost_equalrZ   r[   r   )
r0   r   Zoneday_in_nsZtsmax_in_daysZshould_succeedr3   Z
error_moderesult1Zshould_fail1Zshould_fail2r#   r#   r$   (test_float_to_datetime_raise_near_bounds  s"     z;TestToDatetimeUnit.test_float_to_datetime_raise_near_bounds)!r   r   r   rZ   r   r   rT   r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  intr  r   r+   rY   r  r  r  r  r  r  r#   r#   r#   r$   r    s`   
"





	



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    rV   r   r   rG   rV     :   ;   r   r  r   	rQ  rR  rS  rT  rU  secondr  usr%  )r   r0   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 )NrQ  rR  rS  rQ  rR  rS  r   20150204 00:00:00z20160305 00:0:00)r   r   r   r.   r=   to_dictr0   r
  r%   r2   r3   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 )NrQ  rR  rS  rV   r   r  z20160205 00:0:00)r  r   r   r   r.   r=   )r0   r
  r%   df2r2   	expected2r#   r#   r$   &test_dataframe_dict_with_constructable  s    z>TestToDatetimeDataFrame.test_dataframe_dict_with_constructabler=  Zyearsmonthsdaysr   r   r  )rQ  rR  rS  rT  rU  r  rQ  rR  rS  rT  rU  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.   r=   )r0   r
  r%   r=  r2   r3   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 )NrQ  rR  rS  rT  rU  r  r  r  r%  r  r  r   20150204 06:58:10.00100200320160305 07:59:11.001002003)r   r  r   r   r.   r=   )r0   r
  r%   dr2   r3   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_dtype1  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  rV   r  r   rG   r  z^^cannot assemble the datetimes: time data ".+" doesn\'t match format "%Y%m%d", at position 1\.rW   r   rj   r<  r  )
r   rZ   r[   r\   r   r   r   r   r.   r=   )r0   r%   r  r   r2   r3   r#   r#   r$   test_dataframe_coerce<  s    z-TestToDatetimeDataFrame.test_dataframe_coercec              	   C   s>   d}t jt|d" | }d|d< t||d W 5 Q R X d S )Nz?extra keys have been passed to the datetime assemblage: \[foo\]rW   r   r   r   )rZ   r[   r\   copyr   )r0   r
  r%   r   r  r#   r#   r$   !test_dataframe_extra_keys_raisesmK  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 missingrW   r   r  )r0   r
  r%   r"  r   r#   r#   r$   "test_dataframe_missing_keys_raisesS  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  rV   r  r   rG   r  rQ  rS  rW   r   )rQ  rR  rS  rT  rR  )r   r  rZ   r[   r\   r   )r0   r%   r   r  r#   r#   r$   'test_dataframe_duplicate_columns_raisesf  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  rV   r   r   rG   r  Zint16r   r  20160305 00:00:00)r   r   r'  r   r   r.   r=   r0   r%   r
  r2   r3   r#   r#   r$   test_dataframe_int16u  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  rV   r   r   rG   r  rR  Zint8rS  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 )	Nr   r   r  r   r  zk^cannot assemble the datetimes: unconverted data remains when parsing with format ".*": "1", at position 0.rW   r   )r   rZ   r[   r\   r   )r0   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  rV   r   r   rG   r  Tr  z
2015-02-04z
2016-03-05r$  r(   r   )	r   r   r   r+   r,   r   tz_localizer.   r=   )r0   r
  r2   r3   r#   r#   r$   test_dataframe_utc_true  s    z/TestToDatetimeDataFrame.test_dataframe_utc_trueN)r   r   r   rZ   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ejd	d
dddddddgejdddgdd Zejd	dddddgdd Z	ejd	ddddgd d! Z
ejd	d"d#d$d%d&d'd(d)gd*d+ Zejd	d,d-d.d/d0d1d2d3d4d5d6gd7d8 Zejd	d9d:d;d<d=d>d?d@dAdBdCgdDdE Zejd	dFdGdHgdIdJ ZdKdL ZejjdMdNdOdP ZdQdR ZdSdT ZejdUdV ZdWdX ZejejdYdZd[d\gd]d^ Zd_d` Zdadb Zdcdd Zdedf Zdgdh Zejdiedjedjgdkdl Z dmdn Z!dodp Z"dqdr Z#dsdt Z$dudv Z%dwdx Z&dydz Z'd{d| Z(d}d~ Z)ejdddddddgdd Z*dd Z+dd Z,dd Z-ejde.e/gdd Z0dS )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(   z6^Out of bounds nanosecond timestamp: .*, at position 0rW   )r+   r,   r-   rZ   r[   r   r   )r0   r1   r   r#   r#   r$   %test_to_datetime_barely_out_of_bounds  s    z8TestToDatetimeMisc.test_to_datetime_barely_out_of_boundszarg, exp_str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   )r0   r%   rC   Zexp_strr2   r   r#   r#   r$   test_to_datetime_iso8601  s    z+TestToDatetimeMisc.test_to_datetime_iso8601zinput, format)2012%Y-%m)z2012-01r   )
2012-01-01r   )2012-01-01 10r   )2012-01-01 10:00r   )2012-01-01 10:00:00r   )z2012-01-01 10:00:00.123r   )r   r   r   TFc              	   C   s:   t jtd| d| dd t|||d W 5 Q R X d S )Ntime data \"z\" doesn't match format \"\", at position 0rW   r   r  )r0   r  r;   r   r#   r#   r$   test_to_datetime_iso8601_fails  s
    z1TestToDatetimeMisc.test_to_datetime_iso8601_fails)r3  r2  )r4  r   )r5  r   )r6  r   c              	   C   sH   d dt ddt dg}tjt|d t||d W 5 Q R X d S )Nr   r   r   z:^time data ".*" doesn't match format ".*", at position 0. rW   rp   r   )r0   r  r;   r   r#   r#   r$   $test_to_datetime_iso8601_exact_fails  s    

z7TestToDatetimeMisc.test_to_datetime_iso8601_exact_fails)z2012-01-01 00r   )z2012-01-01 00:00r   )r/  r   c                 C   s*   t ddd}t||dd}||ks&td S )Nr   r   Fr   r   r   rB   r0   r  r;   r3   r2   r#   r#   r$   "test_to_datetime_iso8601_non_exact  s    z5TestToDatetimeMisc.test_to_datetime_iso8601_non_exact)2020-01z%Y/%m)r   z%Y/%m/%d)2020-01-01 00z%Y/%m/%dT%H)2020-01-01T00z%Y/%m/%d %H)2020-01-01 00:00z%Y/%m/%dT%H:%M)2020-01-01T00:00z%Y/%m/%d %H:%M)2020-01-01 00:00:00z%Y/%m/%dT%H:%M:%S)2020-01-01T00:00:00z%Y/%m/%d %H:%M:%Sc              	   C   s8   t jtd| d| dd t||d W 5 Q R X d S )Nr7  z\" doesn\'t match format \"r8  rW   rp   r  )r0   r  r;   r#   r#   r$   "test_to_datetime_iso8601_separator  s
    z5TestToDatetimeMisc.test_to_datetime_iso8601_separator)r>  r2  )r   r   )r?  r   )r@  %Y-%m-%dT%H)rA  r   )rB  %Y-%m-%dT%H:%M)rC  r   )rD  %Y-%m-%dT%H:%M:%S)z2020-01-01T00:00:00.000%Y-%m-%dT%H:%M:%S.%f)z2020-01-01T00:00:00.000000rI  )z2020-01-01T00:00:00.000000000rI  c                 C   s(   t ddd}t||d}||ks$td S Nr   r   rp   r;  r<  r#   r#   r$   test_to_datetime_iso8601_valid	  s    z1TestToDatetimeMisc.test_to_datetime_iso8601_valid)z2020-1r2  )z2020-1-1r   )z
2020-1-1 0r   )z
2020-1-1T0rF  )z2020-1-1 0:0r   )z2020-1-1T0:0rG  )z2020-1-1 0:0:0r   )z2020-1-1T0:0:0rH  )z2020-1-1T0:0:0.000rI  )z2020-1-1T0:0:0.000000rI  )z2020-1-1T0:0:0.000000000rI  c                 C   s(   t ddd}t||d}||ks$td S rJ  r;  r<  r#   r#   r$   #test_to_datetime_iso8601_non_padded(	  s    z6TestToDatetimeMisc.test_to_datetime_iso8601_non_padded)z#2020-01-01T00:00:00.000000000+00:00z%Y-%m-%dT%H:%M:%S.%f%z)z2020-01-01T00:00:00+00:00%Y-%m-%dT%H:%M:%S%z)z2020-01-01T00:00:00ZrM  c                 C   s.   t dddtjd}t||d}||ks*td S )Nr   r   r   rp   )r   r   r   r   rB   r<  r#   r#   r$   ,test_to_datetime_iso8601_with_timezone_valid>	  s    
z?TestToDatetimeMisc.test_to_datetime_iso8601_with_timezone_validc                 C   s(   t d|d}tddd}||ks$td S )NZ2001r   r   r   r  )r0   r%   rsZxpr#   r#   r$   test_to_datetime_defaultL	  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 specifiedrW   zProvide formatz
01-13-2012Tdayfirstr%   r  rt  r#   r#   r$   "test_to_datetime_respects_dayfirstQ	  s    z5TestToDatetimeMisc.test_to_datetime_respects_dayfirstc                 C   s4   t tddd}t||d}|d |d ks0td S )Nr7   r   r  r   r   )r   r   r   rB   )r0   r%   rR   r2   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 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 z@^time data " " doesn\'t match format "%m/%d/%Y", at position 2. r   rW   r  r<  rj   i  r   r   r  rc   )
r   r   rZ   r[   r\   r   r   r   r.   r=   )r0   r%   rR   r   Zresult_coerceZexpected_coerceZresult_ignorer#   r#   r$   %test_to_datetime_with_space_in_seriesd	  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   rV   r   index%b %yr:   r   r   rO   r.   r=   )r0   r%   r   r3   r2   r#   r#   r$   test_to_datetime_with_applys	  s    z.TestToDatetimeMisc.test_to_datetime_with_applyc                 C   s.   t ddd}tdddd}||ks*td S )Nz2020-01-01 00:00:00UTCz%Y-%m-%d %H:%M:%S%Zrp   r   r   r   )r   r   r*  rB   r~   r#   r#   r$   test_to_datetime_timezone_name}	  s    z1TestToDatetimeMisc.test_to_datetime_timezone_namere   r  rj   rc   c                    sJ   t dddgdddgd}t|d| d	}| fd
d}t|| d S )NrX  rY  r   r   rV   r   rZ  r\  rd   c                    s   t | dd dS )Nr\  rj   rd   r+  r   r   r#   r$   r   	  r   zOTestToDatetimeMisc.test_to_datetime_with_apply_with_empty_str.<locals>.<lambda>r]  )r0   r%   re   r   r3   r2   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   r0   r%   r2   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 ra  )r   r   r  rB   rb  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;  rh   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 )Nr1  r   r   r   r  r#   r#   r$   test_to_datetime_strings	  s    z+TestToDatetimeMisc.test_to_datetime_stringsc                    s:   dddg} fdd|D }dd |D }t || d S )Nr1  Z20120101z20120101 12:01:01c                    s   g | ]}t | d qS )r   r+  )rJ   r  r   r#   r$   rL   	  s     zITestToDatetimeMisc.test_to_datetime_strings_variation.<locals>.<listcomp>c                 S   s   g | ]}t |qS r#   rH   )rJ   date_strr#   r#   r$   rL   	  s     )r.   r  )r0   r%   r,   r3   r2   r#   r   r$   "test_to_datetime_strings_variation	  s    
z5TestToDatetimeMisc.test_to_datetime_strings_variationr2   r1  c                 C   s   t ddd}||kstd S )Nr   r   )r   rB   r~   r#   r#   r$   'test_to_datetime_strings_vs_constructor	  s    z:TestToDatetimeMisc.test_to_datetime_strings_vs_constructorc              	   C   sh   t ddgd|d}ttjddgdd}t|| d}tjt|d t ddgd	|d W 5 Q R X d S )
Nr   1rc   r<  Or(   z<^Given date string "1" not likely a datetime, at position 1$rW   r  )	r   r   r+   r,   r.   r   rZ   r[   r\   )r0   r%   r2   r3   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 )Nrx  d   rc   r<  rl   )r0   r%   seriesr2   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]rk  r   )r+   r(  viewr'  r   rB   r   )r0   rb  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   r  rT  )r   r   r>   r  Zasi8r.   r/   )r0   rngZintsr2   r#   r#   r$   !test_to_datetime_list_of_integers	  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 00:00:00 to unit='ns' without overflowrW   z1/1/1700Br  )startr  r  )rZ   r[   r   r   r0   r   r#   r#   r$   r   	  s    z,TestToDatetimeMisc.test_to_datetime_overflowc              	   C   s<   t jdgtd}tjtdd t|d|d W 5 Q R X d S )NZ87156549591102612381000001219H5r(   Unknown datetime string formatrW   r  r<  )r+   r,   r-   rZ   r[   r\   r   )r0   r%   invalidr#   r#   r$   test_string_invalid_operation	  s    z0TestToDatetimeMisc.test_string_invalid_operationc                 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/2000r(   r   rk   r   r   )r+   r,   rY   r-   empty	enumerater   r   r	   r   Zarray_to_datetimer.   r  r   r<   r   rB   Zassert_numpy_array_equalr>   )r0   r%   stringsr3   rn  r   r2   result2r#   r#   r$   test_string_na_nat_conversion	  s    
z0TestToDatetimeMisc.test_string_na_nat_conversionc              	   C   s   t jdt jgtd}d}tjt|d t|d|d W 5 Q R X t|d|d}t|}t	
|| tjt|d t|d|d W 5 Q R X d S )Nz
1/100/2000r(   rw  rW   r  r<  rc   )r+   r,   rY   r-   rZ   r[   r\   r   r   r.   r/   )r0   r%   Z	malformedr   r2   r3   r#   r#   r$   'test_string_na_nat_conversion_malformed	  s    z:TestToDatetimeMisc.test_string_na_nat_conversion_malformedc           
   	   C   s  dddddg}t dtjdtjdg|d	d
}t td|dtjtd|dtjtd|dg|d	d
}t||d}t||d}t tjddd|d}tdD ].}|| }	t|	rt||< qt|	|d||< qtj	||dd |j
d	ksttj	||dd |j
d	kstd S )Nrx  r  cr  er7   r9   z1/5/2000r   r[  r   r   rG   rk   r(   rZ  F)Zcheck_names)r   r+   rY   r   rz  r  r   r   r.   r=   r   rB   )
r0   r%   idxrn  Zdseriesr2   Zdresultr3   rn  rK   r#   r#   r$   'test_string_na_nat_conversion_with_name
  s8      



z:TestToDatetimeMisc.test_string_na_nat_conversion_with_namer=  hmr	  r  r  r%  c                 C   s   t d| d}tdddg|d}|j|}|dkr<d}t d| d}t||}|j|ksjttt|| tt||d| d S )	NzM8[]z2000-01-01T00:00z2000-01-02T00:00r   r   )r  r  r	  )	r+   r)   r   r>   r'  r   rB   r.   r/   )r0   r%   r=  r)   baser>   Z	exp_dtyper3   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/2014r  rV   r   r  r   TrR  rQ  )	r   r   r+   r,   r   r   r   r.   r/   )
r0   r%   r1   r3   Zidx1Zidx2Zidx3Zidx4Zidx5Zidx6r#   r#   r$   test_dayfirst>
  s     
 z TestToDatetimeMisc.test_dayfirstc              	   C   sl   d}ddg}t ddgdd d}t|dd	}t|| tjt|d
 t|dd	}W 5 Q R X t|| d S )NzzParsing dates in .* format when dayfirst=.* was specified. Pass `dayfirst=.*` or specify a format to silence this warning.
31/12/2014z
10/03/2011z
2014-12-31z
2011-03-10r$  rY  Tr  rW   F)r   r   r.   r/   r  r  )r0   Zwarning_msgr1   r3   Zres1Zres2r#   r#   r$   "test_dayfirst_warnings_valid_inputQ
  s      z5TestToDatetimeMisc.test_dayfirst_warnings_valid_inputc              	   C   s:   ddg}t jtdt dd t|dd W 5 Q R X d S )Nr  z
03/30/2011zI^time data "03/30/2011" doesn\'t match format "%d/%m/%Y", at position 1. r   rW   Tr  )rZ   r[   r\   r   r   )r0   r1   r#   r#   r$   $test_dayfirst_warnings_invalid_inputg
  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   rT  r   r   Tr  )r   r  r*  r   r.   r   )r0   r  r  r3   objr2   r#   r#   r$   test_to_datetime_dta_tzx
  s    
z*TestToDatetimeMisc.test_to_datetime_dta_tzN)1r   r   r   r.  rZ   r   r   r0  r9  r:  r=  rE  rK  rL  rN  rP  r   rS  rU  rW  r   r   r^  r_  r`  rc  rd  re  rf  rh  r   r   ri  rl  ro  rq  rs  r   ry  r~  r  r  r  r  r  r  r   r   r  r#   r#   r#   r$   r-    s  



	






	

"
r-  c                   @   sb   e Zd Zejddddgejejdgddgddgddgddgddggdd	 Ze	j
d
d ZdS )TestGuessDatetimeFormat	test_listz2011-12-30 00:00:00.000000r   r   random_stringr  r#  c                 C   s(   d}t j|td}t||ks$td S )Nr   r(   )r+   r,   r-   tools _guess_datetime_format_for_arrayrB   )r0   r  Zexpected_formatZ
test_arrayr#   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 )Nrk  r(   )r  r  r+   r,   rY   rB   )r0   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   rZ   r   r   r+   rY   r  r   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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dgdd Zejdddgdd  Zd!d" ZdS )#TestToDatetimeInferFormattest_formatz%m-%d-%Yz%m/%d/%Y %H:%M:%S.%frI  c                    sN   t tdddd}| fdd}t| |d}t||d}t|| d S )	Nr5   2   Hr  r  c                    s
   |   S r   )strftimer   r  r#   r$   r   
  r   zdTestToDatetimeInferFormat.test_to_datetime_infer_datetime_format_consistent_format.<locals>.<lambda>r:   r   )r   r   rO   r   r.   r=   )r0   r%   r  rR   Zs_as_dt_stringsZwith_formatZwithout_formatr#   r  r$   8test_to_datetime_infer_datetime_format_consistent_format
  s
    zRTestToDatetimeInferFormat.test_to_datetime_infer_datetime_format_consistent_formatc              	   C   sN   dddg}t t|}dt d}tjt|d t||d W 5 Q R X d S )N01/01/2011 00:00:00z01-02-2011 00:00:00z2011-01-03T00:00:00z[^time data "01-02-2011 00:00:00" doesn\'t match format "%m/%d/%Y %H:%M:%S", at position 1. r   rW   r   )r   r+   r,   r   rZ   r[   r\   r   )r0   r%   rz   rR   r   r#   r#   r$   $test_to_datetime_inconsistent_format
  s    

z>TestToDatetimeInferFormat.test_to_datetime_inconsistent_formatc                 C   sF   dddg}t t|}t||d}t dddgdd	}t|| d S )
NzJan/01/2011zFeb/01/2011zMar/01/2011r   
2011-01-01z
2011-02-01z
2011-03-01r$  r(   )r   r+   r,   r   r.   r=   )r0   r%   rz   rR   r2   r3   r#   r#   r$   "test_to_datetime_consistent_format
  s    
 z<TestToDatetimeInferFormat.test_to_datetime_consistent_formatc                 C   sN   t tjdtjdtjgtd}t||d}t dtdtgdd}t|| d S )Nr  01/03/2011 00:00:00r(   r   r  
2011-01-03r$  	r   r+   r,   rY   r-   r   r   r.   r=   rf   r#   r#   r$   !test_to_datetime_series_with_nans
  s    
 z;TestToDatetimeInferFormat.test_to_datetime_series_with_nansc                 C   sR   t tjtjtjdddgtd}t||d}t ttdddgd	d}t|| d S )
Nr  z01/02/2011 00:00:00r  r(   r   r  z
2011-01-02r  r$  r  rf   r#   r#   r$   'test_to_datetime_series_start_with_nans
  s"     zATestToDatetimeInferFormat.test_to_datetime_series_start_with_nansztz_name, offset)r   r   )zUTC-3   )zUTC+3iLc                 C   sJ   t d| g}t|}tt|d}t td|g}t|| d S )Nz2019-02-02 08:07:13 r   2019-02-02 08:07:13)r   r   r   r   r   r*  r.   r=   )r0   Ztz_namer   rR   r2   r   r3   r#   r#   r$   "test_infer_datetime_format_tz_name
  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   sJ   t || g}t|}|dkr$tjnd }t t||dg}t|| d S )Nr  r   )r   r   r   r   r   r.   r=   )r0   r?  Zzero_tzrR   r2   r   r3   r#   r#   r$   "test_infer_datetime_format_zero_tz
  s
    z<TestToDatetimeInferFormat.test_infer_datetime_format_zero_tzr;   Nr   c                 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   )r0   r%   r;   rR   r3   r#   r#   r$   %test_to_datetime_iso8601_noleading_0s  s    z?TestToDatetimeInferFormat.test_to_datetime_iso8601_noleading_0sc              	   C   s,   t jtdd tdgdd W 5 Q R X d S )Nz2The argument 'infer_datetime_format' is deprecatedrW   z
10-10-2000T)Zinfer_datetime_format)r.   r  r  r   r	  r#   r#   r$   .test_parse_dates_infer_datetime_format_warning  s
    zHTestToDatetimeInferFormat.test_parse_dates_infer_datetime_format_warning)r   r   r   rZ   r   r   r  r  r  r  r  r  r  r  r  r#   r#   r#   r$   r  
  s4    

	
	

r  c                   @   s   e Zd Zejdddgddgddgddggdd Zd	d
 Zejdddde dfddde dfddde dfddde dfddde dfddde df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 )TestDaysInMonthr9  
2015-02-29Nr   z
2015-02-32z
2015-04-31c                 C   s   t t|d||dstd S )Nrj   re   r;   r%   )r   r   rB   )r0   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 )Nz8day is out of range for month: 2015-02-29, at position 0rW   r  r  r<  r  rt  r#   r#   r$   test_day_not_in_month_raise+  s    z+TestDaysInMonth.test_day_not_in_month_raisezarg, format, msgz/^day is out of range for month, at position 0. r   z
2015-29-02r   zS^unconverted data remains when parsing with format "%Y-%m-%d": "2", at position 0. z
2015-32-02zH^time data "2015-32-02" doesn't match format "%Y-%d-%m", at position 0. z
2015-31-04c              	   C   s.   t jt|d t|d||d W 5 Q R X d S )NrW   r  r  r  )r0   r%   rC   r;   r   r#   r#   r$   !test_day_not_in_month_raise_value0  s    'z1TestDaysInMonth.test_day_not_in_month_raise_valuezexpected, formatc                 C   s    t |d||d}||kstd S )Nrc   r  r   )r0   r%   r3   r;   r2   r#   r#   r$   test_day_not_in_month_ignoreZ  s    
z,TestDaysInMonth.test_day_not_in_month_ignore)r   r   r   rZ   r   r   r  r  r   r  r  r#   r#   r#   r$   r    s`   	






%
	r  c                8   @   s  e Zd Zejddedddfdedddfdedddfd	edddfd
edddfdedddfdedddfdedddfdedddfdedddfdedddfdedddfdedddfdedddfdedddfdedddfdedddfdedddfdedddfdedddfdedddfdedddfd edddfd!edddfd"ed#d$dfd%eddd&fd'eddd&dd(fd)eddd&d*d+fd,eddd&dd(fd-eddd&d*d+fd.eddd&dd(fd/eddd&dd(d0fd1eddd&dd(d0fd2eddd&d3d(d0fd4eddd&d*d+fd5ed6d&d7dd8d9fd:ed6d&d7fd;ed6d&d7fd<ed=ddfd>ed=d?dfd@ed=d?dfdAed=d?dfdBed=d?dfdCedDdddEfdFedDdddEdGfdHedDdddEdGdIfg.dJdK ZdLdM ZdNdO Z	ejdPdQdRdRedSddfdQdTdRedSddfdQdRdTedUddEfdQdTdTedUdEdfdVdRdRedWdEdXfdVdTdRedWdEdXfdVdRdTed#dEdYfdVdTdTed#dEdYfgdZd[ Z
ejd\d]eddddd(gd^edddd&d$ggd_d` Zejdadbeedcdddefdfeedgdddhfgdidj ZdkS )lTestDatetimeParsingWrapperszdate_str, expectedr  i  r   Z2Q2005i  r   Z2Q05Z2005Q1Z05Q1Z2011Q3r  Z11Q3Z3Q2011Z3Q11Z2000Q4r   r   Z00Q4Z4Q2000Z4Q00Z2000q4z2000-Q4z00-Q4z4Q-2000z4Q-00Z00q4Z2005z2005-11r  z2005 11z11-2005z11 2005Z200511r   rG   Z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 10:15:32    z2005/11/09 10:15:32 AMz2005/11/09 10:15:32 PM   z2005/11/09 08HzThu Sep 25 10:36:28 2003i     $      zThu Sep 25 2003zSep 25 2003zJanuary 1 2014r  z2014-06rV  z06-2014z2014-6z6-2014z20010101 12r   r   z20010101 1234r   z20010101 123456r   c                 C   s   d}t j||d\}}t||d}t|g|d}ttj|gtd||d}	t|g|d}
tt|g|d}tt|g|d}||fD ]}||kst	q||	|
||fD ]}tt
|g}t|| q|st
|}||kst	t|dd|d}||kst	d S )NT)	yearfirstr(   )r  r%   Sr   )r  r  r  )r   parse_datetime_string_with_resor   r+   r,   r-   r   r   r   rB   r   r.   r/   r   )r0   rg  r3   r%   r  r  _r}  result3result4Zresult6Zresult8Zresult9r   r   result5Zresult7r#   r#   r$   test_parsersi  s2    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/   )r0   r%   Zunique_nulls_fixtureZunique_nulls_fixture2r3   r2   r#   r#   r$   test_na_values_with_cache  s    z5TestDatetimeParsingWrappers.test_na_values_with_cachec                 C   s`   t d\}}td}td}tdgd }|tks8t|tksDt|tksPt|tks\td S )Nr   r   )r   r  r   r   r   r   rB   )r0   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  r     c                 C   s   t |||d}||ksttj|||d\}}|sJ|sJt|}	|	|ksJtt||||d}
t|g||dd }||kszt|
|kst||kstd S )N)rR  r  )rR  r  r%   r   )r	   rB   r   r  r   r   r   )r0   r%   rg  rR  r  r3   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   r  r   r   r   rB   )
r0   rg  Zexp_defZexp_nowr  r  r}  r  r  r  r#   r#   r$   test_parsers_timestring"  s    
z3TestDatetimeParsingWrappers.test_parsers_timestringzdt_string, tz, dt_string_reprz2013-01-01 05:45+0545iY  r   z5Timestamp('2013-01-01 05:45:00+0545', tz='UTC+05:45')z2013-01-01 05:30+0530iJ  z5Timestamp('2013-01-01 05:30:00+0530', tz='UTC+05:30')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)r0   r%   Z	dt_stringr   Zdt_string_reprr  Zdt_timer#   r#   r$   .test_parsers_timezone_minute_offsets_roundtrip8  s
    zJTestDatetimeParsingWrappers.test_parsers_timezone_minute_offsets_roundtripN)r   r   r   rZ   r   r   r   r  r  r  r  r  r   r   r  r#   r#   r#   r$   r  h  s   5
 
D&
r  rA  r	  r  r  r%  c                 C   s   | j S )zIDay and some time units.

    * D
    * s
    * ms
    * us
    * ns
    r   r!   r#   r#   r$   unitsR  s    
r  c                   C   s   t dS )zTimestamp at 1960-01-01.
1960-01-01rH   r#   r#   r#   r$   
epoch_1960_  s    r  c                   C   s   t tdS )NrG   )r  r  r#   r#   r#   r$   units_from_epochse  s    r  	timestamp
pydatetimer&  str_1960c                 C   sL   |j dkst|j dkr| S |j dkr.|  S |j dkr@|  S t| S dS )zxTimestamp at 1960-01-01 in various forms.

    * Timestamp
    * datetime.datetime
    * numpy.datetime64
    * str
    >   r  r  r  r&  r  r  r&  N)r    rB   r   Zto_datetime64rP   )r  r"   r#   r#   r$   epochsj  s    	


r  c                   C   s   t ddd jS )Nr  r   rT  )r   to_julian_dater>   r#   r#   r#   r$   julian_dates~  s    r  c                
   @   s   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zej	
dd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ef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/d0gd.dd0gd1d/d2gd1dd3ggd4d5 ZdS )6
TestOriginc                 C   sH   t dddd}td}||ks"tt dddd}td}||ksDtd S )Nr   r	  r=  originz1970-01-01 00:00:02i ʚ;z2001-09-09 01:46:41rA   )r0   r?  r3   r#   r#   r$   test_origin_and_unit  s    zTestOrigin.test_origin_and_unitc                 C   s>   t t|ddd}t t|td  dd}t|| d S )NrA  julianr  r   r  )r   r   r   r  r.   r=   )r0   r  r2   r3   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   rV   rA  unixr  z
1970-01-01r  r  rf  r~   r#   r#   r$   	test_unix  s
    zTestOrigin.test_unixc              	   C   sN   t dddd}| dkstd}tjt|d t dddd W 5 Q R X d S )NiR|% r  rA  r  r=  z&1 is Out of Bounds for origin='julian'rW   r   )r   r  rB   rZ   r[   r\   )r0   r2   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 )NrA  z$unit must be 'D' for origin='julian'rW   r  r  r  )r0   r  r  r   r#   r#   r$   test_invalid_unit  s    zTestOrigin.test_invalid_unitr=  r%  rA  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 specifiedrW   z
2005-01-01r  r  r  )r0   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   r  r  r#   r$   rL     s     z)TestOrigin.test_epoch.<locals>.<listcomp>r  rl   )r0   r  r  r  r  r3   r2   r#   r  r$   
test_epoch  s
    zTestOrigin.test_epochzorigin, excr  r  z
13-24-1990r   c              	   C   sL   d d| dd| ddg}tj||d t|||d W 5 Q R X d S )Nr   zorigin z is Out of Boundsz# cannot be converted to a Timestampz,Cannot cast .* to unit='ns' without overflowrW   r  )r   rZ   r[   r   )r0   r  excr  r  r   r#   r#   r$   test_invalid_origins  s    


zTestOrigin.test_invalid_originsc              
   C   s:   t jtdd" tddtdddtjdd W 5 Q R X d S )Nzmust be tz-naiverW   r   rA  r   r   r  )rZ   r[   r\   r   r   r   r   r	  r#   r#   r$   test_invalid_origins_tzinfo  s    z&TestOrigin.test_invalid_origins_tzinfoc              	   C   s.   d}t jt|d tddg W 5 Q R X d S )NzIUnknown datetime string format, unable to parse: yesterday, at position 1rW   r#  Z	yesterdayr  rv  r#   r#   r$   test_incorrect_value_exception  s    z)TestOrigin.test_incorrect_value_exceptionzformat, warningN)r   N)r   Nc              	   C   s.   d}t jt|d td|d W 5 Q R X d S )NzG^Out of bounds nanosecond timestamp: 2417-10-10 00:00:00, at position 0rW   z2417-10-10 00:00:00rp   r  )r0   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( r  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 )NrA  r  r  r  r  r  r  rA   )r0   rC   r  Zexpected_strr2   r3   r#   r#   r$   test_processing_order  s    z TestOrigin.test_processing_orderzoffset,utc,expr  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   ry   )r0   r   r   r   rC   r2   r3   r#   r#   r$   test_arg_tz_ns_unit  s    
zTestOrigin.test_arg_tz_ns_unit)r   r   r   r  r  r  r  r  rZ   r   r   r  r  r\   r   r   r  r  r  r  r  r  r  r#   r#   r#   r$   r    sX   

	
	


	r  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   rV   r   r   rG   rV  r  r  r  r   FTc                 C   s    t j|t|dd|kstd S )Ngffffff?)check_countunique_share)r  should_cacher  rB   )r0   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\)\])r   rV   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   r   rW   )rZ   r[   rB   r  r  )r0   r  r  Zerr_messagerC   r#   r#   r$   test_should_cache_errors$  s    
z(TestShouldCache.test_should_cache_errorsr  r  r  c                 C   s   t |dkstd S )NT)r  r  rB   )r0   r  r#   r#   r$   &test_no_slicing_errors_in_should_cache1  s    
z6TestShouldCache.test_no_slicing_errors_in_should_cacheN)r   r   r   rZ   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   rV   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   r3   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 datetimerW   r   )r<   r   rZ   r[   rp  r   r   rB   )Znulls_fixturer  r2   r#   r#   r$   test_na_to_datetimeT  s
    
r   re   r  rj   rc   zargs, formatz
03/24/2016z
03/25/2016r   r6   
2016-03-24
2016-03-25r   r   r   r   c                 C   s8   t |}t||| d}t ddtgdd}t|| d S )Nrs   r  r  r$  r(   )r   r   r   r.   r=   )re   r   r;   r   r2   r3   r#   r#   r$   test_empty_string_datetime`  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	  rj   r  r  r   r$  r(   r  r   r2   r3   r#   r#   r$   'test_empty_string_datetime_coerce__units  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   rV   r   r%  r  r  r  z1970-01-01 00:00:00.000000003r$  rY  )r  Z	DataArrayr   r   r.   r/   )Zxrr1   r2   r3   r#   r#   r$   test_xarray_coerce_unit  s    	r  c                 C   s   t }ttd|dd}|jdddj|dd}|j td	 |_t	|j
d d d
f | d}|j
d d d
f }t|| d S )NZ1980ZYSr  FZDTr  r   )nZrandom_statei  r   r   )r   r   r   Zto_framesampler[  Z	to_seriesr'  rT   r   r  r.   r=   )r%   Zcstarttimesr2   r3   r#   r#   r$   +test_to_datetime_monotonic_increasing_index  s    r  series_lengthr  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:00rj   T)re   r   rc   rB  rW   r  )r   r   fromisoformatr   r   r   r.   r=   rZ   r[   r   )r  r	  r  Z	expected1r}  r  r#   r#   r$   2test_to_datetime_cache_coerce_50_lines_outofbounds  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.%frp   r   rV   r  r   r   r   i  )rQ  rR  rS  rT  rU  r  microsecondZ
nanosecondrA   )r  Ztimestamp_formatr2   r3   r#   r#   r$   %test_to_datetime_format_f_parse_nanos  s    
r  c                  C   s,   t ddgdd} tddg}t| | d S )Nr   z2020-01-01 05:00:00r   rp   rC  r   r  r#   r#   r$   test_to_datetime_mixed_iso8601  s    r  c                  C   s,   t ddgdd} tddg}t| | d S )Nz
01/11/2000z12 January 2000r  rp   z
2000-01-11z
2000-01-12r   r  r#   r#   r$   test_to_datetime_mixed_other  s    r  r   r;   r  c              	   C   s2   d}t jt|d tdg| |d W 5 Q R X d S )Nz8Cannot use 'exact' when 'format' is 'mixed' or 'ISO8601'rW   r   )r   r;   r  )r   r;   r   r#   r#   r$   #test_to_datetime_mixed_or_iso_exact  s    r  c                	   C   s.   t jtdd tddgdd W 5 Q R X d S )Nz9Time data 01-01-2000 is not ISO8601 format, at position 1rW   r   
01-01-2000r   rp   r  r#   r#   r#   r$   4test_to_datetime_mixed_not_necessarily_iso8601_raise  s
     r  )re   r3   rC  r   r  c                 C   s"   t ddgd| d}t|| d S )Nr   r  r   rs   ry   )re   r3   r2   r#   r#   r$   5test_to_datetime_mixed_not_necessarily_iso8601_coerce  s    	r  c                 C   sL   t d tddg|   dd}t|}tddgdd}t|| d S )NZpyarrowr   rV   z	[pyarrow]r(   r$  )rZ   Zimportorskipr   lowerr   r.   r=   )Zany_numeric_ea_dtyperR   r2   r3   r#   r#   r$   test_from_numeric_arrow_dtype  s
    
r  )^__doc__r   collectionsr   r   r   r   r   decimalr   r   Zdateutil.parserr	   Zdateutil.tz.tzr
   numpyr+   rZ   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-  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$   <module>   s   ,
   m            J   iyL k




 (





