o
    LDi"                     @   sl  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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PY314)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   {/var/www/www-root/data/www/77.83.87.30/venv/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_raises2   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_raises;   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     r4   r#   r   )	r   yearmonthdayhourminutesecondmicrosecond
nanosecond)valuer   r0   r/   r-   r1   stampr   r   r   checka   s   zKTestTimestampConstructorUnitKeyword.test_construct_with_unit.<locals>.check)Nr4   r4   r   r   r   )r   r>   check_kwargsr@   r   r   r   test_construct_with_unitE   s   
z<TestTimestampConstructorUnitKeyword.test_construct_with_unitN)__name__
__module____qualname__r%   markparametrizeintfloatr    r(   r,   rB   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_raiseu   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      tzrN   )pytzr   r%   r&   r*   r   r   )r   r'   rV   r   r   r   *test_timestamp_constructor_pytz_fold_raise|   s
   
 "zNTestTimestampConstructorFoldKeyword.test_timestamp_constructor_pytz_fold_raiserN   r   r4   ts_input    P7-f. gP[YѵCr1   2019-10-27 01:30:00+01:00rQ   rR   rS   rT   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!   )rY   rN   r)   )r   rY   rN   r'   r   r   r   (test_timestamp_constructor_fold_conflict   s
   "zLTestTimestampConstructorFoldKeyword.test_timestamp_constructor_fold_conflictrV   dateutil/Europe/LondonNc              	   C   s0   t ddddd||d}|j}|}||ksJ d S )NrQ   rR   rS   r4   rT   )r6   r7   r8   r9   r:   rV   rN   r   rN   )r   rV   rN   r   resultr   r   r   r   &test_timestamp_constructor_retain_fold   s   zJTestTimestampConstructorFoldKeyword.test_timestamp_constructor_retain_foldrP   zts_input,fold_out)rZ   r   )l    pFs. r4   )r[   r   )z2019-10-27 01:30:00+00:00r4   rM   c                 C   s&   t ||d}|j}|}||ksJ d S )NrV   r`   )r   rV   rY   fold_outr   ra   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 )NrU   r   _value)r   rV   rY   rN   	value_outr   ra   r   r   r   r   0test_timestamp_constructor_adjust_value_for_fold   s   zTTestTimestampConstructorFoldKeyword.test_timestamp_constructor_adjust_value_for_fold)rC   rD   rE   rO   rX   r%   rF   rG   np
datetime64r   r   utcr^   rb   zoneinfoZoneInfo_tzsZoneInfoNotFoundErrorre   ri   r   r   r   r   rJ   t   sX    	


	rJ   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  trcd	}n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 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!   r5   r4   month must be in 1..12r      /must be in range 1..31 for month 1 in year 2000day is out of range for month         r3   20151112rL      ?B 2015-11-12 01:02:03.999999)r
   r%   r&   	TypeErrorr   r*   r   reprr+   r   r   r   test_constructor_positional   s6    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  trbd
}n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 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!   r5   r4   r6   r7   rr   r   )r6   r7   r8   rs   rt   ru   rv   rw   rx   r3   ry   rL   rz   r{   )r6   r7   r8   r9   r:   r;   r<   r|   )r%   r&   r}   r   r*   r   r~   r+   r   r   r   test_constructor_keyword   sH   


zLTestTimestampConstructorPositionalAndKeywordSupport.test_constructor_keywordargr6   r7   r8   r9   r:   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 )Nr4   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kwargsr6     r4   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   r3      r\   
2020-12-31)r   r   rl   )r   r   r   r   r   r   'test_constructor_positional_with_tzinfo:  s   z[TestTimestampConstructorPositionalAndKeywordSupport.test_constructor_positional_with_tzinfokwd)r=   r<   r;   r:   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   r3   r   r]   r/   r   rc   r   )r%   rF   xfailapplymarkerr   r   rl   r   )	r   r   requestrF   r   r   	td_kwargstdr   r   r   r   5test_constructor_positional_keyword_mixed_with_tzinfo@  s   
ziTestTimestampConstructorPositionalAndKeywordSupport.test_constructor_positional_keyword_mixed_with_tzinfoN)rC   rD   rE   r   r   r%   rF   rG   r   r   r   r   r   r   r   r   rq      s    %

rq   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_strptimeU  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:00r5   r4   )r   r   fromisocalendar
isinstance)r   expected_timestampexpected_stdlibra   r   r   r    test_constructor_fromisocalendar^  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 )Nr5   r4   
US/Easternrc   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_fromordinalg  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   rc   r4   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_now}  s    
z-TestTimestampClassMethodConstructors.test_nowc                 C   r   )Ntodayr   rc   r4   r   )r   r   r   r   r   r   r   r   r   r   
test_today  s    
z/TestTimestampClassMethodConstructors.test_todayN)rC   rD   rE   r   r   r   r   r   r   r   r   r   r   R  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+0000r1   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)	rC   rD   rE   r   r   r%   rF   rG   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:00r1   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  	   r4   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:00rc   r2   )rj   rk   r   r   r9   )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     r4   r        t  ʚ;z2014-07-01 10:00rR        qaz2014-07-01 09:00:00.000008000r      @  z2014-07-01 09:00:00.000000005r2   Nr   UTCr   
Asia/Tokyor   r   zdateutil/US/PacificiLPF  r1   rc   i  r   )r   calendartimegm	timetupler   rW   rl   FixedOffsetdateutilrV   r   as_unitrg   
tz_convert)r   base_strbase_dtbase_expectedtests	timezonesdate_strdate_objr   ra   rV   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   r4   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:00r2   r   r   r   r   r   r   r   r   r   r1   rc   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   rW   rl   r   r   rV   r   r   r   rg   r   r~   eval)r   r   r   r   r   r   r   r   ra   rV   r   r   r   r   r   r   "test_constructor_with_stringoffset\  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!   rL   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]   rV   zHCannot pass a date attribute keyword argument when passing a date stringz
2012-01-01
US/Pacific)r%   r&   r}   r   r*   rW   rl   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  rR      r   )r6   r7   r8   rV   r6   r7   r8   r]   r\   rc   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   rW   rl   r   allr   r   r  r   test_constructor_tz_or_tzinfo  s   z7TestTimestampConstructors.test_constructor_tz_or_tzinfora   r5   r4   rL   rz   r   r2      )r=   r   r   )	r6   r7   r8   r9   r:   r;   r<   r=   rV   N)rV   r=   c              	   C   s<   t tddddddd|jd}|tdd	 }||ksJ d S )
Nr5   r4   rL   rz   r   r2   r  rc   )nanoseconds)r   r   rV   r   r   ra   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 )NrL   r!   )strr   maxrg   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 )	Nr4   ztimedelta64[us]zM8[us]z-292277022657-01-27T08:29mz292277026596-12-04T15:31zOut of boundsr!   )rj   timedelta64astyperk   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-01r1   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_bounds:  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#   r0   r  r/   r.   r-   )r/   r.   r-   i8zOut of bounds second timestamp:r4   )r#   r0   r  r!   )z
1677-09-23z
2262-04-11)rj   rk   r   rg   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_unitsB  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!   r1   r/   r4   )	r%   r&   r   r   r   r   r6   r7   r8   )r   r   r'   r   r   r   r   %test_out_of_bounds_string_consistencyc  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_validn     z(TestTimestampConstructors.test_min_validc                 C   r-  r.  )r   r  r   r   r   r   test_max_validr  r0  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/Helsinkirc   )r   r   )r   r   r   ra   r   r   r   !test_construct_timestamp_near_dstv  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  r4   i  rc   )r   r   rW   r   )r   r   ra   r   r   r   r   +test_construct_with_different_string_format}  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  r4   r   z#Cannot pass a datetime or Timestampr!   r   rc   r\   r   )rW   rl   r%   r&   r*   r   r   )r   r4  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 )Nr5  r4   rc   )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)rC   rD   rE   r   r   r   r   SubDatetime  s    r8  r5   r4   )r   r   )r   r8  datara   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:00rl   rc   r2   )r   r]   r   rl   r9   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:00rc   )r   r   r   )r   r]   r   ra   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:00rc   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+0100r1   z2017-03-26 03:00z2017-03-26 03:00:00+0200)
r   r   r%   r&   rW   AmbiguousTimeErrorNonExistentTimeErrorr   r   rg   )r   rV   ra   r   r'   naiver   r   r   ,test_timestamp_constructor_near_dst_boundary  sJ   zFTestTimestampConstructors.test_timestamp_constructor_near_dst_boundaryrV   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   rz   rx   rc   z	3/11/2012)r   r   r9   )r   rV   ra   r   r   r   r   )test_timestamp_constructed_by_date_and_tz  s   zCTestTimestampConstructors.test_timestamp_constructed_by_date_and_tz)*rC   rD   rE   r   r   r   r   r   r   r   r   r   r  r%   rF   rG   r   r   rW   r   r	  r  r  r  r  r  
skip_ubsanr+  r,  r/  r1  r2  r3  r6  r7  r:  r<  r=  rA  r   r   rB  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_   rc   rf   )r   r   ra   r   r   r   test_constructor_ambiguous_dst  s   
rD  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_Angelesrc   r   r   )r   rV   dstr   rg   )rE  r   ra   r   r   r   r   "test_constructor_before_dst_switch  s
   
rG  c                  C   s    t d} t | }|| u sJ d S )Nz2017-01-01T12r   )r   ra   r   r   r   #test_timestamp_constructor_identity  s   rH  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  r4   )r6   r7   r8   r=   r)   )rI  r   r   r   test_timestamp_nano_range  s   "rK  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!  )ra   r'   r   r   r   r   test_non_nano_value  s   rN  na_valuer   c                 C   s   t | }t}||u sJ d S r.  )r   r   )rO  ra   r   r   r   r   #test_timestamp_constructor_na_value0  s   rP  ),r   r   r   r   r   rm   dateutil.tzr   r   r   r   numpyrj   r%   rW   pandas._libs.tslibs.dtypesr	   pandas.compatr
   r   pandas.errorsr   pandasr   r   r   r   r   r   rJ   rq   r   r   r   rD  rF   rG   rG  rH  rK  rN  nanrk   rP  r   r   r   r   <module>   s>    	Pb|Y9    

