o
    ŀg>                     @   sh  d dl Z d dlmZmZmZmZ d dlZd dlZd dlmZm	Z	m
Z
 d dlZd dlZd dlZd dlmZ d dlmZ d dlmZ d dlmZmZmZmZmZ G dd	 d	ZG d
d dZG dd dZG dd dZG dd dZG dd dZ dd Z!ej"#dddgdd Z$dd Z%ej"#dddgd d! Z&d"d# Z'ej"#d$dej(e)d%eegd&d' Z*dS )(    N)datedatetime	timedeltatimezone)gettztzoffsettzutc)NpyDatetimeUnit)PY310)OutOfBoundsDatetime)NANaTPeriod	Timedelta	Timestampc                   @   s  e Zd Zejdeegdd Zejdeegdd Z	dd Z
ejdd	i gd
ddigdddigdddigddddgdddddgddddgddddgddddgddddgd dd!dgd"dd#dgddddgd$dd!d!dgddddgd%dd&dggd'd( Zd)S )*#TestTimestampConstructorUnitKeywordtypc                 C   sL   |d}t |dd}t d}||ksJ t |dd}t d}||ks$J d S )N   Yunitz
2120-01-01Mz
1982-07-01r   )selfr   valtsexpected r   c/var/www/html/myenv/lib/python3.10/site-packages/pandas/tests/scalar/timestamp/test_constructors.py'test_constructor_int_float_with_YM_unit"   s   zKTestTimestampConstructorUnitKeyword.test_constructor_int_float_with_YM_unitc                 C   sT   |d}d| d}t jt|d t|dd W d    d S 1 s#w   Y  d S )Nl    `n1! zcannot convert input z with the unit 'D'matchDr   pytestraisesr   r   )r   r   r   msgr   r   r   ;test_construct_from_int_float_with_unit_out_of_bound_raises/   s
   "z_TestTimestampConstructorUnitKeyword.test_construct_from_int_float_with_unit_out_of_bound_raisesc                 C   s~   d}t jt|d tddd W d    n1 sw   Y  t jt|d tddd W d    d S 1 s8w   Y  d S )Nz9Conversion of non-round float with unit=[MY] is ambiguousr    g     b@r   r   r   r$   r%   
ValueErrorr   r   r&   r   r   r   4test_constructor_float_not_round_with_YM_unit_raises8   s   "zXTestTimestampConstructorUnitKeyword.test_constructor_float_not_round_with_YM_unit_raiseszvalue, check_kwargsl    Bm@ig jr
Cr   usg  `kBmsg  6Asi*  r"   r   )r   hgb6Ai  i  )r   r,   nsg  6Ai  )r   r,   g `kBi  gyr
Cg W`kBg(jr
C   g@s
Ci  g) `kBg    f@   c                 C   s   ddd}||fi | d S )N   r   c                 S   s   t | |d}|jdksJ |jdksJ |jdksJ |j|ks"J |dkr<|jdks-J |j|ks4J |j|ks;J n|jdksCJ |jdksJJ |jdksQJ |j|ksXJ d S )Nr     r3   r"   r   )	r   yearmonthdayhourminutesecondmicrosecond
nanosecond)valuer   r/   r.   r,   r0   stampr   r   r   check^   s   zKTestTimestampConstructorUnitKeyword.test_construct_with_unit.<locals>.check)Nr3   r3   r   r   r   )r   r=   check_kwargsr?   r   r   r   test_construct_with_unitB   s   
z<TestTimestampConstructorUnitKeyword.test_construct_with_unitN)__name__
__module____qualname__r$   markparametrizeintfloatr   r'   r+   rA   r   r   r   r   r   !   s>    






r   c                   @   s|  e Zd Zdd Zdd Zejdddgejdd	d
e	d	dde
dddddddejdgdd Zejdddgejdddgdd Zz	dedgZW n ejy`   dgZY nw ejdeejddddde
ddddddddddfe
ddddddddddfgd d! Zejddgejd"e
ddddddddd#fe
ddddddddd$fgd%d& ZdS )'#TestTimestampConstructorFoldKeywordc                 C   sD   d}t jt|d tddd W d    d S 1 sw   Y  d S )Nz5Valid values for the fold argument are None, 0, or 1.r    {      foldr(   r*   r   r   r   -test_timestamp_constructor_invalid_fold_raiser   s   "zQTestTimestampConstructorFoldKeyword.test_timestamp_constructor_invalid_fold_raisec              
   C   s`   d}t d}tjt|d ttddddddd|dd	 W d    d S 1 s)w   Y  d S )
NzBpytz timezones do not support fold. Please use dateutil timezones.Europe/Londonr      
      r      tzrM   )pytzr   r$   r%   r)   r   r   )r   r&   rU   r   r   r   *test_timestamp_constructor_pytz_fold_raisey   s
   
 "zNTestTimestampConstructorFoldKeyword.test_timestamp_constructor_pytz_fold_raiserM   r   r3   ts_input    P7-f. gP[YѵCr0   2019-10-27 01:30:00+01:00rP   rQ   rR   rS   tzinfoc                 C   sD   d}t jt|d t||d W d    d S 1 sw   Y  d S )NzCannot pass fold with possibly unambiguous input: int, float, numpy.datetime64, str, or timezone-aware datetime-like. Pass naive datetime-like or build Timestamp from components.r    )rX   rM   r(   )r   rX   rM   r&   r   r   r   (test_timestamp_constructor_fold_conflict   s
   "zLTestTimestampConstructorFoldKeyword.test_timestamp_constructor_fold_conflictrU   dateutil/Europe/LondonNc              	   C   s0   t ddddd||d}|j}|}||ksJ d S )NrP   rQ   rR   r3   rS   )r5   r6   r7   r8   r9   rU   rM   r   rM   )r   rU   rM   r   resultr   r   r   r   &test_timestamp_constructor_retain_fold   s   zJTestTimestampConstructorFoldKeyword.test_timestamp_constructor_retain_foldrO   zts_input,fold_out)rY   r   )l    pFs. r3   )rZ   r   )z2019-10-27 01:30:00+00:00r3   rL   c                 C   s&   t ||d}|j}|}||ksJ d S )NrU   r_   )r   rU   rX   fold_outr   r`   r   r   r   r   0test_timestamp_constructor_infer_fold_from_value   s   zTTestTimestampConstructorFoldKeyword.test_timestamp_constructor_infer_fold_from_valuezts_input,fold,value_outl    RzweW, l    v$iW, c                 C   s(   t |||d}|j}|}||ksJ d S )NrT   r   _value)r   rU   rX   rM   	value_outr   r`   r   r   r   r   0test_timestamp_constructor_adjust_value_for_fold   s   zTTestTimestampConstructorFoldKeyword.test_timestamp_constructor_adjust_value_for_fold)rB   rC   rD   rN   rW   r$   rE   rF   np
datetime64r   r   utcr]   ra   zoneinfoZoneInfo_tzsZoneInfoNotFoundErrorrd   rh   r   r   r   r   rI   q   sX    	


	rI   c                   @   s~   e Zd Zdd Zdd Zejdg ddd Zejd	i d
didddgdd Z	dd Z
ejdg ddd ZdS )3TestTimestampConstructorPositionalAndKeywordSupportc              	   C   s  t rdnd}tjt|d tdd W d    n1 sw   Y  d}tjt|d tddd W d    n1 s<w   Y  tjt|d tddd W d    n1 sYw   Y  d	}tjt|d tddd W d    n1 sxw   Y  tjt|d tddd
 W d    n1 sw   Y  ttdddttdksJ ttdddddddttdksJ d S )Nz5'NoneType' object cannot be interpreted as an integerzan integer is requiredr    r4   r3   month must be in 1..12r      day is out of range for month         r2   20151112rK      ?B 2015-11-12 01:02:03.999999)r
   r$   r%   	TypeErrorr   r)   reprr*   r   r   r   test_constructor_positional   s2    zOTestTimestampConstructorPositionalAndKeywordSupport.test_constructor_positionalc              
   C   s  d}t jt|d tddd W d    n1 sw   Y  d}t jt|d tdddd W d    n1 s:w   Y  t jt|d tdd	dd W d    n1 sXw   Y  d
}t jt|d tdddd W d    n1 sxw   Y  t jt|d tdddd W d    n1 sw   Y  ttddddttdksJ ttddddddddttdksJ d S )Nz@function missing required argument 'day'|Required argument 'day'r    r4   r3   r5   r6   rq   r   )r5   r6   r7   rr   rs   rt   ru   rv   r2   rw   rK   rx   ry   )r5   r6   r7   r8   r9   r:   r;   rz   )r$   r%   r{   r   r)   r|   r*   r   r   r   test_constructor_keyword   sD   


zLTestTimestampConstructorPositionalAndKeywordSupport.test_constructor_keywordargr5   r6   r7   r8   r9   r:   r;   r<   c                 C   sN   |di}d}t jt|d tdi | W d    d S 1 s w   Y  d S )Nr3   z-Cannot pass a date attribute keyword argumentr    2010-10-10 12:59:59.999999999)r   r(   )r   r   kwargr&   r   r   r   )test_invalid_date_kwarg_with_string_input  s
   "z]TestTimestampConstructorPositionalAndKeywordSupport.test_invalid_date_kwarg_with_string_inputkwargsr5     r3   r~   c                 C   sX   d}d}d ||g}tjt|d tdi | W d    d S 1 s%w   Y  d S )NzCfunction missing required argument '(year|month|day)' \(pos [123]\)z<Required argument '(year|month|day)' \(pos [123]\) not found|r    r   )joinr$   r%   r{   r   )r   r   msg1msg2r&   r   r   r    test_constructor_missing_keyword%  s   "zTTestTimestampConstructorPositionalAndKeywordSupport.test_constructor_missing_keywordc                 C   s0   t dddtjd}t dtjd}||ksJ d S )Nr   r2      r[   
2020-12-31)r   r   rk   )r   r   r   r   r   r   'test_constructor_positional_with_tzinfo1  s   z[TestTimestampConstructorPositionalAndKeywordSupport.test_constructor_positional_with_tzinfokwd)r<   r;   r:   r9   c           	      C   sx   |dkrt jjdd}|| |di}tddtji|}|d di}td
i |}tdtjd	| }||ks:J d S )Nr<   zGH#45307)reason   )r   r2   r   r\   r.   r   rb   r   )r$   rE   xfailapplymarkerr   r   rk   r   )	r   r   requestrE   r   r   	td_kwargstdr   r   r   r   5test_constructor_positional_keyword_mixed_with_tzinfo7  s   
ziTestTimestampConstructorPositionalAndKeywordSupport.test_constructor_positional_keyword_mixed_with_tzinfoN)rB   rC   rD   r}   r   r$   rE   rF   r   r   r   r   r   r   r   r   rp      s    "

rp   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )$TestTimestampClassMethodConstructorsc                 C   sL   d}d}d}t jt|d t|| W d    d S 1 sw   Y  d S )Nz%Y%m%d-%H%M%S-%f%zz20190129-235348-000001+0000z)Timestamp.strptime\(\) is not implementedr    )r$   r%   NotImplementedErrorr   strptime)r   fmtr   r&   r   r   r   test_constructor_strptimeL  s   "z>TestTimestampClassMethodConstructors.test_constructor_strptimec                 C   sN   t d}tddd}t ddd}||ksJ ||ksJ t|t s%J d S )Nz2000-01-03 00:00:00r4   r3   )r   r   fromisocalendar
isinstance)r   expected_timestampexpected_stdlibr`   r   r   r    test_constructor_fromisocalendarU  s   zETestTimestampClassMethodConstructors.test_constructor_fromisocalendarc                 C   s   t ddd}t| }||ksJ | | ksJ tj| dd}tddd|ks0J | | ks:J t dddd	d	}t| }| |ksQJ td
dd}| }tj| dd}| |kslJ d S )Nr4   r3   
US/Easternrb   z
2000-01-01i  r      r   z	2011-4-16)r   r   fromordinal	toordinalto_pydatetime)r   baser   dtr>   dt_tzr   r   r   test_constructor_fromordinal^  s   zATestTimestampClassMethodConstructors.test_constructor_fromordinalc                 C      t d}t  }t }t ddd}t jdd}tdd}t|| |k s'J t|| |k s1J t|| |k s;J t|d |d  |k sKJ d S )Nnowr   rb   r3   seconds)r   r   r   r   abstz_localizer   ts_from_stringts_from_methodts_datetimets_from_string_tzts_from_method_tzdeltar   r   r   test_nowt  s    
z-TestTimestampClassMethodConstructors.test_nowc                 C   r   )Ntodayr   rb   r3   r   )r   r   r   r   r   r   r   r   r   r   
test_today  s    
z/TestTimestampClassMethodConstructors.test_todayN)rB   rC   rD   r   r   r   r   r   r   r   r   r   r   I  s    		r   c                   @   s6   e Zd Zdd Zdd Zejdddgdd	 Zd
S ) TestTimestampResolutionInferencec                 C   s   t d}|jdksJ d S )Nz01:01:01.111r-   r   r   r   r   r   r   r   test_construct_from_time_unit  s   z>TestTimestampResolutionInference.test_construct_from_time_unitc                 C   s  t d}|jdksJ t d}|jdksJ t d}|jdks!J t d}|jdks,J t d}|jdks7J t d}|jdksBJ t d	}|jd
ksMJ t d}|jdksXJ t d}|t dksdJ |jd
kskJ t d}|jdksvJ t d}|jdksJ d S )Nz
01/30/2023r.   2015Q1z2016-01-01 1:30:01 PMz2016 June 3 15:25:01.345r-   z	300-01-01z300 June 1:30:01.300z"01-01-2013T00:00:00.000000000+0000r0   z2016/01/02 03:04:05.001000 UTCr,   z%01-01-2013T00:00:00.000000002100+0000z"01-01-2013T00:00:00.000000002+0000z2020-01-01 00:00+00:00z2020-01-01 00+00:00r   r   r   r   r   test_constructor_str_infer_reso  s.   z@TestTimestampResolutionInference.test_constructor_str_infer_resomethodr   r   c                 C   s8   t t| }t|}|j|j  krdksJ  J d S )Nr,   )getattrr   r   )r   r   r   r   r   r   r   test_now_today_unit  s   $z4TestTimestampResolutionInference.test_now_today_unitN)	rB   rC   rD   r   r   r$   rE   rF   r   r   r   r   r   r     s
    +r   c                   @   s  e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zejdeedddddddddedddddddddedddddddddd 	edddddddd!dd	edddddddejdd"	gd#d$ Zejd%d&d'gd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zejjd2d3 Zejd4d5d6gd7d8 Zd9d: Zd;d< Zejd=d>d?gd@dA Zejd4dBdCgdDdE Z ejdFeegdGdH Z!dIdJ Z"dKdL Z#dMdN Z$dOdP Z%dQdR Z&ejdSe'dTe(dTdTdUgdVdW Z)d!S )XTestTimestampConstructorsc                 C   @   d}t jt|d td W d    d S 1 sw   Y  d S )NzFParsing datetimes with weekday but no day information is not supportedr    z2023 Sept Thur(   r*   r   r   r   test_weekday_but_no_day_raises  s   
"z8TestTimestampConstructors.test_weekday_but_no_day_raisesc                 C   s<   t jtdd td W d    d S 1 sw   Y  d S )Nzgives an invalid tzoffsetr    z200622-12-31r(   r   r   r   r   )test_construct_from_string_invalid_raises  s   
"zCTestTimestampConstructors.test_construct_from_string_invalid_raisesc                 C   s\   t d}|jdksJ t d}|jdksJ t d}|jdks!J t d}|jdks,J d S )	Nz2016-01-01 04:05:06-01:00r.   z2016-01-01 04:05:06.000-01:00r-   z 2016-01-01 04:05:06.000000-01:00r,   z#2016-01-01 04:05:06.000000001-01:00r0   r   r   r   r   r   2test_constructor_from_iso8601_str_with_offset_reso  s   zLTestTimestampConstructors.test_constructor_from_iso8601_str_with_offset_resoc                 C   s&   t ddd}t|}|jdksJ d S )N  	   r3   r.   )r   r   r   )r   objr   r   r   r   &test_constructor_from_date_second_reso  s   z@TestTimestampConstructors.test_constructor_from_date_second_resoc                 C   sF   t d}d}t||d}t||}||ksJ |jdks!J d S )Nz1970-01-01 05:00:00z	UTC+05:00rb   r1   )ri   rj   r   r   r8   )r   r   tzstrr   altr   r   r   #test_constructor_datetime64_with_tz  s   
z=TestTimestampConstructors.test_constructor_datetime64_with_tzc                 C   s  d}t dddd}d}t| d |ksJ |||fdt dddd	|d
 fdt ddddddd|d fdtd|d fg}ddtjdfdddtddftj	
d ddfg}|D ]\}}}t|t|fD ]}	|	d}	|	dj|ksxJ t|	}	|	dj|ksJ qg|D ]\\}
}t||
dt||
dfD ]K}	|	d}	||d d  }|	dj|ksJ t|	}	|	dj|ksJ |
d urt|	d}	nt|	dd}	||d d  }|	dj|ksJ qqqZd S )Nz2014-07-01 09:00     r3   r        t  ʚ;z2014-07-01 10:00rQ        qaz2014-07-01 09:00:00.000008000r      @  z2014-07-01 09:00:00.000000005r1   Nr   UTCr   
Asia/Tokyor   r   zdateutil/US/PacificiLPF  r0   rb   i  r   )r   calendartimegm	timetupler   rV   rk   FixedOffsetdateutilrU   r   as_unitrf   
tz_convert)r   base_strbase_dtbase_expectedtests	timezonesdate_strdate_objr   r`   rU   offsetexpected_tzexpected_utcr   r   r   test_constructor  sd   
z*TestTimestampConstructors.test_constructorc                 C   sz  d}t dddd}d}t| d |ksJ ||fd|d	 fd
|d fd|d fg}ddtjdfdddtddftj	d ddfg}|D ]^\}}t
|fD ]}|dj|ks\J t
|}|dj|ksjJ qP|D ]7\}	}
t
||	d}|}|dj|ksJ t
|}|dj|ksJ t
|d}|}|dj|ksJ qmqGt
ddd}|jt
djksJ d}t||ksJ |tt|ksJ t
ddd}|jt
djksJ d}t||ksJ |tt|ksJ t
d d!d}|jt
d"jksJ d#}t||ks	J |tt|ksJ t
d$d%d}|jt
d"jks%J d&}t||ks0J |tt|ks;J d S )'Nz2014-07-01 11:00:00+02:00r   r   r3   r   r   r   z2014-07-01 12:00:00+02:00r   z#2014-07-01 11:00:00.000008000+02:00r   z#2014-07-01 11:00:00.000000005+02:00r1   r   r   r   r   r   r   r   r   r   r0   rb   r   z2013-11-01 00:00:00-0500zAmerica/Chicagoz2013-11-01 05:00z;Timestamp('2013-11-01 00:00:00-0500', tz='America/Chicago')r   z6Timestamp('2013-11-01 14:00:00+0900', tz='Asia/Tokyo')z2015-11-18 15:45:00+05:45zAsia/Katmanduz2015-11-18 10:00z9Timestamp('2015-11-18 15:45:00+0545', tz='Asia/Katmandu')z2015-11-18 15:30:00+05:30Asia/Kolkataz8Timestamp('2015-11-18 15:30:00+0530', tz='Asia/Kolkata'))r   r   r   r   rV   rk   r   r   rU   r   r   r   rf   r   r|   eval)r   r   r   r   r   r   r   r   r`   rU   r   r   r   r   r   r   "test_constructor_with_stringoffsetS  sj   


z<TestTimestampConstructors.test_constructor_with_stringoffsetc                 C   s   d}t jt|d ttd W d    n1 sw   Y  d}t jt|d ttd W d    d S 1 s:w   Y  d S )NzCannot convert inputr    rK   zCannot convert Periodz
1000-01-01)r$   r%   r{   r   slicer)   r   r*   r   r   r   test_constructor_invalid  s   "z2TestTimestampConstructors.test_constructor_invalidc                 C   s   d}t jt|d tddd W d    n1 sw   Y  d}t jt|d tdtjdd W d    n1 s;w   Y  d	}t jt|d td
d W d    d S 1 sZw   Y  d S )NzJArgument 'tzinfo' has incorrect type \(expected datetime.tzinfo, got str\)r    z
2017-10-22r   r[   zat most one ofr   )r\   rU   zHCannot pass a date attribute keyword argument when passing a date stringz
2012-01-01
US/Pacific)r$   r%   r{   r   r)   rV   rk   r*   r   r   r   test_constructor_invalid_tz  s   "z5TestTimestampConstructors.test_constructor_invalid_tzc              
      s   t dddddt dddtjdt dddtjdt tdddtjdt tdddddt tdddtjdg t fd	d
 D sCJ d S )Ni  rQ      r   )r5   r6   r7   rU   r5   r6   r7   r\   r[   rb   c                 3   s    | ]	}| d  kV  qdS )r   Nr   ).0r   stampsr   r   	<genexpr>  s    zJTestTimestampConstructors.test_constructor_tz_or_tzinfo.<locals>.<genexpr>)r   rV   rk   r   allr   r   r   r   test_constructor_tz_or_tzinfo  s   z7TestTimestampConstructors.test_constructor_tz_or_tzinfor`   r4   r3   rK   rx   r   r1      )r<   r   r   )	r5   r6   r7   r8   r9   r:   r;   r<   rU   N)rU   r<   c              	   C   s<   t tddddddd|jd}|tdd	 }||ksJ d S )
Nr4   r3   rK   rx   r   r1   r  rb   )nanoseconds)r   r   rU   r   r   r`   r   r   r   r   test_constructor_nanosecond  s    z5TestTimestampConstructors.test_constructor_nanosecondzZ0Z00c                 C   sL   d| }t jt|d td|  W d    d S 1 sw   Y  d S )NzAUnknown datetime string format, unable to parse: 2014-11-02 01:00r    z2014-11-02 01:00r(   )r   r  r&   r   r   r   %test_constructor_invalid_Z0_isostring  s   
"z?TestTimestampConstructors.test_constructor_invalid_Z0_isostringc                 C   s   t tjjd }tjt|d ttjjd  W d    n1 s"w   Y  t tjjd }tjt|d ttjjd  W d    d S 1 sJw   Y  d S )NrK   r    )strr   maxrf   r$   r%   r   minr*   r   r   r    test_out_of_bounds_integer_value  s   "z:TestTimestampConstructors.test_out_of_bounds_integer_valuec                 C   s
  t dd}t tjd| }t tjd}t| t| tjj	}t|| j
|ks3J t|| j
|ks>J t dd}t dd}d}tjt|d t| W d    n1 sbw   Y  tjt|d t| W d    d S 1 s~w   Y  d S )	Nr3   ztimedelta64[us]zM8[us]z-292277022657-01-27T08:29mz292277026596-12-04T15:31zOut of boundsr    )ri   timedelta64astyperj   r   r  r  r	   	NPY_FR_usr=   _cresor$   r%   r)   )r   one_us	min_ts_us	max_ts_usus_valtoo_lowtoo_highr&   r   r   r   test_out_of_bounds_value  s"   

"z2TestTimestampConstructors.test_out_of_bounds_valuec                 C   s   d}t jt|d tdd W d    n1 sw   Y  t jt|d tdd W d    n1 s9w   Y  td}|jdksIJ td}|jdksTJ d S )Nz,Cannot cast .* to unit='ns' without overflowr    z
1676-01-01r0   z
2263-01-01r.   )r$   r%   r)   r   r   r   )r   r&   r   r   r   r   test_out_of_bounds_string$  s   z3TestTimestampConstructors.test_out_of_bounds_stringc                 C   r   )Nz7Out of bounds nanosecond timestamp: 2262-04-11 23:47:16r    z2262-04-11 23:47:16.854775808r#   r*   r   r   r   test_barely_out_of_bounds1  s   
"z3TestTimestampConstructors.test_barely_out_of_boundsc              
   C   s  d}d}|D ])}|D ]$}t ||}t|}|dv r%|j|dks$J q
|jtjjks.J q
qt 	t j
}d}|jd |jfD ](}	dD ]#}t |	|}tjt|d t| W d    n1 sbw   Y  qDq@d	}
|
D ]}|D ]}t ||}t| qqqmd S )
N)z
1677-09-21z
2262-04-12)r"   r/   r  r.   r-   r,   )r.   r-   r,   i8zOut of bounds second timestamp:r3   )r"   r/   r  r    )z
1677-09-23z
2262-04-11)ri   rj   r   rf   viewr  r	   NPY_FR_sr=   iinfoint64r  r  r$   r%   r   )r   out_of_bounds_dates
time_unitsdate_stringr   dt64r   infor&   r=   in_bounds_datesr   r   r    test_bounds_with_different_units9  s6   

z:TestTimestampConstructors.test_bounds_with_different_unitsr   z	001-01-01z
0001-01-01c                 C   s   d}t jt|d t|d W d    n1 sw   Y  t|}|jdks+J |j|j  kr>|j  kr>dksAJ  J d S )Nz=Cannot cast 0001-01-01 00:00:00 to unit='ns' without overflowr    r0   r.   r3   )	r$   r%   r   r   r   r   r5   r6   r7   )r   r   r&   r   r   r   r   %test_out_of_bounds_string_consistencyZ  s   0z?TestTimestampConstructors.test_out_of_bounds_string_consistencyc                 C      t t j d S N)r   r  r   r   r   r   test_min_valide     z(TestTimestampConstructors.test_min_validc                 C   r+  r,  )r   r  r   r   r   r   test_max_validi  r.  z(TestTimestampConstructors.test_max_validr   z+0300z+0200c                 C   s0   t d| dd}t |d}||ksJ d S )Nz2016-10-30 03:00:00zEurope/Helsinkirb   )r   r   )r   r   r   r`   r   r   r   !test_construct_timestamp_near_dstm  s   z;TestTimestampConstructors.test_construct_timestamp_near_dstz2013/01/01 00:00:00+09:00z2013-01-01 00:00:00+09:00c                 C   s2   t |}t tdddtdd}||ksJ d S )Ni  r3   i  rb   )r   r   rV   r   )r   r   r`   r   r   r   r   +test_construct_with_different_string_formatt  s   zETestTimestampConstructors.test_construct_with_different_string_formatboxc                 C   s   dddt jd}d}tjt|d t|d	i |dd W d    n1 s'w   Y  d}tjt|d t|d	i |t dd W d    d S 1 sOw   Y  d S )
N  r3   r   z#Cannot pass a datetime or Timestampr    r   rb   r[   r   )rV   rk   r$   r%   r)   r   r   )r   r2  r   r&   r   r   r   *test_raise_tz_and_tzinfo_in_datetime_input}  s   "zDTestTimestampConstructors.test_raise_tz_and_tzinfo_in_datetime_inputc                 C   s>   t tdddt d}t tdddt }||ksJ d S )Nr3  r3   rb   )r   r   r   r   r  r   r   r   *test_dont_convert_dateutil_utc_to_pytz_utc  s   zDTestTimestampConstructors.test_dont_convert_dateutil_utc_to_pytz_utcc                 C   s@   G dd dt }|ddd}t|}tddd}||ksJ d S )Nc                   @   s   e Zd ZdS )zSTestTimestampConstructors.test_constructor_subclassed_datetime.<locals>.SubDatetimeN)rB   rC   rD   r   r   r   r   SubDatetime  s    r6  r4   r3   )r   r   )r   r6  datar`   r   r   r   r   $test_constructor_subclassed_datetime  s
   z>TestTimestampConstructors.test_constructor_subclassed_datetimec                 C   sJ   t ddd}|jtju sJ |jdksJ t dd}|jdks#J d S )Nz3/11/2012 05:00rk   rb   r1   )r   r\   r   rk   r8   r   )r   	utc_stampr   r   r   !test_timestamp_constructor_tz_utc  s
   z;TestTimestampConstructors.test_timestamp_constructor_tz_utcc                 C   s2   t d d}td|d}t| }||ksJ d S )Ni   z3/11/2012 04:00rb   )r   r   r   )r   r\   r   r`   r   r   r   #test_timestamp_to_datetime_tzoffset  s   
z=TestTimestampConstructors.test_timestamp_to_datetime_tzoffsetc              	   C   s  dD ]5}t d|d}t d|}||ksJ d}tjtj|d t d|d W d    n1 s2w   Y  qt ddd}t dd}||ksKJ d	}tjtj|d t d	dd W d    n1 sfw   Y  t d
}|dd}t ddd}||ksJ t ddd}t ddd}||ksJ t ddd}t ddd}||ksJ d	}tjtj|d t d	dd W d    n1 sw   Y  t ddd}t |dj	}|dd}||ksJ t ddd}t ddd}||ksJ d S )N)zEurope/BrusselszEurope/Praguez2015-10-25 01:00rb   z.Cannot infer dst time from 2015-10-25 02:00:00r    z2015-10-25 02:00z2017-03-26 01:00zEurope/Parisz2017-03-26 02:00z2015-11-18 10:00:00r   r   z2015-11-18 15:30:00+0530z2017-03-26 00:00z2017-03-26 00:00:00+0100z2017-03-26 01:00:00+0100z2017-03-26 02:00:00+0100r0   z2017-03-26 03:00z2017-03-26 03:00:00+0200)
r   r   r$   r%   rV   AmbiguousTimeErrorNonExistentTimeErrorr   r   rf   )r   rU   r`   r   r&   naiver   r   r   ,test_timestamp_constructor_near_dst_boundary  sJ   zFTestTimestampConstructors.test_timestamp_constructor_near_dst_boundaryrU   r   zdateutil/US/Easternc                 C   s@   t tddd|d}t d|d}|j|jksJ ||ksJ d S )Nr   rx   rv   rb   z	3/11/2012)r   r   r8   )r   rU   r`   r   r   r   r   )test_timestamp_constructed_by_date_and_tz  s   zCTestTimestampConstructors.test_timestamp_constructed_by_date_and_tz)*rB   rC   rD   r   r   r   r   r   r   r   r   r   r  r$   rE   rF   r   r   rV   r   r  r  r  r  r  r  
skip_ubsanr)  r*  r-  r/  r0  r1  r4  r5  r8  r:  r;  r?  r   r   r@  r   r   r   r   r     s    
ET


	!
 





2	r   c                  C   s,   t ddd} | j}t | j}||ksJ d S )Nl     !F r^   rb   re   )r   r   r`   r   r   r   test_constructor_ambiguous_dst  s   
rB  epochl   ?2\BT, l   ?2\BT, c                 C   sD   t | dd}|j|}tdd}t |j| ksJ ||ks J d S )Nzdateutil/America/Los_Angelesrb   r   r   )r   rU   dstr   rf   )rC  r   r`   r   r   r   r   "test_constructor_before_dst_switch  s
   
rE  c                  C   s    t d} t | }|| u sJ d S )Nz2017-01-01T12r   )r   r`   r   r   r   #test_timestamp_constructor_identity  s   rF  nanoi  c                 C   sD   t jtdd tddd| d W d    d S 1 sw   Y  d S )Nznanosecond must be in 0..999r    i  r3   )r5   r6   r7   r<   r(   )rG  r   r   r   test_timestamp_nano_range  s   "rI  c                  C   sv   t dddj} | dksJ d}t d}tjt|d |j W d    n1 s(w   Y  |jd} | d	ks9J d S )
Nz
1800-01-01r.   r   l  'pS zCannot convert Timestamp to nanoseconds without overflow. Use `.asm8.view\('i8'\)` to cast represent Timestamp in its own unit \(here, s\).$z
0300-01-01r    r  ldW
1 )r   r=   r$   r%   OverflowErrorasm8r  )r`   r&   r   r   r   r   test_non_nano_value  s   rL  na_valuer   c                 C   s   t | }t}||u sJ d S r,  )r   r   )rM  r`   r   r   r   r   #test_timestamp_constructor_na_value'  s   rN  )+r   r   r   r   r   rl   dateutil.tzr   r   r   r   numpyri   r$   rV   pandas._libs.tslibs.dtypesr	   pandas.compatr
   pandas.errorsr   pandasr   r   r   r   r   r   rI   rp   r   r   r   rB  rE   rF   rE  rF  rI  rL  nanrj   rN  r   r   r   r   <module>   s>    	PbvY9    

