o
    %j(@                    @   sT  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 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/Z0 ddl1m2Z2 ddl3m4Z5 ddl6m7Z7 dZ8erdZ9dZ:ndZ9dZ:ej;<dZ=ej>ddgddd Z?G dd dZ@G dd dZAG d d! d!ZBG d"d# d#ZCG d$d% d%ZDG d&d' d'ZEG d(d) d)ZFG d*d+ d+ZGG d,d- d-ZHej>g d.dd/d0 ZIej>d1d2 ZJej>d3d4 ZKej>g d5dd6d7 ZLej>d8d9 ZMG d:d; d;ZNG d<d= d=ZOd>d? ZPej;Qd@ejReSgdAdB ZTej;QdCg dDej;jQdEg dFdGfg dHdIfgdJdKgdLdMdN ZUdOdP ZVej;QdddgdQdR ZWej;QdSdTe7e7dU e7dV gdWdX ZXdYdZ ZYd[d\ ZZd]d^ Z[ej;Qd_ddgej;Qd`dKdagdbdc Z\ddde Z]ej;Qdfdge&dhe(gfdie'djdkgdldmfgdndo Z^dpdq Z_drds Z`dtdu Zadvdw Zbdxdy Zcdzd{ Zdd|Zee*eeZfej;<d}ej;jQd~eee*eegdd dLej;jQdeedd efgdef efjhefjiejefjigdd dLej;Qdddgdd ZkdS )z test to_datetime     N)deque)datedatetime	timedeltatimezone)Decimalparse)tzoffset)tslib)iNaTparsing)PY314)OutOfBoundsDatetimeOutOfBoundsTimedelta)is_datetime64_ns_dtype)		DataFrameDatetimeIndexIndexNaTSeries	Timestamp
date_rangeisnato_datetime)DatetimeArray)	datetimes)start_caching_ata_  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.z, not 99zXday \d{1,2} must be in range 1\.\.\d{1,2} for month \d{1,2} in year \d{4}, at position 0 z,day is out of range for month, at position 0z2ignore:errors='ignore' is deprecated:FutureWarningTF)paramsc                 C      | j S )z/
    cache keyword to pass to to_datetime.
    paramrequest r%   d/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/pandas/tests/tools/test_to_datetime.pycacheM   s   r'   c                   @   sX  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g dg dg dg dg dg dgdd Z	dd Z
dd Zdd Zdd  Zd!d" Zd#d$ Zejd%g d&d'd(ejgd'd(egg d)g d*d+d,ejgd+d,egg d-gd.d/ Zejd0ed'ejd1d2geed'ejejejgged'd1d2ejgeed'ejejejgged3ejd4d5geed6ejejejgged3d4ejd5geed6ejejejgggd7d8 Zejd9ejgd:ed;gfejgd<ed;gfejd=gd:ed;d>gfd?ejgd@edAd;gfd?ejgdBedCd;gfd<ejejgd<eg dDfd<ejejgdEeg dDfgdFdG ZdHdI ZdJdK ZejdLdMedNdOdPgdQedRdSdTgdUdUgdVdVgdWdWgdXdXggdYdZ Zd[d\ Zejd]d^d_ed`gdadbedcgdddeedfgejdgdhediejj e!" dj dkv dlddmdnejdodhedpejj e!" dj dkv dlddmdnejdqdredsejj e!" dj dkv dlddmdngdtdu Z#e$j%dvdw Z&ejddxedydzdSfd{edydSdzfd|edydzdSd}fd~edydSdzd}fdedydzdSd}dfdedydSdzd}dfdedydzdSd}ddfdedydSdzd}ddfdedydzdSd}dddfdedydSdzd}dddfdedydzdSd}dddddfdedydSdzd}dddddfgdd Z'ejdg ddd Z(ejdddedgddedggdd Z)ejdddgd edddgd gddgd ede*e+dddgd gddgd ede*e+dddgd gdddgede,-djdede,-djdgggdd Z.ejddg dedddedddedddggdddgede*e+dddede*e+dddgggdd Z/dd Z0ejdg ddd Z1dd Z2d<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_readonlyV   s   z3TestTimeConversionFormats.test_to_datetime_readonlyzformat, expected%d/%m/%Y200001012000020120000301%m/%d/%Y2000010220000103c                 C   s2   |g d}t |||d}||}t|| d S )N)1/1/20001/2/20001/3/2000formatr'   )r   r0   assert_equal)r2   r'   Zindex_or_seriesrB   r5   valuesr4   r%   r%   r&   test_to_datetime_format`   s   z1TestTimeConversionFormats.test_to_datetime_formatzarg, expected, format)r>   r8   r7   )r>   r8   r;   )r?   r9   r7   )r?   r<   r;   )r@   r:   r7   )r@   r=   r;   c                 C   s&   t |||d}t|}||ksJ d S NrA   r   r   )r2   r'   argr5   rB   r4   r%   r%   r&   test_to_datetime_format_scalars   s   z8TestTimeConversionFormats.test_to_datetime_format_scalarc                 C   sl   t ddgdgd  }t dd |tD }t|d|d}t|| t|td|d}t|| d S )N$.9G.   c                 S      g | ]}t |qS r%   r   .0xr%   r%   r&   
<listcomp>       zNTestTimeConversionFormats.test_to_datetime_format_YYYYMMDD.<locals>.<listcomp>%Y%m%drA   r   applystrr   r0   assert_series_equalr2   r'   serr5   r4   r%   r%   r&    test_to_datetime_format_YYYYMMDD   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 d    d S 1 sXw   Y  d S )NrJ   rK   rL   floatr*   19801222Z19810105   rT   rA   ZnatzOunconverted data remains when parsing with format "%Y%m%d": ".0", at position 0match)r   r   r-   nanr   r0   rX   rV   rW   pytestraises
ValueError)r2   r'   rZ   r5   r4   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 rL   r\   r*   Z19801201Z19810101r^   %Y%mrA   )r   r   r-   ra   r   r0   rX   rY   r%   r%   r&   'test_to_datetime_format_YYYYMM_with_nat   s   

zATestTimeConversionFormats.test_to_datetime_format_YYYYMM_with_natc                 C   s<   t g d}t|dd|d}t g dtd}t|| d S )Ni3iT3irT   ignorerB   errorsr'   r*   )r   r   r/   r0   rX   r2   r'   rZ   r4   r5   r%   r%   r&   'test_to_datetime_format_YYYYMMDD_ignore   s   zATestTimeConversionFormats.test_to_datetime_format_YYYYMMDD_ignorec                 C   s<   t ddtjgdd|d}tddtjgtd}t|| d S )NZ15010101Z20150101rT   ri   rj   r*   )r   r-   ra   r   r/   r0   r1   r2   r'   r4   r5   r%   r%   r&   8test_to_datetime_format_YYYYMMDD_ignore_with_outofbounds   s   
zRTestTimeConversionFormats.test_to_datetime_format_YYYYMMDD_ignore_with_outofboundsc                 C   s<   t g d}t|dd|d}t g ddd}t|| d S )Nrh   rT   coercerj   )Z20121231Z20141231r   M8[ns]r*   r   r   r0   rX   rl   r%   r%   r&   )test_to_datetime_format_YYYYMMDD_coercion   s   zCTestTimeConversionFormats.test_to_datetime_format_YYYYMMDD_coercioninput_s)r]   20010112Nr]   ru   )r]   ru   r   )rJ   T1NrJ   rv   )rJ   rv   r   c                 C   s6   t tdtdtg}t t|dd}t|| d S )Nr]   ru   rT   rB   )r   r   r   r   r0   rX   r2   rt   r5   r4   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 )NrT   rp   rB   rk   )r   r0   rX   rx   r%   r%   r&   )test_to_datetime_format_YYYYMMDD_overflow   s   zCTestTimeConversionFormats.test_to_datetime_format_YYYYMMDD_overflowzdata, format, expectedz%Y%m%d%H%M%Sr   NZ20210202202020z2021-02-02 20:20:20201010z%y%m%dz
2020-10-10z%d%m%y
2010-10-20)r   r   r   rT   c                 C   s   t ||d}t|| d S Nrw   r   r0   r1   )r2   datarB   r5   r4   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 )Nr|   r}   r   )r   pdNAr   r0   r1   r2   r4   r5   r%   r%   r&   %test_to_datetime_with_NA_with_warning  s   z?TestTimeConversionFormats.test_to_datetime_with_NA_with_warningc                 C   s   t g d}t dd |tD }t|d|d}t|| t g d}t dd |tD }t|d|d}t|| d S )	N)    i  c                 S   rM   r%   rN   rO   r%   r%   r&   rR   %  rS   zMTestTimeConversionFormats.test_to_datetime_format_integer.<locals>.<listcomp>z%YrA   )iA i i c                 S   s,   g | ]}t |d d d |dd   qS )N   -rN   rO   r%   r%   r&   rR   +  s   , rf   rU   rY   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J d S )NrT   ri   rz   r   )r2   Zint_dater5   r4   r%   r%   r&   .test_int_to_datetime_format_YYYYMMDD_typeerror0  s   zHTestTimeConversionFormats.test_int_to_datetime_format_YYYYMMDD_typeerrorc                 C   sD   t jd }d| d}d}t|||d}t||}||ks J d S )Nr   z01-z-2011 00:00:01.978z%d-%b-%Y %H:%M:%S.%frA   )calendar
month_abbrr   r   strptime)r2   r'   r   valrB   r4   expr%   r%   r&   #test_to_datetime_format_microsecondF  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J d S rF   r   )r2   r'   valuerB   dtr%   r%   r&   test_to_datetime_format_timeO  s   -z6TestTimeConversionFormats.test_to_datetime_format_timec                 C   sF   t g d}t|dd|d}t|jjdddd|d}t|| d S )N)Z19MAY11Zfoobar19MAY11z19MAY11:00:00:00z19MAY11 00:00:00Zz%d%b%yF)rB   exactr'   z(\d+\w+\d+))expandrA   )r   r   rW   extractr0   rX   rl   r%   r%   r&   test_to_datetime_with_non_exact~  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J d S )Nz 2000-01-03 12:34:56.123456+01:00FrB   r   r   )r2   r'   rB   r5   r4   r%   r%   r&   (test_non_exact_doesnt_parse_whole_string  s   zBTestTimeConversionFormats.test_non_exact_doesnt_parse_whole_stringrH   )z2012-01-01 09:00:00.000000001z2012-01-01 09:00:00.000001z2012-01-01 09:00:00.001z2012-01-01 09:00:00.001000z2012-01-01 09:00:00.001000000c                 C   s*   t ||d}t |d|d}||ksJ d S )Nr'   r   rA   r   )r2   r'   rH   r5   r4   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J d S rF   r   )r2   r   fmtr5   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 %Z2010-01-01 12:00:00 UTCr^   2010-01-01 12:00:00UTC%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 Zc                 C   s$   t ||d}t|}t|| d S r~   )r   r   r0   rC   )r2   r   datesexpected_datesr4   r5   r%   r%   r&   )test_to_datetime_parse_tzname_or_tzoffset  s   *zCTestTimeConversionFormats.test_to_datetime_parse_tzname_or_tzoffset)r   z2010-01-01 12:00:00 GMTz2010-01-01 12:00:00 US/PacificGMT
US/Pacific2010-01-01 12:00:00 -0100c                 C   sV   d}t jt|d t||d}W d    n1 sw   Y  t|}t || d S )N;parsing datetimes with mixed time zones will raise an errorr_   rw   )r0   assert_produces_warningFutureWarningr   r   rC   )r2   r   r   r   msgr4   r5   r%   r%   r&   >test_to_datetime_parse_tzname_or_tzoffset_utc_false_deprecated  s   "zXTestTimeConversionFormats.test_to_datetime_parse_tzname_or_tzoffset_utc_false_deprecatedc                 C   s:   g d}g d}d}t ||dd}t|}t|| d S )N)r   r   z2010-01-01 12:00:00 +0300z2010-01-01 12:00:00 +0400)z2010-01-01 11:00:00+00:00z2010-01-01 13:00:00+00:00z2010-01-01 09:00:00+00:00z2010-01-01 08:00:00+00:00r   TrB   utcr   r   r0   r1   )r2   r   r   r   r4   r5   r%   r%   r&   =test_to_datetime_parse_tzname_or_tzoffset_different_tz_to_utc  s   zWTestTimeConversionFormats.test_to_datetime_parse_tzname_or_tzoffset_different_tz_to_utcoffset)z+0z-1fooZUTCbarz:10z
+01:000:01r   c                 C   sl   d}d| }d dt ddt dg}tjt|d t|g|d W d    d S 1 s/w   Y  d S )	Nr   z2010-01-01 12:00:00 |z;^time data ".*" doesn\'t match format ".*", at position 0. $N^unconverted data remains when parsing with format ".*": ".*", at position 0. r_   rw   joinPARSING_ERR_MSGrb   rc   rd   r   )r2   r   r   r   r   r%   r%   r&   )test_to_datetime_parse_timezone_malformed0  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namerw   r   r   )r   r   )r   r   r   r0   r1   )r2   r   rH   r4   r5   r%   r%   r&   *test_to_datetime_parse_timezone_keeps_nameB  s
   zDTestTimeConversionFormats.test_to_datetime_parse_timezone_keeps_name)3__name__
__module____qualname__rb   markparametrizer6   r   rE   rI   r[   re   rg   rm   ro   rs   r-   ra   r   ry   r   r{   r   r   r   r   r   r   r   r   r   r"   xfaillocale	getlocaler   tdskip_if_not_us_localer   r   r   r   r   r   pytzFixedOffsetr   r   r   r   r   r%   r%   r%   r&   r(   U   s   
	









	


,






(





r(   c                   @   s8
  e Zd Zejddd Z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d d!gddd%dgej	d&ed'd( gd)d* Zejj	dddgddgdej	d&ed+d( gd,d- Zej	d.ejdeed/d0d1ed2d3d1egd4dejdeed/d0d1ed5d3d1egd6dgd7d8 Zej	d.ejdeg d9ddd:dejdeg d;dd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dAdgej	d&edBd( gdCdD ZdEdF Zej	dGdHdIedJdKdLdMdMgdNdIedOdPdPdMdMgdQdIedOdPdRdMdMggdSdT Zej	dUg dVg dWg dXg dYg dZg d[g d\g d]g d^g d_g d`g dag dbg dcg ddg deg dfg dgg dhgej	dig djdkdl Zej	dmdndogdpdq Zejej	dreegej	dsddgej	dmdndogdtdu Zdvdw Zdxdy Zdzd{ Z ejd|d} Z!ejej	dmd~dgdd Z"ej	dddgdd Z#ej	dg d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	dig ddd Z)ejj*dd Z+ej	dddgdd Z,dd Z-dd Z.dd Z/dd Z0dd Z1dd Z2ej	deefe3efe%j4efeefgdd Z5ej	ddeddsd1gdeddsd1ggdd Z6dd Z7dd Z8ej	dddgdd Z9ddĄ Z:ej	dddgddƄ Z;ddȄ Z<ej	de=e>gddʄ Z?ej	dig dˢdd̈́ Z@ej	dddgej	ddndgddӄ ZAej	ddgej	ddndgddք ZBej	ddgdgg dآgej	ddndgddڄ ZCej	dsddngej	dddngej	d&e3eDe%j4eeEgdd݄ ZFdd߄ ZGej	dsddngej	dddngdd ZHdd ZIej	ddne%jJfefeK  efeKd  fdnedfefeK  eedfefeK  fdefeK  dedf efeKdP  ededf ffdd ZLej	dddgej	deegd dngd  ddeegd dngd  ddedngd edngd edgd edgd eeMjNgd eeMjNgd ee%jJgd ee%jJgd g
dd ZOej	dg ddd ZPdd ZQej	dddgej	deddPdPeRddPdPe%&dddgd d ZSej	ddeeegfdeddgeTdfgdd ZUd	d
 ZVdd ZWdd ZXdd ZYdd ZZdd Z[ej	dededdd1feddd1eddd1fgdd Z\ej	dg ddd Z]d d! Z^d"d# Z_ej	d$d%d&gd%eddd1gd%ed'dPdPd(e`ad)d*ggd+d, ZbdnS (-  TestToDatetimezignore:Could not infer formatc                 C   s   d}d}t jt|d t| W d    n1 sw   Y  t jt|d t|g W d    n1 s6w   Y  t|dd}|tu sGJ t|gdd}t|ttg t|dd}t|t	rf||kshJ t|gdd}t|t|gt
d d S )NZ08335394550z:Parsing "08335394550" to datetime overflows, at position 0r_   rp   rk   ri   r*   )rb   rc   r   r   r   r0   r1   r   
isinstancerW   r/   )r2   rH   r   resr%   r%   r&   test_to_datetime_overflowL  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_convertr0   r1   )r2   d1Zd2r   r5   r%   r%   r&   *test_to_datetime_mixed_datetime_and_stringc  s
   z9TestToDatetime.test_to_datetime_mixed_datetime_and_stringc                 C   s   ddg}t dd |D }t|dd}t|d d d ddd d d }t |}t |d d d d d d }t|| t|| t|| t|| d S )Nz
2016-01-01r   c                 S   rM   r%   rN   rO   r%   r%   r&   rR   n  rS   zLTestToDatetime.test_to_datetime_mixed_string_and_numeric.<locals>.<listcomp>mixedrw   )r   r   r0   r1   )r2   valsr5   r4   result2result3result4r%   r%   r&   )test_to_datetime_mixed_string_and_numerick  s    z8TestToDatetime.test_to_datetime_mixed_string_and_numericrB   r   r   ISO8601non-ISO8601Zidsc                 C   s<   t ddd}td|g|d}tddgdd}t|| d S )	Nr   r   r^   
2020-01-01rw   z
2020-01-02rq   r*   )r   r   r   r0   r1   )r2   rB   r   r   r5   r%   r%   r&   &test_to_datetime_mixed_date_and_stringy  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:002000-01-01 02:00:00+00:00zall tz-aware, without utcz%all tz-aware, mixed offsets, with utc2000-01-01 01:00:00z+tz-aware string, naive pydatetime, with utcconstructorc                 C      t |  S Nr   to_pydatetimerQ   r%   r%   r&   <lambda>      zTestToDatetime.<lambda>c           	      C   s6   ||d }|d }t ||g||d}t|| d S )Nr   r   r   r   )	r2   r   r   argsr5   r	  ts1ts2r4   r%   r%   r&   6test_to_datetime_mixed_datetime_and_string_with_format  s   8zETestToDatetime.test_to_datetime_mixed_datetime_and_string_with_formatc                 C   r
  r  r  r  r%   r%   r&   r    r  c           	      C   s   ddg}||d }|d }d}t tdtdddg}tjt|d	 t||g|d
d}W d    n1 s7w   Y  t|| d S )Nr  r  r   r   r   z2000-01-01 02:00:00+0000r   r   r_   Fr   )r   r   r0   r   r   r   r1   )	r2   r   r	  r  r  r  r   r5   r4   r%   r%   r&   Ntest_to_datetime_mixed_datetime_and_string_with_format_mixed_offsets_utc_false  s   
z]TestToDatetime.test_to_datetime_mixed_datetime_and_string_with_format_mixed_offsets_utc_falsezfmt, expectedz2000-01-01 09:00:00+0100r   r   z2000-01-02 02:00:00+0200z	UTC+02:00zISO8601, non-UTCz2000-02-01 02:00:00+0200znon-ISO8601, non-UTCc                 C   sT   d}t jt|d tg d|dd}W d    n1 sw   Y  t || d S )Nr   r_   z2000-01-01 09:00:00+01:00z2000-01-02 02:00:00+02:00NFr   r0   r   r   r   r1   )r2   r   r5   r   r4   r%   r%   r&   +test_to_datetime_mixed_offsets_with_none_tz  s   z:TestToDatetime.test_to_datetime_mixed_offsets_with_none_tz)2000-01-01 08:00:00+00:00z2000-01-02 00:00:00+00:00r   zISO8601, UTC)r  z2000-02-01 00:00:00+00:00r   znon-ISO8601, UTCc                 C   s"   t g d|dd}t|| d S )Nr  Tr   r   )r2   r   r5   r4   r%   r%   r&   (test_to_datetime_mixed_offsets_with_none  s   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   r
  r  r  r  r%   r%   r&   r  4  r  c                 C   s^   ||d }||d }t jtdd t||g|dd W d    d S 1 s(w   Y  d S )Nr   r   z1cannot be converted to datetime64 unless utc=Truer_   Fr   rb   rc   rd   r   )r2   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sJ t|jd |ks#J t|g}t|g}t|| t|}t|}t	|| d S )Nz2019-02-04 10:18:46.297000+0000z2019-02-04 10:18:46.297000r   r   r   )
r-   Zstr_r   r   r   ilocr   r0   r1   rX   )r2   r   rZ   r   r   r5   r%   r%   r&   test_to_datetime_np_strC  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
J d S r~   r   )r2   s_formatr   r%   r%   r&   %test_to_datetime_iso_week_year_formatW  s   
z4TestToDatetime.test_to_datetime_iso_week_year_formatzmsg, s, _format)dISO week directive '%V' is incompatible with the year directive '%Y'. Use the ISO year '%G' instead.1999 50z%Y %V)xISO year directive '%G' must be used with the ISO week directive '%V' and a weekday directive '%A', '%a', '%w', or '%u'.z1999 51z%G %V)r'  z1999 Mondayz%G %A)r'  z1999 Monz%G %a)r'  1999 6z%G %w)r'  r(  z%G %u)r'  Z2051z%G)`Day of the year directive '%j' is not compatible with ISO year directive '%G'. Use '%Y' instead.z1999 51 6 256z%G %V %u %j)r%  1999 51 Sundayz%Y %V %A)r%  1999 51 Sunz%Y %V %a)r%  	1999 51 1z%Y %V %w)r%  r,  z%Y %V %u)xISO week directive '%V' must be used with the ISO year directive '%G' and a weekday directive '%A', '%a', '%w', or '%u'.Z20z%V)r-  r*  %V %A)r-  r+  z%V %a)r-  r,  z%V %w)r-  r,  z%V %u)r)  r&  z%G %j)r-  z	20 Mondayr.  rk   raiserp   ri   c                 C   sb   t  dkr-t  dkr/tjt|d t|||d W d    d S 1 s&w   Y  d S d S d S )N)r   UTF-8)r   r1  r_   rz   )r   r   rb   rc   rd   r   )r2   r   r"  r#  rk   r%   r%   r&   test_error_iso_week_yearc  s    "z'TestToDatetime.test_error_iso_week_yearr   Nz
US/Centralc                 C   s.   t ddd|d}|j}t|}||u sJ d S )N
1965-04-03   2Wperiodsfreqr   )r   _datar   )r2   r   dtir3   r4   r%   r%   r&   test_to_datetime_dtarr  s   z%TestToDatetime.test_to_datetime_dtarr	arg_classr   c           	      C   s   t d}tddd|d}||}|t|jd|d}t||d}t||dt|jd|s3|nd	d}|sE|turE||u sEJ |tu rQt	
|| d S t	|| d S )
Npyarrowr3  r4  r5  r6  ns)unitr   r   r   )rb   importorskipr   astyper   Z
ArrowDtype	timestampr   r   r0   rX   r1   )	r2   r   r   r<  par:  Z	dti_arrowr4   r5   r%   r%   r&   test_to_datetime_arrow  s   
z%TestToDatetime.test_to_datetime_arrowc                 C   s(   t tddd}|tdddksJ d S )N  r      r   r   r2   actualr%   r%   r&   test_to_datetime_pydatetime  s   z*TestToDatetime.test_to_datetime_pydatetimec                 C   s    t d}|tdddksJ d S )NZ20080115rF  r   rG  rH  rI  r%   r%   r&   test_to_datetime_YYYYMMDD  s   z(TestToDatetime.test_to_datetime_YYYYMMDDc                 C   s   d}t |dd|ksJ d S )NzMonth 1, 1999ri   r   r   )r2   rZ   r%   r%   r&   "test_to_datetime_unparsable_ignore  s   z1TestToDatetime.test_to_datetime_unparsable_ignorec                 C   s   t dA tdd}td}tdgd }t|j|j dk s$J t|j|j dk s0J |jd u s7J |jd u s>J W d    d S 1 sIw   Y  d S )N
US/Easternnowr>  r       _B)r0   set_timezoner   as_unitr   abs_valuer   )r2   rO  ZpdnowZpdnow2r%   r%   r&   test_to_datetime_now  s   "z#TestToDatetime.test_to_datetime_nowzPacific/AucklandzUS/Samoac                 C   s   t |n tddtj}td}tdgd }tdd}t	 d}t
| j| dk s8J t
| j| dk sEJ t
|j|j dk sQJ t
|j|j dk s]J |jd u sdJ |jd u skJ W d    d S 1 svw   Y  d S )Ntodaydatetime64[ns]r   r>  rP  )r0   rQ  r-   
datetime64rB  int64r   r   rR  rV  rS  	normalizerT  r   )r2   r   ZnptodayZpdtodayZpdtoday2ZtstodayZtstoday2r%   r%   r&   test_to_datetime_today+  s   	"z%TestToDatetime.test_to_datetime_todayrH   rO  rV  c                 C   s   t |g d S r  r   )r2   rH   r%   r%   r&   (test_to_datetime_today_now_unicode_bytesF  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)rO  utcnow)rV  rV  c                 C   sF   t d|g|dd}t|tt| gdd}||   dk s!J d S )Nz2020-01-03 00:00:00ZTr   r  r*   r   )r   r   getattrr   maxtotal_seconds)r2   rB   Zexpected_dsstring	attributer4   r5   r%   r%   r&    test_to_datetime_now_with_formatJ  s
   z/TestToDatetime.test_to_datetime_now_with_formatr   
2000-01-01
2000-01-02c                 C   s   t ||dt|ksJ d S )Nr   rG   )r2   r'   r   r%   r%   r&   test_to_datetime_dt64sa  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  rw   ri  )r   r-   rX  r   r0   r1   )r2   rH   rB   r4   r5   r%   r%   r&   test_to_datetime_dt64s_and_strg  s   	z-TestToDatetime.test_to_datetime_dt64s_and_strz
1000-01-01z
5000-01-02)r0  ri   rp   c                 C   s`   t |||d}t|tsJ |jdksJ |j|ksJ t|}|jdks'J |j|ks.J d S )Nrk   r'   r"  )r   r   r   r?  asm8)r2   r'   r   rk   tsr%   r%   r&   'test_to_datetime_dt64s_out_of_ns_boundst  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 d    n1 s#w   Y  tjt|d t	|d|d W d    n1 sAw   Y  t	|d|dt
u sQJ d S )NDz7Out of bounds second timestamp: 25252734927768524-07-27r_   r0  rk  rp   )r-   rX  ZiinforY  r`  rb   rc   r   r   r   r   )r2   r'   Zdt64r   r%   r%   r&   $test_to_datetime_dt64d_out_of_bounds  s   
z3TestToDatetime.test_to_datetime_dt64d_out_of_boundsr?  r"  ro  c                 C   s  t d|t d|gd }t||d}|r"tdd |D dd}ntd	d |D d
d}t|| |t dg }t|dd t|d|d}|s`tt|d jt|d jgd tg }n	tt j	|dd}t|| t|d|d}|s|t
|}t|| d S )Nre  rf  r   r   c                 S      g | ]}t |jqS r%   r   rl  rO   r%   r%   r&   rR         zBTestToDatetime.test_to_datetime_array_of_dt64s.<locals>.<listcomp>zM8[s]r*   c                 S   rq  r%   rr  rO   r%   r%   r&   rR     rs  rq   
9999-01-01r0  r   rp   rk  r   r   ri   )r-   rX  r   r   r0   r1   r   rl  r   r.   r   )r2   r'   r?  dtsr4   r5   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J d S )Nrt  ri   r   )r   r-   rX  r   r%   r%   r&    test_out_of_bounds_errors_ignore  s   
z/TestToDatetime.test_out_of_bounds_errors_ignorec                 C   sf   d}t jt|d ttdtjgdd}W d    n1 sw   Y  tdtjg}t || d S )Nerrors='ignore' is deprecatedr_   z
2362-01-01ri   r   )r0   r   r   r   r   r-   ra   rX   )r2   r   r   r   r%   r%   r&   !test_out_of_bounds_errors_ignore2  s   z0TestToDatetime.test_out_of_bounds_errors_ignore2c                 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   r0   r1   )r2   r'   r3   r4   r5   r%   r%   r&   test_to_datetime_tz  s   

z"TestToDatetime.test_to_datetime_tzc                 C   s   t dddt dddg}d}tjt|d t||d W d    n1 s&w   Y  d	}tjt|d t||d
d}W d    n1 sFw   Y  tt dt dgdd}t	|| t||dd}t
ddgdd}t	|| d S )Nrz  r   r   r{  rN  zLTz-aware datetime.datetime cannot be converted to datetime64 unless utc=Truer_   r   rx  ri   )r'   rk   z2013-01-01 13:00:00-08:00z2013-01-02 14:00:00-05:00r/   r*   rp   r   zdatetime64[ns, US/Pacific])r   rb   rc   rd   r   r0   r   r   r   r1   r   )r2   r'   r3   r   depr_msgr4   r5   r%   r%   r&   test_to_datetime_tz_mixed  s0   

z(TestToDatetime.test_to_datetime_tz_mixedc                 C   s|   d}d}|gd |gd  }t dd |D }d}tjt|d t||d}W d    n1 s1w   Y  t|| d S )	NMarch 1, 2018 12:00:00+0400March 1, 2018 12:00:00+0500rL   c                 S   rM   r%   r   rO   r%   r%   r&   rR     rS   zETestToDatetime.test_to_datetime_different_offsets.<locals>.<listcomp>r   r_   r   )r   r0   r   r   r   r1   )r2   r'   Zts_string_1Zts_string_2r3   r5   r   r4   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 )NrN  r   r   r   r   )yearmonthdayhourminute   r*   Tr   r'   r  2000-06-01 07:00:00+00:00r  r+   r8  )r   r   r-   r.   localizer   r/   r   r   r0   r1   )r2   r'   Z
us_easternr3   r4   r5   r%   r%   r&   test_to_datetime_tz_pytz  s$   
z'TestToDatetime.test_to_datetime_tz_pytzz!init_constructor, end_constructorc                 C   sL   ddg}t dddt dddg}t||dd|d	}||}t|| d S )
N20100102 12131420100102 1213152010-01-02 12:13:14r   r   2010-01-02 12:13:15%Y%m%d %H%M%STrB   r   r'   )r   r   r0   rC   )r2   r'   Zinit_constructorZend_constructorr   Zexpected_datar4   r5   r%   r%   r&   test_to_datetime_utc_true  s   

z(TestToDatetime.test_to_datetime_utc_truezscalar, expectedr  r  r  r  c                 C   s    t |dd|d}||ksJ d S )Nr  Tr  r   )r2   r'   scalarr5   r4   r%   r%   r&    test_to_datetime_utc_true_scalar/  s   	z/TestToDatetime.test_to_datetime_utc_true_scalarc                 C   s:   d}t t|gd|d}tt|ddg}t|| d S )Ng {ѴCTr  r   r   )r   r   r   r0   rX   )r2   r'   rm  r4   r5   r%   r%   r&   2test_to_datetime_utc_true_with_series_single_value;  s   zATestToDatetime.test_to_datetime_utc_true_with_series_single_valuec                 C   sJ   d}d}t |gd }t|d|d}t t|ddgd }t|| d S )Nz2013-01-01 00:00:00-01:002013-01-01 01:00:00r   Tr  r   r   r   r   r   r0   rX   )r2   r'   rm  Zexpected_tsr   r4   r5   r%   r%   r&   4test_to_datetime_utc_true_with_series_tzaware_stringB  s   zCTestToDatetime.test_to_datetime_utc_true_with_series_tzaware_stringzdate, dtype)r  rW  )r  r  c                 C   s>   t tdddgdd}tt |g|dd|d}t|| d S )Nr  r   r   M8[ns, UTC]r*   Tr  r   r   r   r0   rX   )r2   r'   r   r+   r5   r4   r%   r%   r&   1test_to_datetime_utc_true_with_series_datetime_nsJ  s
   z@TestToDatetime.test_to_datetime_utc_true_with_series_datetime_nsc           
   
   C   s   t d}|jdd d}|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dd dd}	t|	sUJ t|	d|d}t	
||	 t|	dd|d}tdgdd}t	
|| d S )Nzpsycopg2.tzi)r   r   ir   r   r   r   r   r  r*   rp   T)rk   r   r'   r  r  r  r  z2000-01-01 08:00:00r   rk  z2000-01-01 13:00:00)rb   rA  ZFixedOffsetTimezoner-   r.   r   r/   r   r   r0   r1   r   )
r2   r$   r'   Zpsycopg2_tzZtz1Ztz2r3   r4   r5   ir%   r%   r&   test_to_datetime_tz_psycopg2X  s4   
z+TestToDatetime.test_to_datetime_tz_psycopg2c                 C   sj   d}t jt|d t| W d    n1 sw   Y  t|d|dtu s(J t|d|d|u s3J d S )Nz2dtype bool cannot be converted to datetime64\[ns\]r_   rp   rk  ri   )rb   rc   	TypeErrorr   r   )r2   r'   rH   r   r%   r%   r&   test_datetime_bool~  s   
z!TestToDatetime.test_datetime_boolc                 C   s   t | d}tjt|d tdt g|d W d    n1 s#w   Y  tjtdt dd tddg|d W d    n1 sFw   Y  t	
td	dtd
gd|dttd	|dtttd	|dg d S )Nz is not convertible to datetimer_   Fr   zA^time data "True" doesn\'t match format "%Y%m%d", at position 1. r   20130101Tr   g        rp   rk  )typerb   rc   r  r   r   rV  rd   r   r0   r1   r   r   r2   r'   r   r%   r%   r&   test_datetime_bool_arrays_mixed  s$   z.TestToDatetime.test_datetime_bool_arrays_mixedc                 C   s@   d}t jt|d t| W d    d S 1 sw   Y  d S )Nzis not convertible to datetimer_   )rb   rc   r  r   )r2   rH   r   r%   r%   r&   test_datetime_invalid_datatype  s   
"z-TestToDatetime.test_datetime_invalid_datatype)rp   r0  ri   c                 C   sD   t jtdd tdgd|d W d    d S 1 sw   Y  d S )Nz*':' is a bad directive in format 'H%:M%:S%r_   z00:00:00zH%:M%:S%rz   r  )r2   rk   r%   r%   r&   test_invalid_format_raises  s
   "z)TestToDatetime.test_invalid_format_raisesr   az00:01:99z%H:%M:%Sc                 C   s   t |d|d}||ksJ t |d|d}|tu sJ ddt dddt dd	t d
g}tjt|d t |d|d W d    d S 1 sIw   Y  d S )Nri   rk   rB   rp   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. ^second must be in 0..59: 00:01:99, at position 0$r_   r0  )r   r   r   r   NOT_99rb   rc   rd   r2   r   rB   r   r   r%   r%   r&   test_datetime_invalid_scalar  s$   

"z+TestToDatetime.test_datetime_invalid_scalarz3000/12/11 00:00:00c                 C   s   t |d|d}||ksJ t |d|d}|tu sJ |d urAd}tjt|d t |d|d W d    d S 1 s:w   Y  d S d}tjt|d t |d|d W d    d S 1 s]w   Y  d S )Nri   r  rp   z:^time data ".*" doesn\'t match format ".*", at position 0.r_   r0  z!^Out of bounds .*, at position 0$)r   r   rb   rc   rd   r   r  r%   r%   r&    test_datetime_outofbounds_scalar  s   ""z/TestToDatetime.test_datetime_outofbounds_scalarrD   )r  bz99:00:00c              	   C   s  |d u rt |dkrt}nd }tj|ddd t|d|d}W d    n1 s)w   Y  t|t||d u r9dndd	 tj|ddd t|d
|d}W d    n1 sXw   Y  t|ttgt |  d	ddt
 ddt
 ddt dg}tjt|d0 tj|ddd t|d|d W d    n1 sw   Y  W d    d S W d    d S 1 sw   Y  d S )Nr   Could not infer formatFr`   Zraise_on_extra_warningsri   r  r/   rW   r*   rp   r   r  r  r   r  r  r  r_   r0  )lenUserWarningr0   r   r   r1   r   r   r   r   r   r  rb   rc   rd   )r2   rD   rB   warnr   r   r%   r%   r&   test_datetime_invalid_index  sJ   

"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   rB   r'   Fr   )	r2   r   rB   r	  r   
test_datesr   r4   r5   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   r0   r1   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  rr   )r2   r   rB   r   r  r   r4   r5   r%   r%   r&   test_to_datetime_cache_series  s   
z,TestToDatetime.test_to_datetime_cache_seriesc                 C   s(   d}t |dd}td}||ksJ d S )Nr  Tr   rG   )r2   r   r4   r5   r%   r%   r&   test_to_datetime_cache_scalar  s   z,TestToDatetime.test_to_datetime_cache_scalarzdatetimelikes,expected_valuesr^   z
2012-07-26r  z2012 July 26c                 C   s4   t |dd}t|dd}t |dd}t|| d S )Nr/   r*   rp   r   rW  rr   )r2   ZdatetimelikesZexpected_valuesrZ   Zresult_seriesZexpected_seriesr%   r%   r&   *test_convert_object_to_datetime_with_cache   s   z9TestToDatetime.test_convert_object_to_datetime_with_cacher'   input   r/   r   r   c                 C   s2   t tgt| dd}t||d}t|| d S )Nrq   r*   r   )r   r   r  r   r0   rX   )r2   r'   r  r5   r4   r%   r%   r&   *test_to_datetime_converts_null_like_to_natC  s   z9TestToDatetime.test_to_datetime_converts_null_like_to_natzdate, format))z2017-20z%Y-%W)	20 Sundayz%W %A)20 Sunz%W %a)z2017-21z%Y-%U)r  z%U %A)r  z%U %ac                 C   sD   d}t jt|d t||d W d    d S 1 sw   Y  d S )Nz,Cannot use '%W' or '%U' without day and yearr_   rw   r  )r2   r   rB   r   r%   r%   r&   'test_week_without_day_and_calendar_yearY  s   "z6TestToDatetime.test_week_without_day_and_calendar_yearc                 C   s   g d}d}t jt|d t|dd}W d    n1 sw   Y  ttdddd	d
td ddtdddd	d
td ddtg}t || d S )N)r  r  Z20100240r   r_   rp   r     r   r   r   r   i@8  r   iPF  )	r0   r   r   r   r   r   r
   r   r1   r2   
ts_stringsr   r4   r5   r%   r%   r&   test_to_datetime_coercek  s   z&TestToDatetime.test_to_datetime_coercezstring_arg, format)zMarch 1, 2018z	%B %d, %Y)z
2018-03-01r   outofboundsi'  rt  zJanuary 1, 9999c                 C   s:   ||g}t |d|d}ttdddtg}t|| d S )Nrp   r  r  r   r   )r   r   r   r   r0   r1   )r2   Z
string_argrB   r  r  r4   r5   r%   r%   r&   test_to_datetime_coerce_oob~  s   z*TestToDatetime.test_to_datetime_coerce_oobzerrors, expectedrp   ri   200622-12-31111111-24-11c                 C   sT   ddg}t jtddd t||d}W d    n1 sw   Y  t || d S )Nr  r  r  Fr  r   )r0   r   r  r   r1   )r2   rk   r5   r  r4   r%   r%   r&   #test_to_datetime_malformed_no_raise  s   
z2TestToDatetime.test_to_datetime_malformed_no_raisec              	   C   s   ddg}d}t jt|d. tjtdd t|dd W d    n1 s&w   Y  W d    d S W d    d S 1 s>w   Y  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 0r_   r  r0  r   rb   rc   rd   r0   r   r  r   )r2   r  r   r%   r%   r&    test_to_datetime_malformed_raise  s$   "z/TestToDatetime.test_to_datetime_malformed_raisec                 C   sj   d}t |}t|}||ksJ tt|gd }t |gd }t|| t|gd }t|| d S )N2015-11-18 15:30:00+05:30r^   )r   r   r   r0   r1   )r2   Zts_strr4   r5   r%   r%   r&   &test_iso_8601_strings_with_same_offset  s   z5TestToDatetime.test_iso_8601_strings_with_same_offsetc                 C   s   ddt g}d}tjt|d t|}W d    n1 sw   Y  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   rG  r   iXM  r      ih[  r*   )r   r0   r   r   r   r-   r.   r   r
   r/   r   r1   r  r%   r%   r&   ,test_iso_8601_strings_with_different_offsets  s   

	z;TestToDatetime.test_iso_8601_strings_with_different_offsetsc                 C   sL   ddt g}t|dd}ttddddtddddt gd	d
}t|| d S )Nr  r  Tr@  r!  r  r   r   r   r   )r   r   r   r   r0   r1   )r2   r  r4   r5   r%   r%   r&   0test_iso_8601_strings_with_different_offsets_utc  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 s!J t d}t d}d	}tjt|d
 t }W d    n1 sAw   Y  tdt dt d	 t d	 d gt
d}t|d d | ||jd   dksrJ ||jd   dksJ tjtdd
 t| W d    d S 1 sw   Y  d S )Nra   z
1990-01-01z2015-03-14T16:15:14.123-08:00z2019-03-04T21:56:32.620-07:00rV  rO  c                 3   s     | ]} | | u V  qd S r  r%   )rP   r  rZ   r   r%   r&   	<genexpr>  s    zPTestToDatetime.test_mixed_offsets_with_native_datetime_raises.<locals>.<genexpr>r   r_   r   r*   r   g?zTz-aware datetime.datetime)r   r   allranger  r0   r   r   r   r  r/   rX   r  ra  rb   rc   rd   )r2   rO  rV  r   r   r5   r%   r  r&   .test_mixed_offsets_with_native_datetime_raises  s>   	$




"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 )
Nr  r^   r  r   r   r      r   r   )r   r   r   r   r   r0   r1   r   r%   r%   r&   #test_non_iso_strings_with_tz_offset  s
    z2TestToDatetime.test_non_iso_strings_with_tz_offsetzts, expectedz
2018-01-01r   r   z2018-01-01 08:00c                 C   s   t |dd}||ksJ d S )NTr@  r   )r2   rm  r5   r4   r%   r%   r&   test_timestamp_utc_true  s   z&TestToDatetime.test_timestamp_utc_truedt_str)Z00010101Z13000101Z30000101Z99990101c                 C   D   d}t jt|d t|dd W d    d S 1 sw   Y  d S )N"Out of bounds nanosecond timestampr_   rT   rw   rb   rc   r   r   )r2   r  r   r%   r%   r&   *test_to_datetime_with_format_out_of_bounds  s   "z9TestToDatetime.test_to_datetime_with_format_out_of_boundsc                 C   s4   t jtdgtd}t|dd}|jtju sJ d S )Nz2012-06-13T01:39:00Zr*   Tr@  )r-   r.   r	   r/   r   r   r   r   )r2   r3   r4   r%   r%   r&   test_to_datetime_utc$  s   z#TestToDatetime.test_to_datetime_utcc                 C   s^   ddl m} |dd}tddd|dtddd|dtddd	|dg}t|}|j|ks-J d S )
Nr   )r   i\z-07:00r   r   r   r^   r   )Z-pandas.tests.indexes.datetimes.test_timezonesr   r   r   r   )r2   r   Z	fixed_offr   r4   r%   r%   r&   test_to_datetime_fixed_offset*  s   
z,TestToDatetime.test_to_datetime_fixed_offsetr   z2020-10-26 00:00:00+06:00z2020-10-26 00:00:00+01:00r   r   zAustralia/Melbourner   c                 C   r  )Nr   r_   Fr@  r0   r   r   r   )r2   r   r   r%   r%   r&   8test_to_datetime_mixed_offsets_with_utc_false_deprecated7  s   "zGTestToDatetime.test_to_datetime_mixed_offsets_with_utc_false_deprecated)cr   r   r   rb   r   filterwarningsr   r   r   r   r  r"   r   r   r  r  r   r   r  r  r  r  r   r$  r2  r;  r   Zskip_if_windowsr   rE  rK  rL  rM  rU  r[  r\  rd  r-   rX  rg  rj  rn  Z
skip_ubsanrp  rv  rw  ry  r}  r  r  r  listr.   r  r  r  r  r  r  r  r  boolr   r  r  r  r  r  tupler   r  r  r  r  ra   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   K  s   


		(







		

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dd Zejdg ddd Zejdg dejdddgdd Zejdg d g d!egg d"g d#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/d0 Zd1d2 Zejdeegd3d4 Zejd5eejgd6d7 Zd8d9 Zd:d; Zejd<d=d>gd?d@ Zejd<d=d>gdAdB Z dCdD Z!d$S )ETestToDatetimeUnitr?  YMitem   c                 C   s   t ||d}t|gdd}t|g||d}t|| ttj|gtd||d}t|| tt|g||d}t|| tt|tjg||d}|	 d sTJ t|d d | d S )Nr?  rq   r*   r?  r'   r   )
r   r   r   r0   r1   r-   r.   r/   ra   r   )r2   r'   r?  r  r$   rm  r5   r4   r%   r%   r&   'test_to_datetime_month_or_year_unit_intJ  s   z:TestToDatetimeUnit.test_to_datetime_month_or_year_unit_intc              	   C   s  d}d| d}t jt|d tdg|dd W d    n1 s"w   Y  t jt|d ttdg|dd W d    n1 sDw   Y  t jt|d' tjt|d tdg|dd W d    n1 skw   Y  W d    n1 szw   Y  t jt|d tdg|d	d W d    n1 sw   Y  tdg|d
d}t	t
gdd}t|| tjt|d tdg|d
d}W d    n1 sw   Y  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 ambiguousr_         ?r0  r?  rk   z1.5ri   rp   rq   r*         ?r  r   )rb   rc   rd   r   r-   r.   r0   r   r   r   r   r1   )r2   r'   r?  Zwarn_msgr   r   r5   r%   r%   r&   3test_to_datetime_month_or_year_unit_non_round_float_  s6   zFTestToDatetimeUnit.test_to_datetime_month_or_year_unit_non_round_floatc                 C   sJ   d}t jt|d tdgdd|d W d    d S 1 sw   Y  d S )Nz#cannot specify both format and unitr_   r   ro  rT   )r?  rB   r'   r  r  r%   r%   r&   	test_unit  s   "zTestToDatetimeUnit.test_unitc                 C   sZ   t t tdgddd}W d    n1 sw   Y  tdgddd}t || d S )NZ
1704660000r"  unixr?  origini er  )r2   r'   r   r5   r%   r%   r&   test_unit_str  s
   z TestToDatetimeUnit.test_unit_strc              	   C   s   dddt ttjddg}t|dd|d}tdtd	td	tttttgtd
}t	|| t|dd|d}t
g ddd
}t	|| d}tjt|d t|dd|d W d    d S 1 s^w   Y  d S )Nl   qMe;r   r  r   r   ro  ri   r?  rk   r'   
1970-01-02r*   rp   )r   r  r  r   r   r   r   r   rq   z8cannot convert input 11111111111111111 with the unit 'D'r_   r0  )r   r   r-   ra   r   r   r   r/   r0   r1   r   rb   rc   r   r2   r'   rD   r4   r5   r   r%   r%   r&   test_unit_array_mixed_nans  s2   
"z-TestToDatetimeUnit.test_unit_array_mixed_nansc                 C   s   dt ttjdg}t|dd|d}tdttttgtd}t|| t|dd|d}t	g dd	d}t|| d
}t
jt|d t|dd|d W d    d S 1 sTw   Y  d S )Nl     #0U.KK% r   ri   r"  rk   r?  r'   r*   rp   )r   r   r   r   r   rq   z@cannot convert input 1420043460000000000000000 with the unit 's'r_   r0  )r   r   r-   ra   r   r   r/   r0   r1   r   rb   rc   r   r  r%   r%   r&   $test_unit_array_mixed_nans_large_int  s   "z7TestToDatetimeUnit.test_unit_array_mixed_nans_large_intc                 C   sH   d}t jt|d tddd|d W d    d S 1 sw   Y  d S )Nz+non convertible value foo with the unit 's'r_   r   r0  r"  r  r  r  r%   r%   r&   8test_to_datetime_invalid_str_not_out_of_bounds_valuerror     "zKTestToDatetimeUnit.test_to_datetime_invalid_str_not_out_of_bounds_valuerrorerrorr/  c                 C   s6   t d}tdd||d}||ksJ t|t sJ d S )Nz1970-05-09 14:25:11iǊ r"  r  )r   r   r   )r2   r'   r  r5   r4   r%   r%   r&   test_unit_consistency  s   z(TestToDatetimeUnit.test_unit_consistencyrk   )ri   r0  rp   r+   float64rY  c                 C   sB   t ddgdd}tddg|}t|||d}t|| d S )N2015-06-19 05:33:202015-05-27 22:33:20rq   r*   @CA5Crk  )r   r-   r.   rB  r   r0   r1   )r2   r'   rk   r+   r5   r3   r4   r%   r%   r&   test_unit_with_numeric  s   z)TestToDatetimeUnit.test_unit_with_numericzexp, arr, warning)r   r  r  )r   r  r  )r  r  r   r   )r  r  r   r   Nc                 C   sX   t |dd}tj|dd t|d|d}W d    n1 sw   Y  t|| d S )Nrq   r*   r  r_   rp   rk  )r   r0   r   r   r1   )r2   r'   r   r3   warningr5   r4   r%   r%   r&   test_unit_with_numeric_coerce  s
   z0TestToDatetimeUnit.test_unit_with_numeric_coercer3   r  r  r  c                 C   sb   t dd |D dd}t|d|d}t|| t|d|d}t|| t|}t|| d S )Nc                 S   rM   r%   rN   rO   r%   r%   r&   rR     rS   z6TestToDatetimeUnit.test_unit_mixed.<locals>.<listcomp>rq   r*   rp   rk  r0  )r   r   r0   r1   r   )r2   r'   r3   r5   r4   r%   r%   r&   test_unit_mixed  s   z"TestToDatetimeUnit.test_unit_mixedc                 C   sB   d}t |d|d}td}||ksJ t|dd}||ksJ d S )Ng aAr"  r  z2015-06-19 19:55:31.877000093r  rG   )r2   r'   r   r4   r5   altr%   r%   r&   test_unit_rounding  s   z%TestToDatetimeUnit.test_unit_roundingc                 C   s2   t dgd dd}t|dd|d}t|| d S )Ng   Br^   r   r   ri   r"  r  )r   r   r0   r1   r2   r'   r5   r4   r%   r%   r&   test_unit_ignore_keeps_name  s   z.TestToDatetimeUnit.test_unit_ignore_keeps_namec                 C   s0   t dgdddd}tdgdd}t|| d S )	Nr   r"  Tri   )r?  r   rk   1970-01-01 00:00:01r  r*   r   r   r%   r%   r&   'test_to_datetime_errors_ignore_utc_true  s   z:TestToDatetimeUnit.test_to_datetime_errors_ignore_utc_truec                    sZ   d t  fddtdD |}t|dd}t dd tdD dd	}t|| d S )
NQc                       g | ]} | qS r%   r%   rP   tepochr%   r&   rR     rS   z<TestToDatetimeUnit.test_to_datetime_unit.<locals>.<listcomp>r  r"  r  c                 S      g | ]}t d t|d qS z2013-06-09 02:42:28)secondsr   r   r  r%   r%   r&   rR   "      rq   r*   )r   r  rB  r   r0   rX   )r2   r+   rZ   r4   r5   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 dd	}t|| d S )
Nr  c                    r  r%   r%   r  r!  r%   r&   rR   -  rS   zGTestToDatetimeUnit.test_to_datetime_unit_with_nulls.<locals>.<listcomp>r  r"  r  c                 S   r#  r$  r&  r  r%   r%   r&   rR   0      rq   r*   )r   r  r   r   r0   rX   )r2   r)  rZ   r4   r5   r%   r!  r&    test_to_datetime_unit_with_nulls*  s    z3TestToDatetimeUnit.test_to_datetime_unit_with_nullsc                    s|   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
d}|d}t	
|| d S )Nr  c                    r  r%   r%   r  r!  r%   r&   rR   9  rS   zOTestToDatetimeUnit.test_to_datetime_unit_fractional_seconds.<locals>.<listcomp>r   r^   g      ?r"  r  c                 S   r#  r$  r&  r  r%   r%   r&   rR   <  r'  rq   r*   ms)r   r-   aranger   rB  r\   r   r   roundr0   rX   )r2   rZ   r4   r5   r%   r!  r&   (test_to_datetime_unit_fractional_seconds6  s   ,
	z;TestToDatetimeUnit.test_to_datetime_unit_fractional_secondsc                 C   sJ   t dddttjgdd}ttdtdgdgd  d	d
}t|| d S )Nr   r^   r   ro  r  r  
1970-01-03r   rq   r*   )r   r   r-   ra   r   r   r0   r1   r   r%   r%   r&   test_to_datetime_unit_na_valuesG  s   z2TestToDatetimeUnit.test_to_datetime_unit_na_valuesbad_valr   ikc                 C   sP   | d}t jt|d tdd|gdd W d    d S 1 s!w   Y  d S )Nz with the unit 'D'r_   r   r^   ro  r  r  )r2   r2  r   r%   r%   r&   test_to_datetime_unit_invalidO  s   
"z0TestToDatetimeUnit.test_to_datetime_unit_invalidc                 C   sF   t tdtdgdgd  dd}tdd|gdd	d
}t|| d S )Nr  r0  r   r   rq   r*   r^   ro  rp   r  )r   r   r   r0   r1   )r2   r2  r5   r4   r%   r%   r&   test_to_timestamp_unit_coerceU  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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 d    n1 slw   Y  t	j
t|d t|	ddd	 W d    d S 1 sw   Y  d S )Nz"cannot convert input with unit 'D'g  S$Bl            r   g{Gzt?r*   r/  ro  r  g|=)Zrtolr_   r0  )r   r\   rB  r-   rY  r   r0   assert_almost_equalr  rb   rc   r   )
r2   r   Zoneday_in_nsZtsmax_in_daysZshould_succeedr5   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   rb   r   r   r\   r  r  r  r  r  r	  r
  r  r  r  r  r   r  r  r  r  intr(  r   r-   ra   r+  r/  r1  r3  r4  r7  r%   r%   r%   r&   r  I  sd    
 







	r  c                   @   s   e Zd Zejdd Zdd Zdd Zej	ddd	d
dddddddddddgdd Z
dd Zdd Zdd Zdd Zej	ddgddgg d ddgg d!gd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.S )/TestToDatetimeDataFramec                 C   s@   t ddgddgddgddgd	d
gddgddgddgddgd	S )Nr!    r^   r   r   rL   r     :   ;   r   r  r   	r  r  r  r  r  secondr,  usr>  )r   r2   r%   r%   r&   df|  s   zTestToDatetimeDataFrame.dfc                 C   sh   t |d |d |d d|d}ttdtdg}t|| t |g d  |d}t|| d S )Nr  r  r  r  r  r  r   20150204 00:00:00z20160305 00:0:00)r   r   r   r0   rX   to_dictr2   rB  r'   r4   r5   r%   r%   r&   test_dataframe  s   z&TestToDatetimeDataFrame.test_dataframec                 C   sH   |g d   }d|d< t||d}ttdtdg}t|| d S )NrC  r^   r  r   rD  z20160205 00:0:00)rE  r   r   r   r0   rX   )r2   rB  r'   df2r4   	expected2r%   r%   r&   &test_dataframe_dict_with_constructable  s   z>TestToDatetimeDataFrame.test_dataframe_dict_with_constructabler?  Zyearsmonthsdaysr   r   r%  )r  r  r  r  r  r?  r  r  r  r  r  r?  c                 C   sH   t |t|  j|d|d}ttdtdgdd}t|| d S )Ncolumnsr   z20150204 06:58:10z20160305 07:59:11rq   r*   )r   r  keysrenamer   r   r0   rX   )r2   rB  r'   r?  r4   r5   r%   r%   r&   *test_dataframe_field_aliases_column_subset  s    zBTestToDatetimeDataFrame.test_dataframe_field_aliases_column_subsetc              
   C   sP   ddddddddd	d
	}t |j|d|d}ttdtdg}t|| d S )Nr  r  r  r  r  r?  r,  r@  r>  r>  rM  r   20150204 06:58:10.00100200320160305 07:59:11.001002003)r   rP  r   r   r0   rX   )r2   rB  r'   dr4   r5   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   rR  rS  )r   rB  rW   r   r   r0   rX   rF  r%   r%   r&   test_dataframe_str_dtype  s   z0TestToDatetimeDataFrame.test_dataframe_str_dtypec                 C   s   t ddgddgddgd}d}tjt|d	 t||d
 W d    n1 s(w   Y  t|d|d}ttdtg}t	|| d S )Nr!  r:  r^   r  r   rL   rC  z^^cannot assemble the datetimes: time data ".+" doesn\'t match format "%Y%m%d", at position 1\.r_   r   rp   rk  rD  )
r   rb   rc   rd   r   r   r   r   r0   rX   )r2   r'   rH  r   r4   r5   r%   r%   r&   test_dataframe_coerce  s   z-TestToDatetimeDataFrame.test_dataframe_coercec                 C   sT   d}t jt|d | }d|d< t||d W d    d S 1 s#w   Y  d S )Nz?extra keys have been passed to the datetime assemblage: \[foo\]r_   r   r   r   )rb   rc   rd   copyr   )r2   rB  r'   r   rH  r%   r%   r&   !test_dataframe_extra_keys_raisesm  s   "z9TestToDatetimeDataFrame.test_dataframe_extra_keys_raisesmcols)r  r  r?  )r  r  r?  c                 C   sH   d}t jt|d t|| |d W d    d S 1 sw   Y  d S )Nz`to assemble mappings requires at least that \[year, month, day\] be specified: \[.+\] is missingr_   r   r  )r2   rB  r'   rZ  r   r%   r%   r&   "test_dataframe_missing_keys_raises  s
   "z:TestToDatetimeDataFrame.test_dataframe_missing_keys_raisesc                 C   s   d}t ddgddgddgd}g d	|_tjt|d
 t||d W d    n1 s-w   Y  t ddgddgddgddgd}g d|_tjt|d
 t||d W d    d S 1 saw   Y  d S )Nz#cannot assemble with duplicate keysr!  r:  r^   r  r   rL   rC  )r  r  r  r_   r   )r  r  r  r  )r  r  r  r  )r   rN  rb   rc   rd   r   )r2   r'   r   rH  r%   r%   r&   'test_dataframe_duplicate_columns_raises	  s   

"z?TestToDatetimeDataFrame.test_dataframe_duplicate_columns_raisesc                 C   sR   t ddgddgddgd}t|d|d	}ttd
tdg}t|| d S )Nr!  r:  r^   r   r   rL   rC  Zint16r   rD  20160305 00:00:00)r   r   rB  r   r   r0   rX   r2   r'   rB  r4   r5   r%   r%   r&   test_dataframe_int16	  s   z,TestToDatetimeDataFrame.test_dataframe_int16c                 C   sp   t ddgddgddgd}|d d	|d< |d
 d	|d
< t||d}ttdtdg}t|| d S )Nr!  r:  r^   r   r   rL   rC  r  Zint8r  r   rD  r]  )r   rB  r   r   r   r0   rX   r^  r%   r%   r&   test_dataframe_mixed&	  s   z,TestToDatetimeDataFrame.test_dataframe_mixedc                 C   s`   t ddgddgddgd}d}tjt|d t||d W d    d S 1 s)w   Y  d S )	Nr   r   r  r   rC  zk^cannot assemble the datetimes: unconverted data remains when parsing with format ".*": "1", at position 0.r_   r   )r   rb   rc   rd   r   )r2   r'   rB  r   r%   r%   r&   test_dataframe_float1	  s   "z,TestToDatetimeDataFrame.test_dataframe_floatc                 C   sV   t ddgddgddgd}t|dd	}ttjd
dgddjd}t|| d S )Nr!  r:  r^   r   r   rL   rC  Tr@  z
2015-02-04z
2016-03-05rW  r*   r   )	r   r   r   r-   r.   r   tz_localizer0   rX   )r2   rB  r4   r5   r%   r%   r&   test_dataframe_utc_true;	  s   z/TestToDatetimeDataFrame.test_dataframe_utc_trueN)r   r   r   rb   fixturerB  rG  rJ  r   r   rQ  rU  rV  rW  rY  r[  r\  r_  r`  ra  rc  r%   r%   r%   r&   r9  {  sV    

	
	

	
r9  c                   @   sB  e Zd Zdd Zejdddgddggdd Zejd	g d
ejdddgdd Zejd	g ddd Z	ejd	g ddd Z
ejd	g ddd Zejd	g ddd Zejd	g ddd Zejd	g dd d! Zd"d# Zejjd$d%d&d' Zd(d) Zd*d+ Zejd,d- Zd.d/ Zejejd0g d1d2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Zd<d= Zejd>ed?ed?gd@dA Z dBdC Z!dDdE Z"dFdG Z#dHdI Z$dJdK Z%dLdM Z&dNdO Z'dPdQ Z(dRdS Z)ejdTg dUdVdW Z*dXdY Z+dZd[ Z,d\d] Z-ejd^e.e/j0gd_d` Z1daS )bTestToDatetimeMiscc                 C   sP   t jdgtd}d}tjt|d t| W d    d S 1 s!w   Y  d S )Nz2262-04-11 23:47:16.854775808r*   z6^Out of bounds nanosecond timestamp: .*, at position 0r_   )r-   r.   r/   rb   rc   r   r   )r2   r3   r   r%   r%   r&   %test_to_datetime_barely_out_of_boundsF	  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J d S )Nr   r   rG   )r2   r'   rH   Zexp_strr4   r   r%   r%   r&   test_to_datetime_iso8601P	  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   sP   t jtd| d| dd t|||d W d    d S 1 s!w   Y  d S )Ntime data \"z\" doesn't match format \"\", at position 0r_   r   r  )r2   r  rB   r   r%   r%   r&   test_to_datetime_iso8601_fails\	  s   "z1TestToDatetimeMisc.test_to_datetime_iso8601_fails)rk  rj  )rl  r   )rm  r   )rn  r   ro  c                 C   s^   d dt ddt dg}tjt|d t||d W d    d S 1 s(w   Y  d S )Nr   r   r   z:^time data ".*" doesn't match format ".*", at position 0. r_   rw   r   )r2   r  rB   r   r%   r%   r&   $test_to_datetime_iso8601_exact_failsv	  s   "z7TestToDatetimeMisc.test_to_datetime_iso8601_exact_fails)rs  )z2012-01-01 00r   )z2012-01-01 00:00r   )rg  r   c                 C   s*   t ddd}t||dd}||ksJ d S )Nr   r   Fr   r   r   r2   r  rB   r5   r4   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   sN   t jtd| d| dd t||d W d    d S 1 s w   Y  d S )Nrp  z\" doesn\'t match format \"rq  r_   rw   r  )r2   r  rB   r%   r%   r&   "test_to_datetime_iso8601_separator	  s   "z5TestToDatetimeMisc.test_to_datetime_iso8601_separator))rx  rj  )r  r   )ry  r   )rz  %Y-%m-%dT%H)r{  r   )r|  %Y-%m-%dT%H:%M)r}  r   )r~  %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.000000r  )z2020-01-01T00:00:00.000000000r  c                 C   (   t ddd}t||d}||ksJ d S Nr   r   rw   ru  rv  r%   r%   r&   test_to_datetime_iso8601_valid	     z1TestToDatetimeMisc.test_to_datetime_iso8601_valid))z2020-1rj  )z2020-1-1r   )z
2020-1-1 0r   )z
2020-1-1T0r  )z2020-1-1 0:0r   )z2020-1-1T0:0r  )z2020-1-1 0:0:0r   )z2020-1-1T0:0:0r  )z2020-1-1T0:0:0.000r  )z2020-1-1T0:0:0.000000r  )z2020-1-1T0:0:0.000000000r  c                 C   r  r  ru  rv  r%   r%   r&   #test_to_datetime_iso8601_non_padded	  r  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:00Zr  c                 C   s.   t dddtjd}t||d}||ksJ d S )Nr   r   r   rw   )r   r   r   r   rv  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J d S )NZ2001r   r   r   rH  )r2   r'   rsZxpr%   r%   r&   test_to_datetime_default	  s   z+TestToDatetimeMisc.test_to_datetime_defaultz1fails to enforce dayfirst=True, which would raise)r   c              	   C   s   d}t jt|d/ tjtdd tdd|d W d    n1 s#w   Y  W d    d S W d    d S 1 s;w   Y  d S )NzInvalid date specifiedr_   zProvide formatz
01-13-2012Tdayfirstr'   r  r  r%   r%   r&   "test_to_datetime_respects_dayfirst	  s   "z5TestToDatetimeMisc.test_to_datetime_respects_dayfirstc                 C   s4   t tddd}t||d}|d |d ksJ d S )Nr>   r   r7  r   r   )r   r   r   )r2   r'   rZ   r4   r%   r%   r&   %test_to_datetime_on_datetime64_series
  s   z8TestToDatetimeMisc.test_to_datetime_on_datetime64_seriesc                 C   s   t g d}dt d}tjt|d t|d|d W d    n1 s%w   Y  t|d|d}t tdd	d
tdd	d
tg}t	|| t|d|d}t	|| d S )N)z
10/18/2006z
10/18/2008 z@^time data " " doesn\'t match format "%m/%d/%Y", at position 2. r   r_   r0  rk  rp   i  r   r   rF  ri   )
r   r   rb   rc   rd   r   r   r   r0   rX   )r2   r'   rZ   r   Zresult_coerceZexpected_coerceZresult_ignorer%   r%   r&   %test_to_datetime_with_space_in_series

  s   z8TestToDatetimeMisc.test_to_datetime_with_space_in_seriesc                 C   sB   t g dg dd}t|d|d}|jtd|d}t|| d S )N)May 04Jun 02zDec 11r   r^   r   index%b %yrA   r   r   rV   r0   rX   )r2   r'   r   r5   r4   r%   r%   r&   test_to_datetime_with_apply
  s   z.TestToDatetimeMisc.test_to_datetime_with_applyc                 C   s.   t ddd}tdddd}||ksJ d S )Nz2020-01-01 00:00:00UTCz%Y-%m-%d %H:%M:%S%Zrw   r   r   r   )r   r   rb  r   r%   r%   r&   test_to_datetime_timezone_name#
  s   z1TestToDatetimeMisc.test_to_datetime_timezone_namerk   r/  c                    sF   t g dg dd}t|d| d}| fdd}t|| d S )N)r  r  r   r  r  r  rj   c                    s   t | dd dS )Nr  rp   rj   r   r  r   r%   r&   r  3
  s    zOTestToDatetimeMisc.test_to_datetime_with_apply_with_empty_str.<locals>.<lambda>r  )r2   r'   rk   r   r5   r4   r%   r   r&   *test_to_datetime_with_apply_with_empty_str)
  s   
z=TestToDatetimeMisc.test_to_datetime_with_apply_with_empty_strc                 C   s   t d|d}|tu sJ d S Nr   r   )r   r   r2   r'   r4   r%   r%   r&   test_to_datetime_empty_stt7
     z-TestToDatetimeMisc.test_to_datetime_empty_sttc                 C   s$   t ddg|d}t| sJ d S r  )r   r   r  r  r%   r%   r&   test_to_datetime_empty_str_list<
  s   z2TestToDatetimeMisc.test_to_datetime_empty_str_listc                 C   s$   t d}td|d}||ksJ d S )Nr   r   ru  rn   r%   r%   r&   test_to_datetime_zero@
  s   z(TestToDatetimeMisc.test_to_datetime_zeroc                 C   s.   t dg|dd }t d|d}||ksJ d S )Nri  r   r   r   r  r%   r%   r&   test_to_datetime_stringsF
  s   z+TestToDatetimeMisc.test_to_datetime_stringsc                    s8   g d} fdd|D }dd |D }t || d S )N)ri  Z20120101z20120101 12:01:01c                    s   g | ]}t | d qS )r   r   )rP   r  r   r%   r&   rR   N
  s    zITestToDatetimeMisc.test_to_datetime_strings_variation.<locals>.<listcomp>c                 S   rM   r%   rN   )rP   date_strr%   r%   r&   rR   O
  rS   )r0   r5  )r2   r'   r.   r5   r4   r%   r   r&   "test_to_datetime_strings_variationL
  s   z5TestToDatetimeMisc.test_to_datetime_strings_variationr4   ri  c                 C   s   t ddd}||ksJ d S )Nr   r   rN   r   r%   r%   r&   'test_to_datetime_strings_vs_constructorR
  r  z:TestToDatetimeMisc.test_to_datetime_strings_vs_constructorc                 C   s~   t ddgd|d}ttjddgdd}t|| d}tjt|d t ddgd	|d W d    d S 1 s8w   Y  d S )
Nr   1ri   rk  Or*   z<^Given date string "1" not likely a datetime, at position 1$r_   r0  )	r   r   r-   r.   r0   rC   rb   rc   rd   )r2   r'   r4   r5   r   r%   r%   r&   $test_to_datetime_unprocessable_inputW
  s   "z7TestToDatetimeMisc.test_to_datetime_unprocessable_inputc                 C   s.   t dggd }t|d|d}t|| d S )Nr  d   ri   rk  rr   )r2   r'   seriesr4   r%   r%   r&   !test_to_datetime_unhashable_inputb
  s   z4TestToDatetimeMisc.test_to_datetime_unhashable_inputc                 C   sR   t dd}|d}t|g}|d |dksJ t|}||ks'J d S )Nl    `SD& zM8[us]r  r   )r-   rY  viewrB  r   r   )r2   r  Zas_objr  r   r%   r%   r&   'test_to_datetime_other_datetime64_unitsg
  s   

z:TestToDatetimeMisc.test_to_datetime_other_datetime64_unitsc                 C   s8   t ddd}t|j}t|j}t|}t|| d S )Nr>   r  r  )r   r   rD   r  Zasi8r0   r1   )r2   rngZintsr4   r%   r%   r&   !test_to_datetime_list_of_integersr
  s
   

z4TestToDatetimeMisc.test_to_datetime_list_of_integersc                 C   sF   d}t jt|d tdddd W d    d S 1 sw   Y  d S )Nz>Cannot cast 139999 days 00:00:00 to unit='ns' without overflowr_   z1/1/1700Br  )startr8  r7  )rb   rc   r   r   r2   r   r%   r%   r&   r   |
     "z,TestToDatetimeMisc.test_to_datetime_overflowc                 C   sR   t jdgtd}tjtdd t|d|d W d    d S 1 s"w   Y  d S )NZ87156549591102612381000001219H5r*   Unknown datetime string formatr_   r0  rk  )r-   r.   r/   rb   rc   rd   r   )r2   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|r$t||< qt|||< qt	
|d }t|| t||d}t|tsEJ t||j d S )	Nr>   r?   z1/4/2000r*   r   rq   r   r   )r-   r.   ra   r/   empty	enumerater   r   r	   r   Zarray_to_datetimer0   r5  r   r   r   Zassert_numpy_array_equalrD   )r2   r'   stringsr5   r  r   r4   r   r%   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 d    n1 s%w   Y  t|d|d}t|td}t	
|| tjt|d t|d|d W d    d S 1 sWw   Y  d S )Nz
1/100/2000r*   r  r_   r0  rk  ri   )r-   r.   ra   r/   rb   rc   rd   r   r   r0   r1   )r2   r'   Z	malformedr   r4   r5   r%   r%   r&   'test_string_na_nat_conversion_malformed
  s   "z:TestToDatetimeMisc.test_string_na_nat_conversion_malformedc           
   	   C   s  g d}t dtjdtjdg|dd}t td|dtjtd|dtjtd|dg|dd}t||d}t||d}t tjdd	d
|d}tdD ]}|j| }	t|	rXt|j|< qGt|	|d|j|< qGt	j
||dd |jdksqJ t	j
||dd |jdksJ d S )N)r  r  crT  er>   r@   z1/5/2000r   r  r   r   rL   rq   r*   r  F)Zcheck_names)r   r-   ra   r   r  r  r  r   r   r0   rX   r   )
r2   r'   idxr  Zdseriesr4   Zdresultr5   r  rQ   r%   r%   r&   'test_string_na_nat_conversion_with_name
  s4   



z:TestToDatetimeMisc.test_string_na_nat_conversion_with_namer?  )hmr"  r,  r@  r>  c                 C   s   t d| d}tg d|d}|j|}|dv rd}t d| d}t||}|j|ks4J 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   rD   rB  r   r0   r1   )r2   r'   r?  r+   baserD   Z	exp_dtyper5   r%   r%   r&   $test_dti_constructor_numpy_timeunits
  s   z7TestToDatetimeMisc.test_dti_constructor_numpy_timeunitsc           
      C   s   g d}t tdddtdddtdddg}t |dd}t t|dd}t|d|d	}tt|d|d	}t t|dd}t t|dd}	t|| t|| t|| t|| t|| t||	 d S )
N)z
10/02/2014z
11/02/2014z
12/02/2014r  r^   r   r  r   Tr  r  )	r   r   r-   r.   r   r   r   r0   r1   )
r2   r'   r3   r5   Zidx1Zidx2Zidx3Zidx4Zidx5Zidx6r%   r%   r&   test_dayfirst
  s     z TestToDatetimeMisc.test_dayfirstc                 C   s   d}ddg}t ddgdd d}t|dd	}t|| tjt|d
 t|dd	}W d    n1 s3w   Y  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-10rW  r  Tr  r_   F)r   r   r0   r1   r   r  )r2   Zwarning_msgr3   r5   res1res2r%   r%   r&   "test_dayfirst_warnings_valid_input
  s   
z5TestToDatetimeMisc.test_dayfirst_warnings_valid_inputc                 C   sP   ddg}t jtdt dd t|dd W d    d S 1 s!w   Y  d S )Nr  z
03/30/2011zI^time data "03/30/2011" doesn\'t match format "%d/%m/%Y", at position 1. r   r_   Tr  )rb   rc   rd   r   r   )r2   r3   r%   r%   r&   $test_dayfirst_warnings_invalid_input  s   "z7TestToDatetimeMisc.test_dayfirst_warnings_invalid_inputklassc                 C   sH   t dddd}|d}||}||}t|dd}t|| d S )Nz
2015-04-05r   r  r   r   Tr@  )r   rP  rb  r   r0   rC   )r2   r  r:  r5   objr4   r%   r%   r&   test_to_datetime_dta_tz  s   
z*TestToDatetimeMisc.test_to_datetime_dta_tzN)2r   r   r   rf  rb   r   r   rh  rr  rt  rw  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   Z_from_sequencer  r%   r%   r%   r&   re  E	  s    




	





	

"
re  c                   @   s`   e Zd Zejdg d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_list)2011-12-30 00:00:00.000000r  r  r  r   r   random_stringrO  rV  c                 C   s(   d}t j|td}t||ksJ d S )Nr   r*   )r-   r.   r/   tools _guess_datetime_format_for_array)r2   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 u sJ d S )Nr  r*   )r  r  r-   r.   ra   )r2   Zformat_for_string_of_nansr%   r%   r&   -test_guess_datetime_format_for_array_all_nansA  s   zETestGuessDatetimeFormat.test_guess_datetime_format_for_array_all_nansN)r   r   r   rb   r   r   r-   ra   r  r   r   r  r%   r%   r%   r&   r  +  s    
r  c                   @   s   e Zd Zejdg ddd Zdd Zdd Zd	d
 Z	dd Z
ejdg ddd Zejdg ddd Zejdddgdd Zdd ZdS )TestToDatetimeInferFormattest_format)z%m-%d-%Yz%m/%d/%Y %H:%M:%S.%fr  c                    sN   t tdddd}| fdd}t| |d}t||d}t|| d S )	Nr8   2   r  r7  r8  c                    s
   |   S r  )strftimer  r  r%   r&   r  R     
 zdTestToDatetimeInferFormat.test_to_datetime_infer_datetime_format_consistent_format.<locals>.<lambda>rA   r   )r   r   rV   r   r0   rX   )r2   r'   r  rZ   Zs_as_dt_stringsZwith_formatZwithout_formatr%   r  r&   8test_to_datetime_infer_datetime_format_consistent_formatJ  s
   zRTestToDatetimeInferFormat.test_to_datetime_infer_datetime_format_consistent_formatc                 C   sb   g d}t t|}dt d}tjt|d t||d W d    d S 1 s*w   Y  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   r_   r   )r   r-   r.   r   rb   rc   rd   r   )r2   r'   r   rZ   r   r%   r%   r&   $test_to_datetime_inconsistent_format[  s   "z>TestToDatetimeInferFormat.test_to_datetime_inconsistent_formatc                 C   sB   g d}t t|}t||d}t g ddd}t|| d S )N)zJan/01/2011zFeb/01/2011zMar/01/2011r   )
2011-01-01z
2011-02-01z
2011-03-01rW  r*   )r   r-   r.   r   r0   rX   )r2   r'   r   rZ   r4   r5   r%   r%   r&   "test_to_datetime_consistent_formate  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-03rW  	r   r-   r.   ra   r/   r   r   r0   rX   rl   r%   r%   r&   !test_to_datetime_series_with_nansn  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  rW  r  rl   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   rb  r0   rX   )r2   Ztz_namer   rZ   r4   r   r5   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   r0   rX   )r2   rm  Zzero_tzrZ   r4   r   r5   r%   r%   r&   "test_infer_datetime_format_zero_tz  s
   z<TestToDatetimeInferFormat.test_infer_datetime_format_zero_tzrB   Nr   c                 C   sD   t g d}t tdtdtdg}t|||d}t|| d S )N)2014-1-1z2014-2-2z2015-3-3z
2014-01-01z
2014-02-02z
2015-03-03rA   r  )r2   r'   rB   rZ   r5   r4   r%   r%   r&   %test_to_datetime_iso8601_noleading_0s  s   z?TestToDatetimeInferFormat.test_to_datetime_iso8601_noleading_0sc                 C   sB   t jtdd tdgdd W d    d S 1 sw   Y  d S )Nz2The argument 'infer_datetime_format' is deprecatedr_   z
10-10-2000T)Zinfer_datetime_format)r0   r   r  r   rA  r%   r%   r&   .test_parse_dates_infer_datetime_format_warning  s   "zHTestToDatetimeInferFormat.test_parse_dates_infer_datetime_format_warning)r   r   r   rb   r   r   r  r  r  r  r  r  r  r  r  r%   r%   r%   r&   r  I  s,    

	

	
r  c                   @   s   e Zd Zejdddgddgddgddggdd Zd	d
 Zejdddde de	 dfddde de	 dfddde	 dfddde	 dfddde de	 dfddde 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 )TestDaysInMonthrh  
2015-02-29Nr   z
2015-02-32z
2015-04-31c                 C   s   t t|d||dsJ d S )Nrp   rk   rB   r'   )r   r   )r2   r'   rH   rB   r%   r%   r&   test_day_not_in_month_coerce  s   
z,TestDaysInMonth.test_day_not_in_month_coercec                 C   sP   t rd}nd}tjt|d tdd|d W d    d S 1 s!w   Y  d S )NzBday 29 must be in range 1..28 for month 2 in year 2015: 2015-02-29z)day is out of range for month: 2015-02-29r_   r  r0  rk  )r   rb   rc   rd   r   r  r%   r%   r&   test_day_not_in_month_raise  s   "z+TestDaysInMonth.test_day_not_in_month_raisezarg, format, msg^z. 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   sD   t jt|d t|d||d W d    d S 1 sw   Y  d S )Nr_   r0  r  r  )r2   r'   rH   rB   r   r%   r%   r&   !test_day_not_in_month_raise_value  s   '"z1TestDaysInMonth.test_day_not_in_month_raise_valuezexpected, formatc                 C   s    t |d||d}||ksJ d S )Nri   r  r   )r2   r'   r5   rB   r4   r%   r%   r&   test_day_not_in_month_ignore  s   
z,TestDaysInMonth.test_day_not_in_month_ignore)r   r   r   rb   r   r   r  r  DAY_IS_OUT_OF_RANGEr   r  r  r%   r%   r%   r&   r    sj    
	
%	r  c                   @   sh  e Zd Zejdg 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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   rL   Z20051109	   z20051109 10:15rG  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-06r  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sJJ qB||	|
||fD ]}tt	|g}t
|| qR|s|t	|}||ksnJ t|dd|d}||ks~J d S d S )NT)	yearfirstr*   )r  r'   Sr   )r8  r7  r  )r   parse_datetime_string_with_resor   r-   r.   r/   r   r   r   r   r0   r1   r   )r2   r  r5   r'   r  r6  _r   r   r   Zresult6Zresult8Zresult9r   r   result5Zresult7r%   r%   r&   test_parsers  s0   8
z(TestDatetimeParsingWrappers.test_parsersc                 C   s0   t ttgdd}t||g|d}t|| d S )NrW  r*   r   )r   r   r   r0   r1   )r2   r'   Zunique_nulls_fixtureZunique_nulls_fixture2r5   r4   r%   r%   r&   test_na_values_with_cacheh  s   z5TestDatetimeParsingWrappers.test_na_values_with_cachec                 C   s`   t d\}}td}td}tdgd }|tu sJ |tu s"J |tu s(J |tu s.J d S )Nr   r   )r   r  r   r   r   r   )r2   r6  r  r   r   r   r%   r%   r&   test_parsers_natp  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J tj|||d\}}|s%|s%t|}	|	|ks%J t||||d}
t|g||dd }||ks=J |
|ksCJ ||ksIJ d S )N)r  r  )r  r  r'   r   )r	   r   r  r   r   r   )r2   r'   r  r  r  r5   Zdateutil_resultr6  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s%J ||ks+J ||ks1J ||ks7J |	|ks=J d S )Nr   )r	   r   r  r   r   r   )
r2   r  Zexp_defZexp_nowr6  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sJ |t|ks"J d S )Nz2013-01-01 00:00:00r   r   )r   rb  r   repr)r2   r'   Z	dt_stringr   Zdt_string_reprr  Zdt_timer%   r%   r&   .test_parsers_timezone_minute_offsets_roundtrip  s
   zJTestDatetimeParsingWrappers.test_parsers_timezone_minute_offsets_roundtripN)r   r   r   rb   r   r   r   r
  r  r  r  r  r   r   r  r%   r%   r%   r&   r    s   	 !"#$%&'(*+,-./0
5 
D&
r  )ro  r"  r,  r@  r>  c                 C   r    )zIDay and some time units.

    * D
    * s
    * ms
    * us
    * ns
    r!   r#   r%   r%   r&   units  s   
r  c                   C   s   t dS )zTimestamp at 1960-01-01.
1960-01-01rN   r%   r%   r%   r&   
epoch_1960	  s   r  c                   C   s   t tdS )NrL   )r  r  r%   r%   r%   r&   units_from_epochs  s   r  )rC  
pydatetimerX  str_1960c                 C   sH   |j dv sJ |j dkr| S |j dkr|  S |j dkr |  S t| S )zxTimestamp at 1960-01-01 in various forms.

    * Timestamp
    * datetime.datetime
    * numpy.datetime64
    * str
    >   rX  r  rC  r  rC  r  rX  )r"   r  Zto_datetime64rW   )r  r$   r%   r%   r&   epochs  s   	


r  c                   C   s   t ddd jS )Nr  r   r  )r   to_julian_daterD   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ej	
dedddeddddedg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&g d'g d(g d)gd*d+ Zej	
d,g d-g d.g d/g d0gd1d2 Zd!S )3
TestOriginc                 C   sH   t dddd}td}||ksJ t dddd}td}||ks"J d S )Nr   r"  r  z1970-01-01 00:00:02i ʚ;z2001-09-09 01:46:41rG   )r2   rm  r5   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 )Nro  julianr  r   r  )r   r   r   r  r0   rX   )r2   r  r4   r5   r%   r%   r&   test_julian8  s
   zTestOrigin.test_julianc                 C   sD   t tg dddd}t tdtdtdgdd	}t|| d S )
N)r   r   r^   ro  r   r  z
1970-01-01r  r0  rq   r*   r  r   r%   r%   r&   	test_unixB  s   zTestOrigin.test_unixc                 C   sd   t dddd}| dksJ d}tjt|d t dddd W d    d S 1 s+w   Y  d S )NiR|% r  ro  r  r?  z&1 is Out of Bounds for origin='julian'r_   r   )r   r  rb   rc   rd   )r2   r4   r   r%   r%   r&   test_julian_round_tripJ  s   "z!TestOrigin.test_julian_round_tripc                 C   sR   |dkr'd}t jt|d t||dd W d    d S 1 s w   Y  d S d S )Nro  z$unit must be 'D' for origin='julian'r_   r  r  r  )r2   r  r  r   r%   r%   r&   test_invalid_unitS  s   "zTestOrigin.test_invalid_unitr?  r>  ro  c                 C   sF   d}t jt|d tdd|d W d    d S 1 sw   Y  d S )Nz(it must be numeric with a unit specifiedr_   z
2005-01-01r  r   r  )r2   r?  r   r%   r%   r&   test_invalid_originZ  r  zTestOrigin.test_invalid_originr    r   r  c                    sV   t ddd tjdtjd}t fdd|D }tt||d}t|| d S )Nr$  r   rL   r*   c                    s   g | ]}t j|d   qS )r  )r   Z	TimedeltarO   r  r  r%   r&   rR   n  r*  z)TestOrigin.test_epoch.<locals>.<listcomp>r  )r   r-   r-  rY  r   r   r0   rX   )r2   r  r  r  r5   r4   r%   r%  r&   
test_epocha  s   
zTestOrigin.test_epochzorigin, excr  r"  z
13-24-1990c                 C   sb   d d| dd| ddg}tj||d t|||d W d    d S 1 s*w   Y  d S )Nr   zorigin z is Out of Boundsz# cannot be converted to a Timestampz,Cannot cast .* to unit='ns' without overflowr_   r  )r   rb   rc   r   )r2   r  excr  r  r   r%   r%   r&   test_invalid_originst  s   


"zTestOrigin.test_invalid_originsc              
   C   sP   t jtdd tddtdddtjdd W d    d S 1 s!w   Y  d S )Nzmust be tz-naiver_   r   ro  r   r   r  )rb   rc   rd   r   r   r   r   rA  r%   r%   r&   test_invalid_origins_tzinfo  s   "z&TestOrigin.test_invalid_origins_tzinfoc                 C   sD   d}t jt|d tddg W d    d S 1 sw   Y  d S )NzIUnknown datetime string format, unable to parse: yesterday, at position 1r_   rV  Z	yesterdayr  r  r%   r%   r&   test_incorrect_value_exception  s
   "z)TestOrigin.test_incorrect_value_exceptionzformat, warningN)r   N)r   Nc                 C   sD   d}t jt|d td|d W d    d S 1 sw   Y  d S )NzG^Out of bounds nanosecond timestamp: 2417-10-10 00:00:00, at position 0r_   z2417-10-10 00:00:00rw   r  )r2   rB   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)r,  
1870-01-012069-11-13 00:00:00)鼫 r-  2169-10-20 00:00:00c                 C   sj   t |d|d}t|}||ksJ t dddd}td}||ks"J t dddd}td}||ks3J d S )Nro  r  r,  r-  r.  r/  r0  rG   )r2   rH   r  Zexpected_strr4   r5   r%   r%   r&   test_processing_order  s   z TestOrigin.test_processing_orderzoffset,utc,exp)r  T2019-01-01T00:00:00.000Z)r  Nr2  )-01:00Tz2019-01-01T01:00:00.000Z)r3  Nz2019-01-01T00:00:00.000-01:00c                 C   s8   d| }t |gd|d}t |gd}t|| d S )Nz2019-01-01T00:00:00.000r>  )r?  r   )r   rR  r0   r1   )r2   r   r   r   rH   r4   r5   r%   r%   r&   test_arg_tz_ns_unit  s   zTestOrigin.test_arg_tz_ns_unit)r   r   r   r  r  r  r!  r"  rb   r   r   r#  r   r   r-   rX  r&  rd   r   r(  r)  r*  r  r+  r1  r4  r%   r%   r%   r&   r  -  sj    

	



	

	

	r  c                   @   s   e Zd Zejdg ddfg ddfgdd Zejdd	d
gdd Zejdee	dgd e	dgd e
e	dgd gdd ZdS )TestShouldCachezlistlike,do_caching)
r   r^   r   r   rL   r  r;  r  r  r   F)
r   r   r   r   r   rL   r  r;  r  r  Tc                 C   s    t j|t|dd|ksJ d S )Ngffffff?)check_countunique_share)r  should_cacher  )r2   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   r^   z-unique_share must be in next bounds: \(0; 1\)c                 C   sL   dgd }t jt|d t||| W d    d S 1 sw   Y  d S )NrL   r   r_   )rb   rc   AssertionErrorr  r8  )r2   r7  r6  Zerr_messagerH   r%   r%   r&   test_should_cache_errors  s   
"z(TestShouldCache.test_should_cache_errorsr9  r  r  c                 C   s   t |du s	J d S )NT)r  r8  )r2   r9  r%   r%   r&   &test_no_slicing_errors_in_should_cache  s   
z6TestShouldCache.test_no_slicing_errors_in_should_cacheN)r   r   r   rb   r   r   r:  r<  r   r   r  r=  r%   r%   r%   r&   r5    s.    



r5  c                  C   sv   t g d} | d} |  }t| dd}t tdtdtdtdtdg}t|| t| | d S )	N)r   r^   Nl            NZInt64r>  r  z1970-01-01 00:00:00.000000001z1970-01-01 00:00:00.000000002r   z2043-01-25 23:56:49.213693952)r   rB  rX  r   r-   rX  r0   rX   )rZ   Zser_copyr   r5   r%   r%   r&   !test_nullable_integer_to_datetime  s   
	r>  r  c                 C   sn   t | tr&tjtdd t|| g W d    d S 1 sw   Y  d S t|| g}|d tu s5J d S )Nznot convertible to datetimer_   r   )r   r   rb   rc   r  r   r   )Znulls_fixturer  r4   r%   r%   r&   test_na_to_datetime
  s   
"r?  rk   r/  zargs, format)z
03/24/2016z
03/25/2016r   r;   )
2016-03-24
2016-03-25r   r   r   r   r  c                 C   s8   t |}t||| d}t ddtgdd}t|| d S )Nrz   r@  rA  rW  r*   )r   r   r   r0   rX   )rk   r  rB   r   r4   r5   r%   r%   r&   test_empty_string_datetime  s   rB  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"  rp   r  r  r   rW  r*   r0  r   r4   r5   r%   r%   r&   'test_empty_string_datetime_coerce__unit)  s
   rD  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_seriesrB  r\   r   r  r0   rX   )r'   Zcstarttimesr4   r5   r%   r%   r&   +test_to_datetime_monotonic_increasing_index5  s   rH  series_length(   r   rL   c                 C   s   t tdgtdg|   td}t|ddd}t tgtdg|   }t|| t|ddd}t tdgtdg|   }t|| t	j
tdd	 t|d
dd W d    d S 1 sbw   Y  d S )Nz1446-04-12 00:00:00+00:00z1991-10-20 00:00:00+00:00r*   rp   T)rk   r   ri   r  r_   r0  )r   r   fromisoformatr/   r   r   r   r0   rX   rb   rc   r   )rI  rZ   r6  Z	expected1r   rI  r%   r%   r&   2test_to_datetime_cache_coerce_50_lines_outofboundsA  s*   

"rL  c               
   C   s<   d} d}t | |d}tddddddd	d
d}||ksJ d S )Nz15/02/2020 02:03:04.123456789z%d/%m/%Y %H:%M:%S.%frw   r   r^   rG  r   r   r   i  )r  r  r  r  r  r?  microsecondZ
nanosecondrG   )rC  Ztimestamp_formatr4   r5   r%   r%   r&   %test_to_datetime_format_f_parse_nanosa  s   
rN  c                  C   s,   t ddgdd} tddg}t| | d S )Nr  z2020-01-01 05:00:00r   rw   r}  r   rC  r%   r%   r&   test_to_datetime_mixed_iso8601s     rO  c                  C   s,   t ddgdd} tddg}t| | d S )Nz
01/11/2000z12 January 2000r   rw   z
2000-01-11z
2000-01-12r   rC  r%   r%   r&   test_to_datetime_mixed_otherz  rP  rQ  r   rB   r   c                 C   sH   d}t jt|d tdg| |d W d    d S 1 sw   Y  d S )Nz8Cannot use 'exact' when 'format' is 'mixed' or 'ISO8601'r_   r  )r   rB   r  )r   rB   r   r%   r%   r&   #test_to_datetime_mixed_or_iso_exact  r  rR  c                   C   sD   t jtdd tddgdd W d    d S 1 sw   Y  d S )Nz9Time data 01-01-2000 is not ISO8601 format, at position 1r_   r  
01-01-2000r   rw   r  r%   r%   r%   r&   4test_to_datetime_mixed_not_necessarily_iso8601_raise  s
   "rT  )rk   r5   rp   r}  ri   r  rS  rW   r*   c                 C   s"   t ddgd| d}t|| d S )Nr  rS  r   rz   r   )rk   r5   r4   r%   r%   r&   5test_to_datetime_mixed_not_necessarily_iso8601_coerce  s   	rU  c                  C   s   d} d}t jt|d t| }W d    n1 sw   Y  |t| d d ks+J t t t| }W d    n1 s?w   Y  |t| d d ksPJ t t t| g}W d    n1 sew   Y  t |t| d d g d S )Nz2014 Jan 9 05:15 FAKEzLun-recognized timezone "FAKE". Dropping unrecognized timezones is deprecatedr_   )r0   r   r   r   r   r1   )dtstrr   r   r%   r%   r&   #test_ignoring_unknown_tz_deprecated  s   

rX  c                 C   sL   t d tddg|   dd}t|}tddgdd}t|| d S )Nr=  r   r^   z	[pyarrow]r*   rW  )rb   rA  r   lowerr   r0   rX   )Zany_numeric_ea_dtyperZ   r4   r5   r%   r%   r&   test_from_numeric_arrow_dtype  s
   
rZ  c                  C   s`   ddg} t | dd}ttddgdd}t|| t | }t|| t| }t|| d S )N2020-01-01 00:00+00:00r   r   rw   r   r  r*   )r   r   r   r0   r1   r   )r   r4   r5   r  Zalt2r%   r%   r&   6test_to_datetime_with_empty_str_utc_false_format_mixed  s   r\  c                  C   sH   d} t jt| d tg ddd W d    d S 1 sw   Y  d S )Nr   r_   )r[  z2020-01-01 00:00+02:00r   r   rw   r  )r   r%   r%   r&   Btest_to_datetime_with_empty_str_utc_false_offsets_and_format_mixed  s   "r]  c                  C   s   t ddd} d}| |g}d}tjt|d t| W d    n1 s$w   Y  tjt|d t|dd W d    n1 sAw   Y  tjt|d t| W d    d S 1 s]w   Y  d S )	Nz2016-01-02 03:04:05r   r   z2023-10-30 15:06+01zsMixed timezones detected. pass utc=True in to_datetime or tz='UTC' in DatetimeIndex to convert to a common timezoner_   r   rw   )r   rb   rc   rd   r   r   )rm  rW  r3   r   r%   r%   r&   &test_to_datetime_mixed_tzs_mixed_types  s   

"r^  c                  C   s   d} t | }|| g}t|}t|d d d d d d }t|dd}t|}t||g}t|| t|| t|| t|| d S )Nz2023-11-01 09:22:03-07:00r   r   rw   r|  )rW  rm  r3   r  r  Zres3Zres4r5   r%   r%   r&   )test_to_datetime_mixed_types_matching_tzs  s   r_  r[  z)ignore:Could not infer format:UserWarning	aware_valc                 C   
   t | jS r  r  r   r  r%   r%   r&   r    r  r  	naive_valic                 C   ra  r  rb  r  r%   r%   r&   r     r  naive_firstc           
   	   C   s  | |dg}|}|r|| dg}t | tot |t}t |ttf}d}tdd |D }t |ts}d}	|r[t | tr[t |tr?d}	tjt|	d t	| W d    n1 sUw   Y  ntjt|	d t	| W d    n1 sqw   Y  t	|dd	 n|r|
| |
|k rd
}	tjt|	d t	| W d    n1 sw   Y  tjt|	d t	|dd	 W d    n1 sw   Y  n|r|
| |
|k rd}	tjt|	d t	| W d    n1 sw   Y  tjt|	d t	|dd	 W d    n	1 sw   Y  nm|rY|
||
| k rYd}	tjt|	d t	| W d    n	1 s5w   Y  tjt|	d t	|dd	 W d    n	1 sSw   Y  n"tjt|d t	| W d    n	1 spw   Y  t	|dd	 |rtjt|d t	|dd W d    n	1 sw   Y  tjt|d/ d}	tjt|	d t| W d    n1 sw   Y  W d    d S W d    d S 1 sw   Y  d S d}	|r-t | tr-t |trd}	tjt|	d t	|dd W d    n	1 s	w   Y  tjt|	d t| W d    d S 1 s&w   Y  d S tjt|	d t	|dd W d    n	1 sFw   Y  tjt|	d t| W d    d S 1 scw   Y  d S )Nr   zFIn a future version of pandas, parsing datetimes with mixed time zonesc                 s   s    | ]	}|d kr|V  qdS )r   Nr%   rO   r%   r%   r&   r    s    z?test_to_datetime_mixed_awareness_mixed_types.<locals>.<genexpr>z(Cannot mix tz-aware with tz-naive valuesz<Tz-aware datetime.datetime cannot be converted to datetime64r_   Tr@  z!time data .* doesn't match formatz3time data \"2020-01-01 00:00\" doesn't match formatz1unconverted data remains when parsing with formatr   rw   z!DatetimeIndex has mixed timezones)r   rW   r8  r\   nextr   rb   rc   rd   r   r  r0   r   r   r  r   )
r`  rc  rd  r   ZvecZ	both_strsZhas_numericr~  Zfirst_non_nullr   r%   r%   r&   ,test_to_datetime_mixed_awareness_mixed_types  s   










 $
$
$rf  )l__doc__r   collectionsr   r   r   r   r   decimalr   r   Zdateutil.parserr	   Zdateutil.tz.tzr
   numpyr-   rb   r   Zpandas._libsr   Zpandas._libs.tslibsr   r   Zpandas.compatr   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_testingr0   Zpandas.core.arraysr   Zpandas.core.toolsr   r  Zpandas.core.tools.datetimesr   r   r  r  r   r  Z
pytestmarkrd  r'   r(   r   r  r9  re  r  r  r  r  r  r  r  r  r  r  r5  r>  r   r.   r  r?  rB  rD  rH  rL  rN  rO  rQ  rR  rT  rU  rX  rZ  r\  r]  r^  r_  rW  rm  rb  rl  r   r\   rf  r%   r%   r%   r&   <module>   s
   ,

   y            4 K   izO k




  (






	


*