o
    ҷh                     @  s  d dl mZ d dlZd dl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mZmZmZm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mZ ejg dd	d
d Zejdd Zejdd Z ejdd Z!G dd dZ"G dd de"Z#G dd de"Z$ej%&dej%&dG dd de"Z'ej%j(deg dj)ee*ddffej+d d!d"d#j)ee,ddffej-d d!d"d#j)effgd$d% d&d'd( Z.ej%j(d)eg dj)e,ddej/ffej+d d!d"d#j)e*ddej/ffej-d d!d"d#j)e,dde*ddej/ffgd*d% d&d+d, Z0ej%(d-ej+d.d/d0j1ej2d.d/d0j1gd1d2 Z3ej%(d3d4d5gej%(d6e4d7d8ged9d:gd"d;ed7d8gd"d<gej%(d=e5ej1ej1ej6ej7ej8ej9gd>d? Z:ej%(d6e4d7d8ged9d:gd"d;ed7d8gd"d<gej%(d@d9d:gdAdBge
d7dCdDgd: gdEdF Z;ej%(d=e5e<ej1ej6gdGdH Z=ej%(dIdJdKgdLdM Z>dS )N    )annotationsN)NaTOutOfBoundsDatetime	Timestamp)DatetimeIndexPeriodPeriodIndexTimedeltaIndex)DatetimeArrayNumpyExtensionArrayPeriodArrayTimedeltaArray)_sequence_to_dt64ns)sequence_to_td64ns)DBWMQY)paramsc                 C  s   | j S )z:Fixture returning parametrized frequency in string format.)param)request r   X/var/www/html/venv/lib/python3.10/site-packages/pandas/tests/arrays/test_datetimelike.pyfreqstr"   s   r   c                 C  sR   t   t jddtd tjtdd| d}W d   |S 1 s"w   Y  |S )z
    A fixture to provide PeriodIndex objects with different frequencies.

    Most PeriodArray behavior is already tested in PeriodIndex tests,
    so here we just test that the PeriodArray behavior matches
    the PeriodIndex behavior.
    ignorezPeriod with BDay freq)messagecategory
2000-01-01d   startperiodsfreqN)warningscatch_warningsfilterwarningsFutureWarningpdperiod_ranger   )r   pir   r   r   period_index(   s   


r,   c                 C  s   t jtdd| d}|S )z
    A fixture to provide DatetimeIndex objects with different frequencies.

    Most DatetimeArray behavior is already tested in DatetimeIndex tests,
    so here we just test that the DatetimeArray behavior matches
    the DatetimeIndex behavior.
    r   r    r!   )r)   
date_ranger   )r   dtir   r   r   datetime_index;   s   
r/   c                   C  s   t g dS )a  
    A fixture to provide TimedeltaIndex objects with different frequencies.
     Most TimedeltaArray behavior is already tested in TimedeltaIndex tests,
    so here we just test that the TimedeltaArray behavior matches
    the TimedeltaIndex behavior.
    1 Day3 Hoursr   )r	   r   r   r   r   timedelta_indexI   s   	r3   c                   @  s  e Zd ZU ded< ejdd Zdd Zej	de
jdd	d
e
jdd	dde
jdd	d
e
jdd	ddgdd Zej	dddgej	dddgdd Zdd Zej	dddedddd jgd!d" Zd#d$ Zejd%d&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zej	d2d3d4gd5d6 Zd7d8 Zej	d9g d:d;d< Zd=d> Zd?d@ Z dAdB Z!dCdD Z"dEdF Z#ej	d9e
j$e
j%e&j'e(e)gdGdH Z*dIdJ Z+ej	dddgdKdL Z,dMdN Z-ej	d9e(e&j'e
j$e
j%gdOdP Z.dQdR Z/dSdT Z0dUdV Z1dWdX Z2dYS )ZSharedTestsz2type[DatetimeIndex | PeriodIndex | TimedeltaIndex]	index_clsc                 C  s,   t jdddd d d }| j|dd}|S )	z5Fixture returning DatetimeArray with daily frequency.
   i8dtype      ʚ;r   r$   )nparange	array_cls)selfdataarrr   r   r   arr1dX   s   zSharedTests.arr1dc                 C  s   |}|  |}tjtdd ||d d k W d    n1 s!w   Y  tjtdd ||dg k W d    d S 1 s@w   Y  d S )NzLengths must matchmatch   r   )r5   pytestraises
ValueError)rA   rD   rC   idxr   r   r   test_compare_len1_raises_   s   
"z$SharedTests.test_compare_len1_raisesresult2020   r#   UTC)r#   tzz0 days2020Q1r   r#   r$   c                 C  s.   t |}t||ksJ t||krJ d S N)r)   Categoricalallany)rA   rM   expectedr   r   r   test_compare_with_Categoricall   s   

z)SharedTests.test_compare_with_CategoricalreverseTFas_indexc                 C  s   t j||d}|rt |}||}}|r||}}tj|jtd}| }	||k}
t|
| ||k}
t|
|	 |sg|si||k }
t|
|	 ||k}
t|
| ||k}
t|
|	 ||k}
t|
| d S d S d S )N)orderedr8   )	r)   rV   CategoricalIndexr>   onesshapebooltmassert_numpy_array_equal)rA   rD   r\   r[   r]   otherleftrightr_   zerosrM   r   r   r   test_compare_categorical_dtypez   s,   


z*SharedTests.test_compare_categorical_dtypec                 C  s   t jdddd d d }t jd| | jtu r"t|dd}n| |}| j|}g d	}|	|}|	|}t
| || t g d	}|	|}|	|}t
| || d S )
Nr    r7   r8   r:   r;   r<      	period[D])rG      ^   )r>   r?   randomdefault_rngshuffler@   r   r5   _simple_newtakerb   assert_index_equalarray)rA   rB   rC   rK   takersrM   rY   r   r   r   	test_take   s   





zSharedTests.test_take
fill_valueri   g       @i  rG      c                 C  sX   d|j j d}tjt|d |jddgd|d W d    d S 1 s%w   Y  d S )Nvalue should be a '' or 'NaT'. GotrE   r   rG   T
allow_fillrv   )_scalar_type__name__rH   rI   	TypeErrorrq   )rA   rv   rD   msgr   r   r   test_take_fill_raises   s   "z!SharedTests.test_take_fill_raisesc                 C  s   t jdddd d d  |}|jddgd	d d
}|d tu s!J |jddgd	t jd
}|d tu s4J |jddgd	td
}|d tu sFJ d S )Nr6   r7   r8   r:   r;   r<   rG   Trz   r   )r>   r?   rq   r   nan)rA   rD   rC   rM   r   r   r   test_take_fill   s   zSharedTests.test_take_fill8ignore:Period with BDay freq is deprecated:FutureWarningc                 C  s   |j ddgdt|d d}|ddg }t|| d|jj d}tjt|d |j ddgddd W d    d S 1 s?w   Y  d S )	Nr   rG   Trz   rx   ry   rE   foo)	rq   strrb   assert_equalr|   r}   rH   rI   r~   rA   rD   rM   rY   r   r   r   r   test_take_fill_str   s   "zSharedTests.test_take_fill_strc                 C  s   |}|  |}|dt}| |}||d d |dd  |g}|t}|  t|d d |dd  |gd }t	
|  || d S )Nr   r   rG   )r5   insertr   r@   _concat_same_typeastypeobjectr>   concatenaterb   rr   )rA   rD   rC   rK   rM   arr2rY   r   r   r   test_concat_same_type   s   

 
(z!SharedTests.test_concat_same_typec                 C  s   | |d }|jjj}t||sJ | t}t||sJ d| jj d}tj	t
|d | d W d    d S 1 s?w   Y  d S )Nr   z'value' should be a .rE   r   )_unbox_scalar_ndarrayr9   type
isinstancer   scalar_typer}   rH   rI   rJ   r   r   r   r   test_unbox_scalar   s   

"zSharedTests.test_unbox_scalarc                 C  s.   | |d  | |d d  | t d S )Nr   rG   )_check_compatible_withr   rA   rD   r   r   r   test_check_compatible_with   s   z&SharedTests.test_check_compatible_withc                 C  s&   | t|d }||d ksJ d S )Nr   )_scalar_from_stringr   )rA   rD   rM   r   r   r   test_scalar_from_string   s   z#SharedTests.test_scalar_from_stringc                 C  sB   d}t jt|d |d W d    d S 1 sw   Y  d S )Nz)does not support reduction 'not a method'rE   znot a method)rH   rI   r~   _reduce)rA   rD   r   r   r   r   test_reduce_invalid   s   "zSharedTests.test_reduce_invalidmethodpadbackfillc                 C  s   t jdddd d d }| jtu r| j|dd}n| |}t|d< |d	kr+|d
 n|d }|j|d}|d |ks=J |d tu sEJ d S )Nr6   r7   r8   r:   r;   r<   rj   rk   r   rO      )r   )r>   r?   r@   r   r   _pad_or_backfill)rA   r   rB   rC   rv   rM   r   r   r   %test_fillna_method_doesnt_change_orig   s   

z1SharedTests.test_fillna_method_doesnt_change_origc                 C  s   t jdddd d d }| jtu r| j|dd}n| |}||d }|dks,J |j|d	 d
d}|dks;J ||dd }t jdd	gt jd}t|| |j|dd d
d}t jd	dgt jd}t|| |t	}|dkszJ d S )Nr6   r7   r8   r:   r;   r<   rj   rG   ri   rf   siderO   )
r>   r?   r@   r   searchsortedrs   intprb   rc   r   )rA   rB   rC   rM   rY   r   r   r   test_searchsorted  s    


zSharedTests.test_searchsortedbox)Nindexseriesc              
   C  s  |}|d u rn|dkr|  |}nt|}|t|d }|dks%J |jt|d dd}|dks6J |dd |dd D }tjddgtjd	}t	|| t
jttd
|jj dd |d W d    n1 stw   Y  |dkrd}n	|dkrd}nd}td|? t
jttd
|jj d| dd |t|d dg W d    n1 sw   Y  W d    d S W d    d S 1 sw   Y  d S )Nr   rG   ri   rf   r   rO   c                 S     g | ]}t |qS r   r   .0xr   r   r   
<listcomp>:      zBSharedTests.test_searchsorted_castable_strings.<locals>.<listcomp>r8   rx   z/', 'NaT', or array of those. Got 'str' instead.rE   r   pythonStringArraypyarrowArrowStringArrayArrowStringArrayNumpySemanticsstring_storagez"', 'NaT', or array of those. Got 'z
' instead.baz)r5   r)   Seriesr   r   r>   rs   r   rb   rc   rH   rI   r~   reescaper|   r}   option_context)rA   rD   r   r   rC   rM   rY   arr_typer   r   r   "test_searchsorted_castable_strings'  sP   
	"z.SharedTests.test_searchsorted_castable_stringsc                 C  sv   t jdd tddD dd}| jtu r| j|dd}n| j|dd	}|d
  t|}|d
  t|}|d
  d S )Nc                 S  s   g | ]}t j| qS r   )r   _value)r   nr   r   r   r   [      zGSharedTests.test_getitem_near_implementation_bounds.<locals>.<listcomp>rG   r   r7   r8   z
period[ns]nsr=   r   )r>   asarrayranger@   r   r)   Indexr   )rA   i8valsrC   r   serr   r   r   'test_getitem_near_implementation_boundsX  s   


z3SharedTests.test_getitem_near_implementation_boundsc                 C  s   t ||jd d tjf |jd}|d d tjf }t|| |}t ||jd ddf |jd}|d ddf }t|| |d }|d }||ksNJ d S )Nr8   rO   r   )r   r   r   )r   r   r>   newaxisr9   rb   r   )rA   rD   rY   rM   arr2dr   r   r   test_getitem_2dh  s   " zSharedTests.test_getitem_2dc                 C  s~   |j d dtjf }t|j||jd}t|}t|dks J |D ]}t|t|s-J |j	dks4J |j|jks<J q"d S )NrO   r8   rG   )
r   r>   r   r   rp   r9   listlenr   ndim)rA   rD   data2dr   rM   r   r   r   r   test_iter_2dy  s   zSharedTests.test_iter_2dc              
   C  s   |j d dtjf }t|j||jd}t|}t|tr?dt|j	 d|d 
  d|d 
  d|d 
  d	|j 
}ndt|j	 d|d  d|d  d|d  d	|j 
}||ks`J d S )
NrO   r8   <z>
[
['r   z'],
['rG   ri   z']
]
Shape: (3, 1), dtype: )r   r>   r   r   rp   r9   reprr   r   r}   
_repr_base)rA   rD   r   r   rM   rY   r   r   r   test_repr_2d  s2   




zSharedTests.test_repr_2dc                 C  s   t jdddd d d }| jtu r| j|dd}n| j|dd	}|d
 |d< t jdddd d d }|d
 |d< t|j| |dd  |d d< |dd  |d d< t|j| d S )Nr6   r7   r8   r:   r;   r<   rj   r   r=   rG   r   ri   )r>   r?   r@   r   rb   rc   asi8rA   rB   rC   rY   r   r   r   test_setitem  s   
zSharedTests.test_setitemc                 C  s   |  d d d }|jjdv r|d }|}|tu rt|}n#|tju r-t|t}n|t	u r;|tj
|td}n||t}||d d < t|| d S )Nr   )mr   r8   )copyr9   kind
_with_freqr   r>   rs   r   r   r   r   rb   r   )rA   r   rD   rY   valsr   r   r   test_setitem_object_dtype  s   


z%SharedTests.test_setitem_object_dtypec                 C  s   |  }|dd  |ddg< |  }dd |dd  D |d d< t|| |  }|d |d< |  }t|d |d< t|| d S )Nr   r   rG   c                 S  r   r   r   r   r   r   r   r     r   z1SharedTests.test_setitem_strs.<locals>.<listcomp>ri   r   )r   rb   r   r   )rA   rD   rY   rM   r   r   r   test_setitem_strs  s   zSharedTests.test_setitem_strsc                 C  sd   |  d d d }t|ts|d }t|}|rt|}|d d d |d d < t|| d S )Nr   )	r   r   r   r   r)   rV   r^   rb   r   )rA   rD   r\   rY   catr   r   r   test_setitem_categorical  s   



z$SharedTests.test_setitem_categoricalc                 C  s  |d d }|d }t jtdd ||d< W d    n1 s w   Y  t jtdd t |d< W d    n1 s<w   Y  d}t jt|d |d g|g < W d    n1 s\w   Y  d	}t jt|d |d d
 |dd< W d    d S 1 sw   Y  d S )Nr6   r   zindex 12 is out of boundsrE   rw   zvalue should be a.* 'object'z<cannot set using a list-like indexer with a different lengthrG   z=cannot set using a slice indexer with a different length thanrO   )rH   rI   
IndexErrorr~   r   rJ   )rA   rD   rC   valr   r   r   r   test_setitem_raises  s    
"zSharedTests.test_setitem_raisesc                 C  s   d|j j d}tjt|d |ddg|d d< W d    n1 s$w   Y  tjt|d |ddg|d d< W d    d S 1 sFw   Y  d S )	Nrx   z ', 'NaT', or array of those. GotrE   r   rG   ri   g        g      ?)r|   r}   rH   rI   r~   )rA   rD   r   r   r   r   r   test_setitem_numeric_raises  s   "z'SharedTests.test_setitem_numeric_raisesc                 C  s   t jdddd d d }| jtu r| j|dd}n| j|dd	}|tjd
d }|tjd
d7 }t|| |tjd
d }|tjd
d8 }t|| d S )Nr6   r7   r8   r:   r;   r<   rj   r   r=   rG   days)r>   r?   r@   r   r)   	Timedeltarb   r   r   r   r   r   test_inplace_arithmetic  s   
z#SharedTests.test_inplace_arithmeticc                 C  sB   t jtdd |jddd W d    d S 1 sw   Y  d S )Nzvalue should be arE   rG   )rv   )rH   rI   r~   shiftr   r   r   r   test_shift_fill_int_deprecated"  s   "z*SharedTests.test_shift_fill_int_deprecatedc                 C  s  |}t |d dkr|d d }|t |d  }| }t|t|u s&J ||ks,J t|t |d < t|tsM|t |d d t |d d   }|jddtu sWJ | }t|t|u seJ ||kskJ |d d  tu swJ |d d jddtu sJ |dd}|jd d}t|t|u sJ ||ksJ |jd ddtu sJ |jdd}t|j|g|j	d	}t
|| |jddd}t|jtg|j	d	}t
|| |jdd}t
|| |jddd}t
|| d S )
Nri   r   r   rG   F)skipna)axis)r   r   r8   )r   medianr   r   r   r   meanreshape_from_sequencer9   rb   r   )rA   rD   rC   rY   rM   r   	expected2r   r   r   test_median'  s>   
(zSharedTests.test_medianc                 C  sR   t jg dt jd}| j|| jd}tj|dd}| j|| jd}t|| d S )NrG   ri   rO   r8   Int64)r>   rs   int64r@   example_dtyper)   rb   assert_extension_array_equal)rA   rC   rY   rB   rM   r   r   r   test_from_integer_arrayW  s
   z#SharedTests.test_from_integer_arrayN)3r}   
__module____qualname____annotations__rH   fixturerD   rL   markparametrizer)   r-   timedelta_ranger*   rZ   rh   ru   r   timer   r   r'   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r>   rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r4   U   sx   
 

	!




0




0r4   c                   @  s   e Zd ZeZeZeZdZ	e
j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dd Zdd Ze
jdejdd Ze
jdejdd Zdd Zd d! Zd"d# Z d$d% Z!d&d' Z"d(S ))TestDatetimeArrayM8[ns]c                 C  s    |}t jdd||d}|j}|S )zc
        Fixture returning DatetimeArray with parametrized frequency and
        timezones
        z2016-01-01 01:01:00r   r#   r$   rR   )r)   r-   _data)rA   tz_naive_fixturer   rR   r.   dtar   r   r   rD   g  s   zTestDatetimeArray.arr1dc                 C  sj   |  |}|jdd}|tjdd }|d }t|| |j}|jdd}|jd }t|| d S )N2Tr=   rG   )minutes)	r5   roundr)   r   r   rb   rr   r  assert_datetime_array_equal)rA   rD   r.   rM   rY   r	  r   r   r   
test_roundr  s   

zTestDatetimeArray.test_roundc                 C  z  t |}t|}|j}||u sJ t|| tj|dd}||u s%J t|| tj|dd}|j}||u s;J t|| tj|ddd}||u sOJ t|| tj|dd}||usbJ t|| tj|td}tjt|td}t|| tj|dd}||j	usJ t
||rJ |j	 }t|| dtfD ]}tj||d}t||}t|| qd S )NFr   datetime64[ns]r8   r9   r   r   float64)r
   r>   r   r   rb   rc   rs   r   r   r   may_share_memoryr   r   r   )rA   r/   rC   rM   rY   r9   r   r   r   test_array_interface  >   

z&TestDatetimeArray.test_array_interfacec                 C  sT   |}|  |}tt|}tj|td}t|| tj|td}t|| d S Nr8   )r5   r>   rs   r   r   rb   rc   rA   rD   rC   r.   rY   rM   r   r   r   test_array_object_dtype  s   
z)TestDatetimeArray.test_array_object_dtypec                 C  s   |}|  |}|jd}tj|dd}t|| tj|dd}t|| tj|ddd}|j|ju s7J |jd us>J tj|ddd}|j|ju sNJ |jd usUJ d S )Nr  r8   r  Fr  )r5   r   viewr>   rs   rb   rc   baser  r   r   r   test_array_tz  s   
zTestDatetimeArray.test_array_tzc                 C  s|   |}|  |}|j}tj|dd}t|| tj|tjd}t|| tj|ddd}|j|jus5J |jd u s<J d S )Nr7   r8   Fr  )r5   r   r>   rs   rb   rc   r   r  r  r   r   r   test_array_i8_dtype  s   
z%TestDatetimeArray.test_array_i8_dtypec                 C  sL   t jddgdd}t|}|j|u sJ t|d d }|jj|u s$J d S )Nr   z
2000-01-02r  r8   r   )r>   rs   r
   r   r  )rA   rC   r	  r   r   r   test_from_array_keeps_base  s
   z,TestDatetimeArray.test_from_array_keeps_basec                 C  sR   |}|  |}t|t|ksJ t|}t|tsJ t|t|ks'J d S rU   )r5   r   r)   r   r   r   )rA   rD   rC   r.   dti2r   r   r   test_from_dti  s   

zTestDatetimeArray.test_from_dtic                 C  sN   |}|  |}|d}t|tjsJ |jdksJ t|t|ks%J d S NOr5   r   r   r>   ndarrayr9   r   )rA   rD   rC   r.   asobjr   r   r   test_astype_object  s   

z$TestDatetimeArray.test_astype_object3ignore:PeriodDtype\[B\] is deprecated:FutureWarningc                 C  sD   |}t |}|j|d}|j|d}t|tsJ t||j d S )Nr=   )r
   	to_periodr   r   rb   r   r  )rA   r/   r   r.   rC   rY   rM   r   r   r   test_to_period  s   z TestDatetimeArray.test_to_periodc                 C  st   | dd}|jd u rd nt}t| |d}|d dd}W d    n1 s-w   Y  t|| d S )NrG   r   r   )r   rR   UserWarningrb   assert_produces_warningr(  assert_period_array_equal)rA   rD   r   warnrM   rY   r   r   r   test_to_period_2d  s   
z#TestDatetimeArray.test_to_period_2dpropnamec                 C  sN   |  |}|}|j|jksJ t||}tjt|||jd}t|| d S r  )r5   r$   getattrr>   rs   r9   rb   rc   rA   rD   r/  r.   rC   rM   rY   r   r   r   test_bool_properties  s   

z&TestDatetimeArray.test_bool_propertiesc                 C  s>   |  |}|}t||}tjt|||jd}t|| d S r  )r5   r0  r>   rs   r9   rb   rc   r1  r   r   r   test_int_properties  s
   

z%TestDatetimeArray.test_int_propertiesc                 C  s>  |}|  |}||j}|jddgd|d}|d |ksJ d|jj d}tjt|d |jddgd|| d W d    n1 sEw   Y  tjt|d |jddgdt	d	d W d    n1 shw   Y  |jd urtd nd
}||}d}tjt|d |jddgd|d W d    n1 sw   Y  t
j}	d|jj d}tjt|d |jddgd|	d W d    n1 sw   Y  tdd}	tjt|d |jddgd|	d W d    n1 sw   Y  |jd ur|d}	|jddgd|	d}|jddgd|	|jjd}
t||
 d S d S )Nr   rG   Trz   r   rx   ry   rE   2014Q1z
US/Easternz:Cannot compare tz-naive and tz-aware datetime-like objectsr   r   zAustralia/Melbourne)r5   tz_localizerR   rq   r|   r}   rH   rI   r~   r   r   r   r>   timedelta64
tz_convertr9   rb   r   )rA   rD   fixed_now_tsrC   r.   nowrM   r   rR   valuerY   r   r   r   test_take_fill_valid"  sJ   


z&TestDatetimeArray.test_take_fill_validc                 C  sf   |}|j d u r|d}n|d }tjtdd |||g W d    d S 1 s,w   Y  d S )NrQ   zto_concat must have the samerE   )rR   r5  rH   rI   rJ   r   )rA   rD   rC   rd   r   r   r   test_concat_same_type_invalidR  s   

"z/TestDatetimeArray.test_concat_same_type_invalidc                 C  sb   t tjddddd}t tjddddd}t ||g}t tg dd}t|| d S )N2000ri   r   z
US/Centralr  H)2000-01-01 00:00:00z2000-01-02 00:00:00r?  z2000-01-01 01:00:00)r
   r)   r-   r   to_datetimer5  rb   r  )rA   abrM   rY   r   r   r   $test_concat_same_type_different_freq^  s   z6TestDatetimeArray.test_concat_same_type_different_freqc                 C  6   |}| d}tjdd |D td}t|| d S )N%Y %bc                 S     g | ]}| d qS )rE  strftime)r   tsr   r   r   r   t  r   z3TestDatetimeArray.test_strftime.<locals>.<listcomp>r8   rH  r>   rs   r   rb   rc   rA   rD   rC   rM   rY   r   r   r   test_strftimep     
zTestDatetimeArray.test_strftimec                 C  s>   t tdtg}|d}tjdtjgtd}t	|| d S )N
2019-01-01%Y-%m-%dr8   )
r
   r   r   rH  r>   rs   r   r   rb   rc   rA   rC   rM   rY   r   r   r   test_strftime_natw  s   
z#TestDatetimeArray.test_strftime_natN)#r}   r   r   r   r5   r
   r@   r   r   r   rH   r   rD   r  r  r  r  r  r  r   r&  r   r'   r)  r.  r  	_bool_opsr2  
_field_opsr3  r;  r<  rC  rL  rQ  r   r   r   r   r  a  s6    

*	

	

	

	0r  c                   @  sf   e Zd ZeZeZejZ	dZ
dd Zdd Zdd Zdd	 Zejd
ejdd Zdd Zdd ZdS )TestTimedeltaArraym8[ns]c                 C  sX   t ddg}t|}t|t|ksJ t|}t|t s J t|t|ks*J d S )Nr1   r2   )r	   r   r   r)   r   r   )rA   tdirC   tdi2r   r   r   test_from_tdi  s   
z TestTimedeltaArray.test_from_tdic                 C  sT   t ddg}t|}|d}t|tjsJ |jdksJ t|t|ks(J d S )Nr1   r2   r"  )r	   r   r   r   r>   r$  r9   r   )rA   rV  rC   r%  r   r   r   r&    s   
z%TestTimedeltaArray.test_astype_objectc                 C  s,   |}t |}| }| }t|| d S rU   )r   to_pytimedeltarb   rc   rA   r3   rV  rC   rY   rM   r   r   r   test_to_pytimedelta  s
   z&TestTimedeltaArray.test_to_pytimedeltac                 C  s.   |}t |}| }| }t||j d S rU   )r   total_secondsrb   rc   valuesrZ  r   r   r   test_total_seconds  s
   z%TestTimedeltaArray.test_total_secondsr/  c                 C  s<   |}t |}t||}tjt|||jd}t|| d S r  )r   r0  r>   rs   r9   rb   rc   )rA   r3   r/  rV  rC   rM   rY   r   r   r   r3    s
   
z&TestTimedeltaArray.test_int_propertiesc                 C  r  )NFr  ztimedelta64[ns]r8   r  r   r  )r   r>   r   r   rb   rc   rs   r   r   r   r  r   r   r   )rA   r3   rC   rM   rY   r9   r   r   r   r    r  z'TestTimedeltaArray.test_array_interfacec           	      C  s2  |}t |}tjdd}|jddgd|d}|d |ksJ |}d|jj d}tjt|d	 |jddgd|d W d    n1 sDw   Y  |	d
}tjt|d	 |jddgd|d W d    n1 sjw   Y  t
dd}tjt|d	 |jddgd|d W d    d S 1 sw   Y  d S )NrG   r   r   Trz   r   rx   ry   rE   r   r   r   )r   r)   r   rq   r|   r}   rH   rI   r~   r(  r>   
datetime64)	rA   r3   r8  rV  rC   td1rM   r:  r   r   r   r   r;    s$   
"z'TestTimedeltaArray.test_take_fill_validN)r}   r   r   r	   r5   r   r@   r)   r   r   r   rX  r&  r[  r^  rH   r   r  rS  r3  r  r;  r   r   r   r   rT    s    
		
	*rT  r   r'  c                   @  s   e Zd ZeZeZeZeg ddj	Z
ejdd Zdd Zdd Zd	d
 Zejdddgdd Zdd Zdd Zejdejdd Zejdejdd Zdd Zdd Zdd ZdS ) TestPeriodArrayr   r=   c                 C  s   |j S )zW
        Fixture returning DatetimeArray from parametrized PeriodIndex objects
        )r  )rA   r,   r   r   r   rD     s   zTestPeriodArray.arr1dc                 C  sR   |  |}|}t|t|ksJ t|}t|tsJ t|t|ks'J d S rU   )r5   r   r)   r   r   r   )rA   rD   r+   rC   pi2r   r   r   test_from_pi  s   

zTestPeriodArray.test_from_pic                 C  sN   |  |}|}|d}t|tjsJ |jdksJ t|t|ks%J d S r!  r#  )rA   rD   r+   rC   r%  r   r   r   r&    s   

z"TestPeriodArray.test_astype_objectc                 C  s   |}t j}d|jj d}tjt|d |jddgd|d W d    n1 s)w   Y  t	dd	}tjt|d |jddgd|d W d    d S 1 sQw   Y  d S )
Nrx   ry   rE   r   rG   Trz   r   r   )
r   r   r|   r}   rH   rI   r~   rq   r>   r6  )rA   rD   rC   r:  r   r   r   r   r;    s   "z$TestPeriodArray.test_take_fill_validhowSEc                 C  sH   |  |}|}t|j|d}|j|d}t|tsJ t|| d S )N)rd  )r5   r
   to_timestampr   rb   r   )rA   rd  rD   r+   rC   rY   rM   r   r   r   test_to_timestamp&  s   
z!TestPeriodArray.test_to_timestampc           	      C  s   t jddddj}| }| }|jdksJ t|| |d d d }| }| }|jdks4J t|| |d}| }|jdksJJ t|| d S )Nz
2021-10-18rO   r   rT   ri   2B)r)   r-   r  r(  rg  r$   rb   r   )	rA   r	  parrrM   dta2parr2result2parr3result3r   r   r    test_to_timestamp_roundtrip_bday1  s   
z0TestPeriodArray.test_to_timestamp_roundtrip_bdayc                 C  s   t jdddd}d}tjt|d |  W d    n1 s w   Y  tjt|d |j  W d    d S 1 s=w   Y  d S )N1500r   rO   )r$   r#   z7Out of bounds nanosecond timestamp: 1500-01-01 00:00:00rE   )r)   r*   rH   rI   r   rg  r  )rA   r+   r   r   r   r   test_to_timestamp_out_of_boundsD  s   
"z/TestPeriodArray.test_to_timestamp_out_of_boundsr/  c                 C  8   |  |}|}t||}tt||}t|| d S rU   r5   r0  r>   rs   rb   rc   rA   rD   r/  r+   rC   rM   rY   r   r   r   r2  N  s
   

z$TestPeriodArray.test_bool_propertiesc                 C  rs  rU   rt  ru  r   r   r   r3  Y  s
   

z#TestPeriodArray.test_int_propertiesc                 C  s   |}t |}t jt|td}t|| t j|td}t|| t j|dd}t||j d}tj	t
|d t j|dd W d    n1 sLw   Y  t j|dd}t |d}t|| d S )Nr8   r   zEfloat\(\) argument must be a string or a( real)? number, not 'Period'rE   r  S20)r>   r   rs   r   r   rb   rc   r   rH   rI   r~   r   )rA   rD   rC   rM   rY   r   r   r   r   r  c  s   
z$TestPeriodArray.test_array_interfacec                 C  rD  )N%Yc                 S  rF  )rw  rG  )r   perr   r   r   r     r   z1TestPeriodArray.test_strftime.<locals>.<listcomp>r8   rJ  rK  r   r   r   rL  {  rM  zTestPeriodArray.test_strftimec                 C  sB   t tdtgdd}|d}tjdtjgtd}t	|| d S )NrN  rj   r8   rO  )
r   r   r   rH  r>   rs   r   r   rb   rc   rP  r   r   r   rQ    s   
z!TestPeriodArray.test_strftime_natN)r}   r   r   r   r5   r   r@   r   r   r9   r   rH   r   rD   rc  r&  r;  r   r  rh  rp  rr  rR  r2  rS  r3  r  rL  rQ  r   r   r   r   ra    s*    







	ra  zarr,casting_natsr0   r   r   r   rO   r   rT   c                 C  
   t | jS rU   r   r}   r   r   r   r   <lambda>     
 r|  )idsc                 C  sF   t | t| d | d g}|D ]}|  } || d< t| | qd S )NrG   ri   r   )r   r   r   r   rb   r   )rC   casting_natsrY   natr   r   r   test_casting_nat_setitem_array  s   r  zarr,non_casting_natsc                 C  ry  rU   rz  r{  r   r   r   r|    r}  c              	   C  sH   d}|D ]}t jt|d || d< W d    n1 sw   Y  qd S )Nzwvalue should be a '(Timestamp|Timedelta|Period)', 'NaT', or array of those. Got '(timedelta64|datetime64|int)' instead.rE   r   )rH   rI   r~   )rC   non_casting_natsr   r  r   r   r   test_invalid_nat_setitem_array  s   
r  rC   r=  rk   rP   c                 C  s   t | d< |  }|  }t|d sJ | jdd}|d dks#J | jddd}|d dks2J | j| d  d}|d |d ksFJ | j| d jdd	d}|d |d ks\J t| | d S )
Nr   r   r8   l         )r9   na_valuerG   )r  Fr  )r   r   to_numpyr>   isnanrb   r   )rC   originalrM   r   r   r   test_to_numpy_extra  s   r  r\   TFr]  z
2020-01-01z
2020-02-01rG   ri   )unitr=   klassc                 C  s<   |s| j } | || }tjddg|jd}t|| d S )Nr   rG   r8   )r  r   r>   rs   r9   rb   rc   )r]  r  r\   rM   rY   r   r   r   ,test_searchsorted_datetimelike_with_listlike  s
   r  argrA  rB  zEurope/London)rR   c                 C  sB   d}t jt|d | | W d    d S 1 sw   Y  d S )Nz [Unexpected type|Cannot compare]rE   )rH   rI   r~   r   )r]  r  r   r   r   r   :test_searchsorted_datetimelike_with_listlike_invalid_dtype  s   "r  c                 C  sB   ddgd }| |}t |dd}t dd |D }t|| d S )NrS   2020Q2ri   r   r=   c                 S  r   r   )r   )r   sr   r   r   r     r   z?test_period_index_construction_from_strings.<locals>.<listcomp>)r   rb   rr   )r  stringsrB   rM   rY   r   r   r   +test_period_index_construction_from_strings  s
   r  r9   r  rU  c                 C  s   t jg d| d}t|}ttd|  }||}||}t|| ||}||}t|| tt	d|  }||d }||d }t
|| tjtjd|  }||j}||j}t
|| ttd|  }||}||}t|| d S )Nr   r8   )r  rU  r   )r>   rs   r   r
   r   rb   r   r   r   r   r   r)   r@  to_timedeltar   r	   rr   )r9   rB   rC   clsrM   rY   funcidx_clsr   r   r   test_from_pandas_array  s*   



r  )?
__future__r   r   r%   numpyr>   rH   pandas._libsr   r   r   pandasr)   r   r   r   r	   pandas._testing_testingrb   pandas.core.arraysr
   r   r   r   pandas.core.arrays.datetimesr   pandas.core.arrays.timedeltasr   r   r   r,   r/   r3   r4   r  rT  r   r'   ra  r  r  r6  r-   r_  r*   r  r   r  rs   r  r  r@  r   r   r   rV   r^   r  r  tupler  r  r   r   r   r   <module>   s    



      !
w
 
	

 
	