o
    dG3                 
   @   s  d dl mZ d dlmZmZ d dlmZ d dlmZ d dlZ	d dlm
Z
 d dlZd dlmZmZ d dlmZ d dlm  mZ d d	lmZmZ d d
lmZ d dlZd dlmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+ d dl,m-Z. d dl/m0Z0m1Z1m2Z2 d dl3m4Z4 G dd dZ5G dd dZ6G dd dZ7dd Z8ej9:dd d ie	j;d gge	j<dfddie	j;dgge=dfddie	j;dgge	j<dfgdd Z>dS )    )OrderedDict)datetime	timedelta)Iterator)tzoffsetN)ma)iNaTlib)IntCastingNaNError)is_categorical_dtypeis_datetime64tz_dtype)CategoricalDtype)Categorical	DataFrameDatetimeIndexIndexIntervalIntervalIndex
MultiIndexNaTPeriod
RangeIndexSeries	Timestamp
date_rangeisnaperiod_rangetimedelta_range)IntegerArrayIntervalArrayperiod_array)NumericBlockc                   @   sL
  e Zd Zdd Zdd Zdd Zdd Zej	d	d
d dd dd dd dd dd dd dd dd dd dd gej	ddg gdd Z
dd Zdd Zdd Zd d! Zd"d# Zd$d% Zej	d&eeegd'd( Zej	d)ejed*gd+d, Zej	d-g d.ej	d/deg gd0d1 Zd2d3 Zd4d5 Zej	d6g d7d8d9 Zd:d; Zd<d= Zd>d? Z d@dA Z!dBdC Z"dDdE Z#dFdG Z$ej	d-g dHdIdJ Z%ej	dKdLdMgdNdOgee&dPdMdQdRee&dPdMdQdSdTe'dUdVdWggdXdY Z(dZd[ Z)d\d] Z*d^d_ Z+d`da Z,dbdc Z-ddde Z.dfdg Z/dhdi Z0djdk Z1dldm Z2dndo Z3dpdq Z4drds Z5dtdu Z6dvdw Z7dxdy Z8dzd{ Z9ej	d|g d}d}ee:d~e;g ddd e:d~D e<dd e:d~gdd Z=dd Z>dd Z?dd Z@dd ZAdd ZBeCjDejj	d/e&dd~dSde&dd~deEdd~deFdd~ddReedeg d}eGdUd~gdd ddd ZHdd ZIdd ZJdd ZKdd ZLdd ZMej	dejNdLgejOdejNdLgejPdejNdLgejQdeOdLgePdLgeQdLggdd ZRdd ZSdd ZTdd ZUdd ZVdd ZWdd ZXdd ZYdd ZZdd Z[dd Z\dd Z]dd Z^dd Z_ddÄ Z`ddń ZaddǄ ZbddɄ Zcdd˄ Zddd̈́ Zeddτ Zfddф Zgddӄ ZhddՄ Ziddׄ Zjddل Zkddۄ Zlej	dejmejngej	dddgej	dg ddd Zoej	ddepejdgdd Zqdd Zrej	desetgdd Zuejj	deejNgddgddd Zvejj	deejNgddgddd Zwdd Zxejj	deejNgddgddd Zyejjzdddd Z{dd Z|dd Z}d d Z~dd Zdd Zdd Zej	ddMejded*gd	d
 Zdd Zdd Zdd Zdd Zdd Zdd Zejd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+ Zejj	d/e&d,d-deEdd-deFd.d-ddRgd/d dd0d1 Zejj	d/e&d,d-deEdd-deFd.d-ddRgd2d dd3d4 Zej	d-ejejgd5d6 Zej	dg d7ej	dddgd8d9 Zej	d-g d:d;d< Zd=d> Zd?d@ Zej	dAdBdCgdDdE ZdFdG ZdHdI Zej	dedJedKgdJdKggdLdM ZdNdO ZdPdQ ZdRdS ZdTdU ZdVdW ZdXdY ZdZd[ Zd\d] Zd^d_ Zd`da Zdbdc Zddde Zdfdg Zdhdi Zdjdk Zejjzdlddmdn Zejjzdlddodp Zejdqej	dreeeejNgdsdt Zdudv Zdwdx Zej	dydLdzgd{d| Zej	dydLdzgd}d~ Zdd Zdd Zdd ZdS (  TestSeriesConstructorsc                 C   sP   t d}||dd}||d}t|| |t|dd}t|| d S )N
   M8[s]dtype)nparangeastypetmassert_equallist)selfindex_or_seriesvaluesresexpected r2   j/var/www/html/visualizacion-main/env/lib/python3.10/site-packages/pandas/tests/series/test_constructors.py'test_from_ints_with_non_nano_dt64_dtype7   s   
z>TestSeriesConstructors.test_from_ints_with_non_nano_dt64_dtypec                 C   s0   t d gdd}|  sJ |jdksJ d S )Nzinterval[datetime64[ns]]r%   zinterval[datetime64[ns], right])r   r   allr&   r-   serr2   r2   r3   1test_from_na_value_and_interval_of_datetime_dtypeA   s   zHTestSeriesConstructors.test_from_na_value_and_interval_of_datetime_dtypec                 C   s`   t ddd}| | g}t|}t|td}t|| t|}t|td}t|| d S )Ni     r%   )	r   to_pydatetimedater   objectr*   assert_series_equalr   assert_index_equal)r-   tsvalsr7   r1   idxr2   r2   r3   !test_infer_with_date_and_datetimeG   s   z8TestSeriesConstructors.test_infer_with_date_and_datetimec                 C   s   dg}d}t jt|d t|dd W d    n1 sw   Y  t jt|d ttj|tddd W d    d S 1 s@w   Y  d S )NaazD^Unknown datetime string format, unable to parse: aa, at position 0$matchdatetime64[ns]r%   )pytestraises
ValueErrorr   r'   arrayr<   )r-   r@   msgr2   r2   r3   (test_unparseable_strings_with_dt64_dtypeU   s   "z?TestSeriesConstructors.test_unparseable_strings_with_dt64_dtypeconstructorc                 C   s
   t | dS Nindexr   rA   r2   r2   r3   <lambda>f      
 zTestSeriesConstructors.<lambda>c                 C      t d | dS rN   rQ   rR   r2   r2   r3   rS   g       c                 C      t i | dS rN   rQ   rR   r2   r2   r3   rS   h   rV   c                 C      t d| dS )Nr2   rO   rQ   rR   r2   r2   r3   rS   i   rV   c                 C      t g | dS rN   rQ   rR   r2   r2   r3   rS   j   rV   c                 C      t dd dD | dS )Nc                 s       | ]}|V  qd S Nr2   .0_r2   r2   r3   	<genexpr>k       2TestSeriesConstructors.<lambda>.<locals>.<genexpr>r2   rO   rQ   rR   r2   r2   r3   rS   k       c                 C   rU   NdatarP   rQ   rR   r2   r2   r3   rS   l   rV   c                 C   rW   rd   rQ   rR   r2   r2   r3   rS   m   rV   c                 C   rX   )Nr2   re   rQ   rR   r2   r2   r3   rS   n   rV   c                 C   rY   rd   rQ   rR   r2   r2   r3   rS   o   rV   c                 C   rZ   )Nc                 s   r[   r\   r2   r]   r2   r2   r3   r`   p   ra   rb   r2   re   rQ   rR   r2   r2   r3   rS   p   rc   empty_indexNc                 C   sF   t |d}||}|jtksJ t|jdksJ tj||dd d S )NrO   r   Tcheck_index_type)r   r&   r<   lenrP   r*   r=   )r-   rM   rg   r1   resultr2   r2   r3   test_empty_constructor_   s
   
z-TestSeriesConstructors.test_empty_constructorc              	   C   sX   d}t dtg}|D ] }tjt|d tg d|d W d    n1 s$w   Y  q	d S )Nznot understoodr   rD   time)namer&   )r   r,   rG   rH   	TypeErrorr   )r-   rK   invalid_listr&   r2   r2   r3   test_invalid_dtype}   s   
z)TestSeriesConstructors.test_invalid_dtypec                 C   sd   t ddg}t jddg|d}tjtdd t|dd	gd
 W d    d S 1 s+w   Y  d S )N)ai8)bf4)r9   g?)   ir%   zUse DataFrame insteadrD   ABrO   )r'   r&   rJ   rG   rH   rI   r   )r-   c_dtypecdt_arrr2   r2   r3   test_invalid_compound_dtype   s
   "z2TestSeriesConstructors.test_invalid_compound_dtypec                 C   s   t d}t|trJ d S )Ng      ?)r   
isinstancefloat)r-   scalarr2   r2   r3   test_scalar_conversion   s   z-TestSeriesConstructors.test_scalar_conversionc                 C   sH   |\}}t |tdd}t |gd |d}|j|ksJ t|| d S )N   rO   r%   )r   ranger&   r*   r=   )r-   ea_scalar_and_dtype	ea_scalarea_dtyper7   r1   r2   r2   r3   test_scalar_extension_dtype   s
   z2TestSeriesConstructors.test_scalar_extension_dtypec           	      C   sd  t  }|jjs	J t |}|jjsJ t|j|jsJ t|jt|jks)J t dtjgddgd}|jtj	ks<J t
|d sEJ |jjrKJ t  jjrRJ tjtdd t tjddtdd W d    n1 srw   Y  d|_t |j}d}||ksJ tdd	gdd
gg}d}tjt|d t | W d    d S 1 sw   Y  d S )Nhellor   r9   rO   zAData must be 1-dimensional, got ndarray of shape \(3, 3\) insteadrD   r   r         z8initializing a Series from a MultiIndex is not supported)r   rP   _is_all_datesr*   equalContentsidr'   NaNr&   object_isnanrG   rH   rI   randomrandnr(   rn   r   from_arraysNotImplementedError)	r-   datetime_seriesempty_seriesderivedmixedrsxpmrK   r2   r2   r3   test_constructor   s4   

"z'TestSeriesConstructors.test_constructorc                 C   sf   t ddgddgddggg dd}tjtd	d
 tg d|d W d    d S 1 s,w   Y  d S )Nr9   r   r   r         )r   r   	   rO   z Index data must be 1-dimensionalrD   r9   r   r   )r   rG   rH   rI   r   )r-   dfr2   r2   r3   'test_constructor_index_ndim_gt_1_raises   s   ""z>TestSeriesConstructors.test_constructor_index_ndim_gt_1_raisesinput_classc                 C   s  t  }t | }tj||dd t dd}t | dd}tj||dd t dd}t | dd}tj||dd |turt tdd}t | tdd}t|| t tjtdd}t | tddd}t|| t d	ttd
d}t d	td
d}t|| d S d S )NFrh   float64r%   categoryr#   rO   rP   r&    r   r&   rP   )r   r*   r=   r,   r   r'   nanstr)r-   r   emptyempty2r2   r2   r3   test_constructor_empty   s(   


z-TestSeriesConstructors.test_constructor_empty	input_argr   c                 C   s4   t dtdd}t |tdd}tj||dd d S )Nr   r#   r   rO   Frh   r   r   r*   r=   )r-   r   r   r   r2   r2   r3   test_constructor_nan   s   z+TestSeriesConstructors.test_constructor_nanr&   )f8rs   M8[ns]m8[ns]r   r<   zdatetime64[ns, UTC]rP   c                 C   s.   t ||d}|j|ksJ t|dksJ d S )Nr   r   )r   r&   rj   )r-   r&   rP   rk   r2   r2   r3   test_constructor_dtype_only   s   z2TestSeriesConstructors.test_constructor_dtype_onlyc                 C   s(   t g dd}|j g dksJ d S )Nrt   rr   crO   )r   rP   tolistr-   rk   r2   r2   r3   $test_constructor_no_data_index_order   s   z;TestSeriesConstructors.test_constructor_no_data_index_orderc                 C   s&   t dgtd}t|jd sJ d S Nr9   r   r   )r   r   r'   r   ilocr   r2   r2   r3   $test_constructor_no_data_string_type  s   z;TestSeriesConstructors.test_constructor_no_data_string_typeitem)entryu   ѐ   c                 C   s*   t |dgtd}|jd t|ksJ d S r   )r   r   r   )r-   r   rk   r2   r2   r3   +test_constructor_string_element_string_type  s   zBTestSeriesConstructors.test_constructor_string_element_string_typec                 C   sl   t dd g|d}| }t ddg}t|| |jd d u s!J t dtjg|d}t|jd s4J d S )Nxr%   FTr9   )r   r   r*   r=   r   r'   r   r   )r-   string_dtyper7   rk   r1   r2   r2   r3   $test_constructor_dtype_str_na_values  s   z;TestSeriesConstructors.test_constructor_dtype_str_na_valuesc                 C   s@   g d}t |}tg d|d}t||d}t||  d S )N)drt   rr   r   )r      r   rO   )sortedr   r*   r=   
sort_index)r-   index1index2s1s2r2   r2   r3   test_constructor_series  s
   z.TestSeriesConstructors.test_constructor_seriesc                 C   s@   G dd d}t ttddd}t | dd}t|| d S )Nc                   @   s   e Zd ZdefddZdS )z>TestSeriesConstructors.test_constructor_iterable.<locals>.Iterreturnc                 s   s    t dE d H  d S )Nr#   )r   r-   r2   r2   r3   __iter__#  s   zGTestSeriesConstructors.test_constructor_iterable.<locals>.Iter.__iter__N)__name__
__module____qualname__r   r   r2   r2   r2   r3   Iter"  s    r   r#   int64r%   r   r,   r   r*   r=   )r-   r   r1   rk   r2   r2   r3   test_constructor_iterable   s   z0TestSeriesConstructors.test_constructor_iterablec                 C   s4   t ttddd}t tddd}t|| d S )Nr#   r   r%   r   r-   r1   rk   r2   r2   r3   test_constructor_sequence*  s   z0TestSeriesConstructors.test_constructor_sequencec                 C   s"   t dg}t d}t|| d S )Nabcr   r*   r=   r   r2   r2   r3   test_constructor_single_str0  s   
z2TestSeriesConstructors.test_constructor_single_strc                 C   sR   t g ddd}g ddtjg dddfD ]}t |g dd}t|| qd S )Nr9   r   r   r   r%   r   r9   r   rO   )r   r'   rJ   r*   r=   )r-   r1   objrk   r2   r2   r3   test_constructor_list_like6  s
    z1TestSeriesConstructors.test_constructor_list_likec                 C   sP   t g dg dd}|dk}t g d|d}t g dg dd}t|| d S )Nr   )r   r   r   rO   r   r   )FTFr   )r-   r   rP   rk   r1   r2   r2   r3   test_constructor_boolean_index?  s
   z5TestSeriesConstructors.test_constructor_boolean_index)boolint32r   r   c                 C   s&   t tg d|d}|j|ksJ d S )N)r   r   r   r%   )r   r   r&   )r-   r&   sr2   r2   r3   test_constructor_index_dtypeH  s   z3TestSeriesConstructors.test_constructor_index_dtype
input_valsr9   r   12z1/1/2011Hperiodsfreq
US/Eastern)r   r   tzr   r   )leftrightc                 C   s*   t ||d}t ||}t|| d S Nr%   r   r)   r*   r=   )r-   r   r   rk   r1   r2   r2   r3   test_constructor_list_strO  s   z0TestSeriesConstructors.test_constructor_list_strc                 C   sJ   t ddtjg|d}t ddtjgtd}t|| t|d s#J d S )N      ?       @r%   z1.0z2.0r   )r   r'   r   r<   r*   r=   r   )r-   r   rk   r1   r2   r2   r3   test_constructor_list_str_naa  s   z3TestSeriesConstructors.test_constructor_list_str_nac                 C   sr   dd t dD }t|}tt d}t|| dd t dD }t|t ddd}t dd|_t|| d S )Nc                 s   r[   r\   r2   r^   ir2   r2   r3   r`   h  ra   zDTestSeriesConstructors.test_constructor_generator.<locals>.<genexpr>r#   c                 s   r[   r\   r2   r   r2   r2   r3   r`   o  ra      rO   )r   r   r*   r=   rP   )r-   genrk   expr2   r2   r3   test_constructor_generatorg  s   z1TestSeriesConstructors.test_constructor_generatorc                 C   sr   t dd td}t|}ttd}t|| t dd td}t|tddd}tdd|_t|| d S )Nc                 S      | S r\   r2   r   r2   r2   r3   rS   v      z=TestSeriesConstructors.test_constructor_map.<locals>.<lambda>r#   c                 S   r   r\   r2   r   r2   r2   r3   rS   }  r   r   rO   )mapr   r   r*   r=   rP   )r-   r   rk   r   r2   r2   r3   test_constructor_mapt  s   z+TestSeriesConstructors.test_constructor_mapc                 C   s`   t g dg ddd}t|}t|j| tt g ddd}tg ddd}t|| d S )N)r   r9   r   r   r9   r   rr   rt   r   T)fastpathr   r   r%   )r   r   r*   assert_categorical_equalr/   r=   )r-   catr0   rk   r1   r2   r2   r3   test_constructor_categorical  s   z3TestSeriesConstructors.test_constructor_categoricalc                 C   s2   t tg ddd}t|sJ t|jsJ d S Nr   r   r%   )r   r   r   r&   )r-   r  r2   r2   r3   *test_construct_from_categorical_with_dtype  s   zATestSeriesConstructors.test_construct_from_categorical_with_dtypec                 C   s.   t g ddd}t|sJ t|jsJ d S r  )r   r   r&   r6   r2   r2   r3   ,test_construct_intlist_values_category_dtype  s   zCTestSeriesConstructors.test_construct_intlist_values_category_dtypec                 C   sj  t g d}t|dd}|jdksJ t|t|ksJ t|j t| td|i}|d }t|| |j	d d df }t|| t|t|ksOJ t|j t| td|i}|d }t|| t|t|ksrJ t|j t| t||dd}|d }|d }t|| tj||d	d
 |j
dksJ t|t|ksJ t|j t| d S )N)rr   rt   rt   rr   rr   r   r   r   rw   rn   r   r   r9   rw   rx   Crx   F)check_names)r   r   r&   rj   r   r/   r   r*   r=   r   rn   )r-   factorr   r   rk   result1result2r2   r2   r3   *test_constructor_categorical_with_coercion  s:   



zATestSeriesConstructors.test_constructor_categorical_with_coercionc                 C   s   t ddgddgddggddgd}t|j|d< |jd j}|jjd }||ks*J |jd }||ks5J |jjd }||ksAJ d S )	Nr9   zJohn P. Doer   z	Jane Dove	person_idperson_name)columnsr   )r   r   r  r   loc)r-   r   r1   rk   r2   r2   r3   +test_constructor_categorical_with_coercion2  s   
zBTestSeriesConstructors.test_constructor_categorical_with_coercion2c                 C   s8   t g d}t |dd}t g ddd}t|| d S )Nr   r   r%   r   )r-   seriesrk   r1   r2   r2   r3   &test_constructor_series_to_categorical  s   z=TestSeriesConstructors.test_constructor_series_to_categoricalc                 C   s   t ddgtg dddd}t|jdu sJ t|jjtg d |jj	s)J t ddgtddgd}t|js<J t|jjtddg |jj	du sPJ t ddd	gtddgddd
}t ddgdd	gtddgddd
}t
|| d S )Nrr   rt   r   T)orderedr%   Fr   r9   r   )r   r   r   r&   r*   r>   r  
categoriesr   r  r=   r-   rk   r1   r2   r2   r3   "test_constructor_categorical_dtype  s"   z9TestSeriesConstructors.test_constructor_categorical_dtypec                 C   sd   t tddd}ttd|d}ttd|d}t|dd}t|| t|dd}t|| d S )NdabcT)r  r  abcabcr%   r   )r   r,   r   r   r*   r=   )r-   cdtr1   r  rk   r2   r2   r3   #test_constructor_categorical_string  s   z:TestSeriesConstructors.test_constructor_categorical_stringc                 C   sR  t g d}t|dd}|j|usJ |jg d}tjg dtjd}tjg dtjd}t	|
 | t	|
 | d|d< tjg d	tjd}t	|
 | t	|
 | t g d}t|d
d}|j|u spJ |jg d}|j|usJ tjg dtjd}t	|
 | d|d< tjg d	tjd}t	|
 | d S )N)rr   rt   r   rr   T)copyr   )r9   r   r   r9   r%   r   r   )r   r   r   r9   F)r   r   r  rename_categoriesr'   rJ   r   r   r*   assert_numpy_array_equal	__array__r/   )r-   r  r   exp_sexp_catexp_s2r2   r2   r3   !test_categorical_sideeffects_free  s,   z8TestSeriesConstructors.test_categorical_sideeffects_freec                 C   sD   t g dtddgd}t tddtjgddgd}t|| d S )Nr   rr   rt   r%   )r  )r   r   r   r'   r   r*   r=   )r-   r   r   r2   r2   r3   test_unordered_compare_equal  s   z3TestSeriesConstructors.test_unordered_compare_equalc                 C   s  t jdtd}t|}ttjtjtjg}t|| d|d< d|d< g d}t||d}tdtjdg|d}t|| d	|d
< t||d}tg d|d}t|| t jdtd}t|}ttjtjtjgtd}t|| d|d< d|d< g d}t||d}tdtjdg|td}t|| d
|d
< t||d}tg d|td}t|| t jdt	d}t|}ttjtjtjgt
d}t|| d|d< d|d< g d}t||d}tdtjdg|t
d}t|| d|d
< t||d}tg d|t	d}t|| t jddd}t|}ttttgdd}t|| tdd
d
|d< tdd
d|d< g d}t||d}ttdd
d
ttdd
dg|dd}t|| tdd
d|d
< t||d}ttdd
d
tdd
dtdd
dg|dd}t|| d S )Nr   r%           r   r   r   r   rO   r   r9   )r)  r   r   r   r   TFTTFr     r   )r   
masked_allr}   r   r'   r   r*   r=   intr   r<   r   r   )r-   rf   rk   r1   rP   r2   r2   r3   test_constructor_maskedarray!  s    z3TestSeriesConstructors.test_constructor_maskedarrayc                 C   s>   t jdtd }t|}ttjtjtjg}t|| d S )Nr(  r%   )	r   r,  r}   harden_maskr   r'   r   r*   r=   r-   rf   rk   r1   r2   r2   r3   %test_constructor_maskedarray_hardenedn  s   z<TestSeriesConstructors.test_constructor_maskedarray_hardenedc                 C   s:   t dddd}dd |D }t||d}|j|u sJ d S )N2009041520090519rx   r   c                 S   s   i | ]}|d qS r9   r2   )r^   kr2   r2   r3   
<dictcomp>w  s    zNTestSeriesConstructors.test_series_ctor_plus_datetimeindex.<locals>.<dictcomp>rO   )r   r   rP   )r-   rngrf   rk   r2   r2   r3   #test_series_ctor_plus_datetimeindexu  s   z:TestSeriesConstructors.test_series_ctor_plus_datetimeindexc                 C   s*   t g d}tj|jttddd d S )Nr   r   T)exact)r   r*   r>   rP   r   r   r-   r   r2   r2   r3   test_constructor_default_index|  s   z5TestSeriesConstructors.test_constructor_default_indexinputr   r   )rr   rt   rr   c                 c   r[   r\   r2   r   r2   r2   r3   r`     ra   z TestSeriesConstructors.<genexpr>c                 C   r   r\   r2   r   r2   r2   r3   rS     r   c                 C   sJ   d}t jt|d t|tdd W d    d S 1 sw   Y  d S )Nz;Length of values \(3\) does not match length of index \(4\)rD   r   rO   )rG   rH   rI   r   r'   r(   )r-   r=  rK   r2   r2   r3   test_constructor_index_mismatch  s   "z6TestSeriesConstructors.test_constructor_index_mismatchc                 C   s>   t tdtddd}t dtddd}t|| d S )Nd   r   r   r   )r   r'   rJ   r(   r*   r=   r  r2   r2   r3   test_constructor_numpy_scalar  s   z4TestSeriesConstructors.test_constructor_numpy_scalarc                 C   sJ   d}t jt|d tdgg dd W d    d S 1 sw   Y  d S )Nz;Length of values \(1\) does not match length of index \(3\)rD   foor   rO   rG   rH   rI   r   r-   rK   r2   r2   r3   test_constructor_broadcast_list  s   "z6TestSeriesConstructors.test_constructor_broadcast_listc                 C   s2   t  }||g}t|ddgd}t|tsJ d S )Nr   r9   rO   )r*   makeTimeDataFramer   r|   )r-   r   objsr   r2   r2   r3   test_constructor_corner  s   z.TestSeriesConstructors.test_constructor_cornerc                 C   s~   t tg ddd}|jtdksJ d}tjt|d t tddtjgddd W d    d S 1 s8w   Y  d S )	N)r   r   g       @rs   r%   9Cannot convert non-finite values \(NA or inf\) to integerrD   r   Tr  r&   )r   r'   rJ   r&   rG   rH   r
   r   )r-   r   rK   r2   r2   r3   test_constructor_sanitize  s   "z0TestSeriesConstructors.test_constructor_sanitizec                 C   st   dgt dgfD ].}t|}t|dtd}t|| d|d< ||r'J |d dks/J |d dks7J q	d S )Nr   TrI  r   r   )r'   rJ   r   r}   r*   r=   equals)r-   rf   r   yr2   r2   r3   test_constructor_copy  s   z,TestSeriesConstructors.test_constructor_copy20170101r   r   r   z1 day2012Q1Qr   c                 C   
   t | jS r\   typer   r   r2   r2   r3   rS     rT   )idsc                 C   s"   t |}|jjd j|usJ d S Nr   )r   _mgrblocksr/   )r-   rP   r   r2   r2   r3   test_constructor_limit_copies  s   z4TestSeriesConstructors.test_constructor_limit_copiesc                 C   sF   t g d}| }t |}|j|jusJ g d|_t|| d S )Nr   r   )r   r  rX  rP   r*   r=   )r-   r   s_origr   r2   r2   r3   test_constructor_shallow_copy  s   
z4TestSeriesConstructors.test_constructor_shallow_copyc                 C   st   t d tdd}|jtjksJ t d tdtd}|jtjks!J t td gd}t td gd}t	
|| d S )Nr   rO   r   )r   r   r&   r'   r   r<   r   rJ   r   r*   r=   r-   r   r1   r2   r2   r3   test_constructor_pass_none  s   z1TestSeriesConstructors.test_constructor_pass_nonec                 C   s  t tjtjgtjd}|jtjksJ tt tjtjg| tt ttjtjg| t ttg}|jdks;J tt ttg| tt tttg| tt ttjg| tt tttjg| tt tjtg| tt ttjtg| d S )Nr%   rF   )	r   r'   r   r   r&   r*   r=   rJ   r   )r-   r   r2   r2   r3   test_constructor_pass_nan_nat  s    z4TestSeriesConstructors.test_constructor_pass_nan_natc                 C   sH   d}t jt|d tg dtd W d    d S 1 sw   Y  d S )Nz!could not convert string to floatrD   r   r%   )rG   rH   rI   r   r}   rC  r2   r2   r3   test_constructor_cast  s   "z,TestSeriesConstructors.test_constructor_castc                 C   s   d}t jt|d tg ddd W d    n1 sw   Y  t jt|d tg ddd W d    d S 1 s<w   Y  d S )Nz/Values are too large to be losslessly convertedrD   )r9      i2 int8r%   uint8rB  rC  r2   r2   r3   +test_constructor_signed_int_overflow_raises  s   "zBTestSeriesConstructors.test_constructor_signed_int_overflow_raisesr/   r%   c                 C   s8   |d }t |}|d j|jksJ |d |ksJ d S rW  )r   r&   )r-   r/   valuerk   r2   r2   r3   test_constructor_numpy_uints  s   z3TestSeriesConstructors.test_constructor_numpy_uintsc                 C   sF   d}t jt|d tdg|d W d    d S 1 sw   Y  d S )Nz5Trying to coerce negative values to unsigned integersrD   r%   )rG   rH   OverflowErrorr   )r-   any_unsigned_int_numpy_dtyperK   r2   r2   r3   (test_constructor_unsigned_dtype_overflow#  s   "z?TestSeriesConstructors.test_constructor_unsigned_dtype_overflowc                 C   sz  t jd}d}tjt|d ||dd W d    n1 s w   Y  tjt|d |t|dd W d    n1 s?w   Y  t j|d< d}tjt|d ||dd W d    n1 scw   Y  t}|t	u rrt}d}tj||d |t|dd W d    n1 sw   Y  t j
d	d
gdd}||d}||dd}t|| |t|dd}t|| d S )Nr   (Trying to coerce float values to integerrD   rs   r%   r   rH  #cannot convert float NaN to integerr   r   r   )r'   r   r   rG   rH   rI   r,   r   r
   r   rJ   r)   r*   r+   )r-   frame_or_seriesarrrK   excr1   r   r2   r2   r3   (test_constructor_floating_data_int_dtype)  s4   
z?TestSeriesConstructors.test_constructor_floating_data_int_dtypec                 C   s   g d}d}t jt|d t||d W d    n1 sw   Y  t jt|d tt||d W d    d S 1 s?w   Y  d S )Nr9   r   g      @rk  rD   r%   )rG   rH   rI   r   r'   rJ   r-   any_int_numpy_dtyper@   rK   r2   r2   r3   "test_constructor_coerce_float_failU  s   "z9TestSeriesConstructors.test_constructor_coerce_float_failc                 C   s2   t g d|d}t g d|}t|| d S )Nrq  r%   r   )r-   float_numpy_dtyper   r1   r2   r2   r3   #test_constructor_coerce_float_validb  s   z:TestSeriesConstructors.test_constructor_coerce_float_validc                 C   s   ddt jg}d}tjt|d t||d W d    n1 s w   Y  d}tjt|d tt ||d W d    d S 1 sCw   Y  d S )Nr9   r   rl  rD   r%   rH  )r'   r   rG   rH   rI   r   r
   rJ   rr  r2   r2   r3   3test_constructor_invalid_coerce_ints_with_float_nang  s   "zJTestSeriesConstructors.test_constructor_invalid_coerce_ints_with_float_nanc                 C   sN   t g d}t |tjd}d|d< |r|d dksJ d S |d dks%J d S )Nr   r%   r   r9   r   )r   r'   r   )r-   using_copy_on_writer   r   r2   r2   r3   test_constructor_dtype_no_castu  s   z5TestSeriesConstructors.test_constructor_dtype_no_castc                 C   sN   t tddgtd}|jd tdksJ |jd dksJ |jtks%J d S )N20130101NOVr%   r   r9   )r   r   r<   r   r&   r;  r2   r2   r3   "test_constructor_datelike_coercion  s   z9TestSeriesConstructors.test_constructor_datelike_coercionc                 C   sn   d  }d  }d  }td  }t|||d|d}|jd }|jtks)J |jd }|jtks5J d S )	Nz216 3T19z	2T15 4H19z416 4T20z2016-01-22 2019-09-07)wing1wing2matrO   3T19216)splitpdto_datetimer   r  r&   r<   )r-   bellyr}  r~  r  r   rk   r2   r2   r3   #test_constructor_datelike_coercion2  s   

z:TestSeriesConstructors.test_constructor_datelike_coercion2c                 C   sB   t ddtjg}||dd}|t dt dtg}t|| d S )Nr   r#   r   r%   )r   r   _valuer*   r+   )r-   rm  rF  rk   r1   r2   r2   r3   (test_constructor_mixed_int_and_timestamp  s   z?TestSeriesConstructors.test_constructor_mixed_int_and_timestampc                 C   sP   t d d d d t d gt d d t d gfD ]}t|}|jdks%J qd S Nr   )r'   rJ   r   nowr   r&   )r-   rn  rk   r2   r2   r3   %test_constructor_datetimes_with_nulls  s   z<TestSeriesConstructors.test_constructor_datetimes_with_nullsc                 C   s   t tdtdd}t| sJ t ttdd}t| r!J t tjdtdd}t| s3J t tdddddtgdd	}t|d sIJ |jdksPJ t tdddddtjgdd	}t|d sgJ |jdksnJ d S )
Nr   r   r   rO   r+  r9   r   r   r%   )	r   r   r   r   r5   r'   r   r   r&   r;  r2   r2   r3   !test_constructor_dtype_datetime64  s   z8TestSeriesConstructors.test_constructor_dtype_datetime64c                 C   s   t dddt dddt dddg}dd |D }t|}|jdks#J tj|jd< |jdks0J t|d	d
}tt|tjd dd
}t	|| t|d	d
}t	|| tt
t dddt dddgdd
}ttjg|dd   dd
}t	|| d S )N  r9   r   r   c                 S      g | ]}t |qS r2   r'   
datetime64r^   r   r2   r2   r3   
<listcomp>  rc   zOTestSeriesConstructors.test_constructor_dtype_datetime64_10.<locals>.<listcomp>r   r   zdatetime64[ms]r%   @B M8[ms]rF   )r   r   r&   r'   r   r   viewr   r*   r=   r   )r-   pydatesdatesr7   r1   rk   r2   r2   r3   $test_constructor_dtype_datetime64_10  s    "z;TestSeriesConstructors.test_constructor_dtype_datetime64_10c                 C   s   t dddt dddt dddg}dd |D }t|dd}|d	 d
}tjt|d |d W d    n1 s<w   Y  t|tjd}t|tj}t	|| d S )Nr  r9   r   r   c                 S   r  r2   r  r  r2   r2   r3   r    rc   zOTestSeriesConstructors.test_constructor_dtype_datetime64_11.<locals>.<listcomp>rF   r%   r   z:Converting from datetime64\[ns\] to int32 is not supportedrD   r   )
r   r   r)   rG   rH   ro   r'   r   r*   r=   )r-   r  r  dtsrK   rk   r1   r2   r2   r3   $test_constructor_dtype_datetime64_11  s   "
z;TestSeriesConstructors.test_constructor_dtype_datetime64_11c                 C   s`   t tdddg}|d tdddddksJ t tdddg}|d tdddddks.J d S )Nr   r9   r   i  )r   r   r   r2   r2   r3   #test_constructor_dtype_datetime64_9  s    z:TestSeriesConstructors.test_constructor_dtype_datetime64_9c                 C   s@   t tddgddgd}|d tdksJ |d dksJ d S )Nrz  r9   rr   rt   rO   )r   r   r   r2   r2   r3   #test_constructor_dtype_datetime64_8  s   z:TestSeriesConstructors.test_constructor_dtype_datetime64_8c           
      C   s(  t dddd}|tjd}t||d}dD ]2}td| d	}|tj|}t||}|d
kr:td}|j|ksAJ t||| qt||t	d}dD ]}|tjd| d	}t||t	d}t|| qTtj
dd | D t	d}t||}	t|	j| |	jt	ksJ d S )Nz01-Jan-2015z01-Dec-2015Mr4  rF   rO   )r   DmsusnszM8[]r  r$   r   c                 S   s   g | ]}|  qS r2   )r;   )r^   r   r2   r2   r3   r        zNTestSeriesConstructors.test_constructor_dtype_datetime64_7.<locals>.<listcomp>r%   )r   r  r'   ndarrayr)   r   r&   r*   r=   r<   rJ   r:   r!  r/   )
r-   r  values2r1   unitr&   values1rk   dates2series1r2   r2   r3   #test_constructor_dtype_datetime64_7  s(   


z:TestSeriesConstructors.test_constructor_dtype_datetime64_7c                 C   sx   t d tdg}|jtksJ t tjtdg}|jtksJ t td dg}|jtks+J t ttjdg}|jtks:J d S )Nz2013-08-05 15:30:00.000001)r   r   r&   r<   r'   r   r6   r2   r2   r3   #test_constructor_dtype_datetime64_6  s   z:TestSeriesConstructors.test_constructor_dtype_datetime64_6c                 C   s|   t ddd}t|jd jd u sJ t dddd}tt|jd jdks'J t dddd}tt|jd jdks<J d S )Nrz  r   rP  r   UTCrO  r   )r   r   r   r   r   )r-   drr2   r2   r3   #test_constructor_dtype_datetime64_5(  s    z:TestSeriesConstructors.test_constructor_dtype_datetime64_5c                 C   s@   t ddtg}|jdksJ |d tu sJ dt|v sJ d S )Nl   *}aiZlr<   r   r   )r   r   r&   r   r;  r2   r2   r3   #test_constructor_dtype_datetime64_42  s   z:TestSeriesConstructors.test_constructor_dtype_datetime64_4c                 C   sP   t tdddtdddtg}|jdksJ |d tu sJ dt|v s&J d S )N  r9   r   r<   r   )r   r   r   r&   r   r;  r2   r2   r3   #test_constructor_dtype_datetime64_39  s   z:TestSeriesConstructors.test_constructor_dtype_datetime64_3c                 C   sT   t tdddtdddtjg}|jdksJ |d tju s J dt|v s(J d S )Nr  r9   r   r<   r   )r   r   r'   r   r&   r   r;  r2   r2   r3   #test_constructor_dtype_datetime64_2@  s    z:TestSeriesConstructors.test_constructor_dtype_datetime64_2c                 C   s  t dddd}t|}|jjdksJ |jdksJ t|js!J dt|v s)J |j}t|tj	s4J |jdks;J t
|}|dj|jjd}t|| |jd	 }|td
ddks_J |d	 }|td
ddksmJ |tg d|jd }t||d	d  |jd	d }t|t|d	d  t|jd	d |jdd  g}t|| dt|v sJ | }dt|v sJ dt|v sJ tt dddd}dt|v sJ t
|dd}t|| d S )Nrz  r   r   rO  datetime64[ns, US/Eastern]rF   r  r   r   z2013-01-01 00:00:00-0500r*  rO   r   r9   r     inferr4  )r   r   r&   rn   r   r   r/   r|   r'   r  r   tz_localize
tz_convertdtr   r*   r>   r   r   rP   r=   r  concatshift)r-   r  r   rk   r   tr2   r2   r3   !test_constructor_with_datetime_tzG  s<   
"z8TestSeriesConstructors.test_constructor_with_datetime_tzc                 C   sD   t tdddtdddg}|jdksJ tj|dddks J d S )	N2013-01-01 13:00:00-0800
US/Pacificr  2013-01-02 14:00:00-0800zdatetime64[ns, US/Pacific]Tskipnar  r   r   r&   r	   infer_dtyper;  r2   r2   r3   "test_constructor_with_datetime_tz4z  s   

z9TestSeriesConstructors.test_constructor_with_datetime_tz4c                 C   sD   t tdddtdddg}|jdksJ tj|ddd	ks J d S )
Nr  r  r  r  r   r<   Tr  r   r  r;  r2   r2   r3   "test_constructor_with_datetime_tz3  s   

z9TestSeriesConstructors.test_constructor_with_datetime_tz3c                 C   s6   t tddgdd}t tddgdd}t|| d S )Nr   r9   r  r   r   r   r  )r   r   r   r*   r=   r]  r2   r2   r3   "test_constructor_with_datetime_tz2  s   z9TestSeriesConstructors.test_constructor_with_datetime_tz2c                    sB   dt dddd gt t fddttD sJ d S )Nr   z
1990-01-01z2015-03-14T16:15:14.123-08:00z2019-03-04T21:56:32.620-07:00c                 3   s     | ]} | | u V  qd S r\   r2   r   r7   r@   r2   r3   r`     s    zVTestSeriesConstructors.test_constructor_no_partial_datetime_casting.<locals>.<genexpr>)r   r   r5   r   rj   r   r2   r  r3   ,test_constructor_no_partial_datetime_casting  s   (zCTestSeriesConstructors.test_constructor_no_partial_datetime_casting	arr_dtypekindr  r   r  )r  r  r  r   hr   r  c           	      C   s   | d| d}t jg d|d}t|}||}t||}|dv r4|j|ks,J |j|ks3J n|j| dks>J |j| dksHJ t|| d S )N8[r  r   r%   )r  r  r  r   z8[s])r'   rJ   r   r)   r&   r*   r=   )	r-   r  r  r  r&   rn  r7   rk   r1   r2   r2   r3   &test_construction_to_datetimelike_unit  s   
z=TestSeriesConstructors.test_construction_to_datetimelike_unitargz2013-01-01 00:00:00c                 C   s2   t |gdd}t t|jd}t|| d S )Nzdatetime64[ns, CET]r%   CET)r   r   r  r  r*   r=   )r-   r  rk   r1   r2   r2   r3   7test_constructor_with_naive_string_and_datetimetz_dtype  s   zNTestSeriesConstructors.test_constructor_with_naive_string_and_datetimetz_dtypec                 C   s^   t dd}t jt ddgdd}t|}tt|gd}|jdks'J t|| d S )Nr9   r  z>M8[ms]r%   r  )	r'   r  rJ   r   r   r)   r&   r*   r=   )r-   r  rn  rk   r1   r2   r2   r3   %test_constructor_datetime64_bigendian  s   z<TestSeriesConstructors.test_constructor_datetime64_bigendianinterval_constructorc                 C   sD   |j tddd}t|}|jdksJ tt|jt| d S )Nr   r   closedzinterval[int64, right])	from_breaksr'   r(   r   r&   r*   r>   r   r/   )r-   r  	intervalsrk   r2   r2   r3   test_construction_interval  s   z1TestSeriesConstructors.test_construction_intervaldata_constructorr,   zndarray[object]c                 C   sL   t ddt ddd g}t||}tt|}|jdksJ t|| d S )Nr   r9   r   zinterval[float64, right])r   r   r   r&   r*   r=   r-   r  rf   rk   r1   r2   r2   r3   test_constructor_infer_interval  s
   z6TestSeriesConstructors.test_constructor_infer_intervalc                 C   sJ   t ddddt ddddg}t||}|jtksJ | |ks#J d S )Nr   r9   bothr  r   neither)r   r   r&   r<   r   )r-   r  rf   rk   r2   r2   r3   &test_constructor_interval_mixed_closed  s   z=TestSeriesConstructors.test_constructor_interval_mixed_closedc                 C   s(  t tdddd}t ||jd}t|| t |jd|jd}t|| t |j|jd}t |jj|jj	}t|| t
d  t |jjd}|j|jj	}W d    n1 saw   Y  t|| t
d  t |jd|jd}W d    n1 sw   Y  t|| d S )Nrz  r   r   rO  r%   r  r   )r   r   r&   r*   r=   r  r  r/   r  r   assert_produces_warningr  )r-   r7   rk   r1   middler2   r2   r3   test_construction_consistency  s"   z4TestSeriesConstructors.test_construction_consistencyc                 C   sL   t ddt ddd g}t||}tt|}t|| |jdks$J d S )N2000r  2001	Period[D])r   r   r    r*   r=   r&   r  r2   r2   r3   test_constructor_infer_period  s
   z4TestSeriesConstructors.test_constructor_infer_periodz$PeriodDtype Series not supported yetreasonc                 C   sH   t dddtjjgdd}|d }t|sJ ||d< t|d s"J d S )Nr   r    z	period[D]r%   r   r   )r   r  _libsr   r   r-   r  valr2   r2   r3   ;test_construct_from_ints_including_iNaT_scalar_period_dtype  s
   zRTestSeriesConstructors.test_construct_from_ints_including_iNaT_scalar_period_dtypec                 C   s>   t ddt ddg}t|}|jtksJ | |ksJ d S )Nr  r  r  rw   )r   r   r&   r<   r   )r-   rf   rk   r2   r2   r3   .test_constructor_period_incompatible_frequency  s   zETestSeriesConstructors.test_constructor_period_incompatible_frequencyc                 C   sB   t dddd}t|}|jdksJ t|t}t|| d S )Nrz  r   r  r   r  )r   r   r&   r)   r<   r*   r=   )r-   pir   r1   r2   r2   r3   test_constructor_periodindex  s
   z3TestSeriesConstructors.test_constructor_periodindexc                 C   s   dddd}t |}t |t| d}t|| t |g dd}t ddtjd	gg dd}t|| td
}|d	 d	|d di}t ||d}t tj|tjd}d	|j	d	< d|j	d< t|| d S )Nr)  r   r   r   rO   )rt   r   r   rr   r9   r   r   r?  r%   )
r   r   keysr*   r=   r'   r   makePeriodIndexr   r   )r-   r   rk   r1   pidxr2   r2   r3   test_constructor_dict'  s   


z,TestSeriesConstructors.test_constructor_dictc                 C   sB   ddgdgdggi}t |dgdd}t |dgd}t|| d S )Nrr   r   r   r   r<   r   rO   r   r-   r   rk   r1   r2   r2   r3   /test_constructor_dict_list_value_explicit_dtype:  s   zFTestSeriesConstructors.test_constructor_dict_list_value_explicit_dtypec                 C   s8   dddd}t |}t g dtdd}t|| d S )Nr9   r   r   r   )r9   r   r   bacrO   )r   r,   r*   r=   r  r2   r2   r3   test_constructor_dict_orderA  s   z2TestSeriesConstructors.test_constructor_dict_orderc                 C   sL   |\}}d|i}t |dgd}t |dg|d}|j|ksJ t|| d S )Nrr   rO   r   )r   r&   r*   r=   )r-   r   r   r   r   rk   r1   r2   r2   r3   test_constructor_dict_extensionJ  s   z6TestSeriesConstructors.test_constructor_dict_extensionre  c                 C   s   dd|dt ddddi}t| }tg dd|tjdgd	}t|| d
ddtjfdd|fdi}t| }tg dtd
dtjfd|fgd	}t|| d S )Nr9   rr   rt   r   r   r   r   rr   rt   r   r   rO   r9   r9   r   r   r   )r}   r   sort_valuesr'   r   r*   r=   r   )r-   re  r   rk   r1   r2   r2   r3   test_constructor_dict_nan_keyT  s   z4TestSeriesConstructors.test_constructor_dict_nan_keyc           	         s   g d g d fdd}|t j}|dd }|t}tdd  D }t|}t|}t|}t|| t|| t|| d S )	N)z
1984-02-19z
1988-11-06z
1989-12-03z
1990-03-15)g{\IAi gtyZQArg  c                    s   t t fddD S )Nc                 3   s    | ]} |V  qd S r\   r2   r  rM   r2   r3   r`   k      zeTestSeriesConstructors.test_constructor_dict_datetime64_index.<locals>.create_data.<locals>.<genexpr>)dictzipr  dates_as_strr/   r  r3   create_dataj  s   zRTestSeriesConstructors.test_constructor_dict_datetime64_index.<locals>.create_datac                 S   s   t | dS )Nz%Y-%m-%d)r   strptimer   r2   r2   r3   rS   n  rV   zOTestSeriesConstructors.test_constructor_dict_datetime64_index.<locals>.<lambda>c                 s   s    | ]}t |V  qd S r\   )r   r  r2   r2   r3   r`   q  r  zPTestSeriesConstructors.test_constructor_dict_datetime64_index.<locals>.<genexpr>)r'   r  r   r   r*   r=   )	r-   r  data_datetime64data_datetimedata_Timestampr1   result_datetime64result_datetimeresult_Timestampr2   r  r3   &test_constructor_dict_datetime64_indexd  s   
z=TestSeriesConstructors.test_constructor_dict_datetime64_indexc                 C   sN   ddi}t |}t dtdgdgtjggdgdgdggdd}t|| d S )N)r9   r9   Ng      r9   r   rg  )levelscodesrO   )r   r   r'   r   r*   r=   r0  r2   r2   r3   #test_constructor_dict_tuple_indexer{  s   &z:TestSeriesConstructors.test_constructor_dict_tuple_indexerc                 C   s4   |ddi}t |}t dgdgd}t|| d S )Nr   threerO   r   )r-   non_dict_mapping_subclassndmrk   r1   r2   r2   r3   test_constructor_mapping  s   z/TestSeriesConstructors.test_constructor_mappingc                 C   s$   g d}t |}t||ksJ d S N)r  )r   r   )r   r   )r   r,   r-   rf   r   r2   r2   r3   test_constructor_list_of_tuples  s   z6TestSeriesConstructors.test_constructor_list_of_tuplesc                 C   s    d}t |}t||ksJ d S r  )r   tupler  r2   r2   r3    test_constructor_tuple_of_tuples  s   z7TestSeriesConstructors.test_constructor_tuple_of_tuplesc                 C   s@   ddd}t | }t ddgtddgd}t|| d S )Nr   r   )r9   r   Nr   r  r  rO   )r   r  r   from_tuplesr*   r=   r0  r2   r2   r3   test_constructor_dict_of_tuples  s   
z6TestSeriesConstructors.test_constructor_dict_of_tuplesz+ignore:elementwise comparison:FutureWarningc                 C   s   ddddd}t |}t|j dddt d}t |}|jtjks&J ddddd}t |}|jtjks9J d	dd
}t |t	d}|jtj
ksLJ d S )Nr   r9   r   r   r  r   r   30rr   rt   r%   )r   r*   assert_is_sortedrP   r   r  r&   r'   r   r}   r   )r-   rf   r  r2   r2   r3   test_fromDict  s   
z$TestSeriesConstructors.test_fromDictc                 C   s   t tj|jtjd}|jtjksJ t|t|ksJ t d|jd}|jtjks+J t|t|ks5J t	
 }t ||jd}|jdksGJ t|t|ksQJ t d|jdd}t d|jdd}|jdksjJ t|t|kstJ t|| d S )Nr   rA  rO   r   r   r   )r   r'   r   rP   r   r&   float_rj   r   r   r  r)   r*   r=   )r-   r   nansstringsr   r  categoricalr1   r2   r2   r3   test_fromValue  s   z%TestSeriesConstructors.test_fromValuec                 C   s  t dd tdD }|jdksJ t tddg}|jdks!J t tddtddtddg}|jdks9J t tddtgd	d
}|jdksKJ t tddtjgd	d
}|jdks^J t tdtgd	d
}|jdkspJ t tdtg}|jdksJ t tdtg}|jdksJ t tdtjg}|jdksJ t ttdg}|jdksJ t tddg}|jdksJ |	d d}t
jt|d |	d W d    n1 sw   Y  dddg}t
jt|d t tdddgd	d
 W d    n	1 s	w   Y  t dd tdD dg }|jdks$J t d tdg}|jtks3J t tjtdg}|jtksCJ t td dg}|jtksRJ t ttjdg}|jtksbJ d S )Nc                 S      g | ]}t |d qS daysr   r   r2   r2   r3   r    rc   zMTestSeriesConstructors.test_constructor_dtype_timedelta64.<locals>.<listcomp>r   timedelta64[ns]r9   r(  r   r   r   r%   i r<   r   z;Converting from timedelta64\[ns\] to int32 is not supportedrD   r   |z+Could not convert object to NumPy timedeltaz*Could not convert 'foo' to NumPy timedeltarA  c                 S   r&  r'  r*  r   r2   r2   r3   r    rc   z1 Day)r   r   r&   r   r'   timedelta64r   r   r   r)   rG   rH   ro   joinrI   r<   )r-   tdrK   r7   r2   r2   r3   "test_constructor_dtype_timedelta64  sZ   "
z9TestSeriesConstructors.test_constructor_dtype_timedelta64c                 C   sD   t tdtdddg}t tdtdddgdd}t|| d S )Nrz  r   r  r<   r%   )r   r   r*   r=   r]  r2   r2   r3   test_constructor_mixed_tz  s   z0TestSeriesConstructors.test_constructor_mixed_tzc                 C   sD   t dddtgdd}|d }t|sJ ||d< t|d s J d S )Nr   r  r  r   r%   r   r   )r   r   r   r  r2   r2   r3   test_NaT_scalar  s
   z&TestSeriesConstructors.test_NaT_scalarc                 C   s,   t tjgd}t tg}t|| d S r  )r   r'   r   r)   r   r*   r=   r  r2   r2   r3   test_NaT_cast$  s   
z$TestSeriesConstructors.test_NaT_castc                 C   s\   dddt dddddfD ]}g dtd	d
ddfD ]}t||d}|j|ks*J qqd S )Ni	  g     H@rn   r+     r5  u   אr   r   r   r9   r  r  )r   r'   onesr   rn   )r-   nrf   r   r2   r2   r3   test_constructor_name_hashable*  s   z5TestSeriesConstructors.test_constructor_name_hashablec              
   C   sz   d}dgt dddifD ]-}dgt dddifD ]}tjt|d t||d W d    n1 s4w   Y  qqd S )Nz$Series\.name must be a hashable type	name_listr   r9   rD   r  )r'   r5  rG   rH   ro   r   )r-   rK   r6  rf   r2   r2   r3    test_constructor_name_unhashable0  s   z7TestSeriesConstructors.test_constructor_name_unhashablec                 C   s&   t ttddd}|jdksJ d S )N1/1/2000r#   rP  r   )r   r,   r   r&   r-   r  r2   r2   r3   test_auto_conversion7  s   z+TestSeriesConstructors.test_auto_conversionc                 C   s   t jg ddd}t|}|j|jksJ tddddd}t|}|j|jks+J t|| t jg dd	d}t|}ttd
ddddd}|jdksPJ t|| t jg ddd}t|}ttdddddd}|jdksuJ t|| d S )Nr   timedelta64[s]r%   z00:00:01r   r   r   )
2013-01-01z
2013-01-02z
2013-01-03zdatetime64[D]rz  r  r$   )z2013-01-01 00:00:01z2013-01-01 00:00:02z2013-01-01 00:00:03zdatetime64[s]z20130101 00:00:01)	r'   rJ   r   r&   r   as_unitr*   r=   r   )r-   rn  r7   tdir1   r2   r2   r3   test_convert_non_ns;  s0   z*TestSeriesConstructors.test_convert_non_nsr:  r#   z2000-Q1c                 C   rS  r\   rT  r   r2   r2   r3   rS   a  rT   c                 C   s   dt |jd d}tjt|d t|td W d    n1 s$w   Y  t|tj	d}t|
tj	}t|| d S )NzCannot cast r   z.*? to rD   r%   )rU  r   rstriprG   rH   ro   r   r}   r'   r   r)   r*   r=   )r-   rP   rK   rk   r1   r2   r2   r3   'test_constructor_cant_cast_datetimelikeZ  s   z>TestSeriesConstructors.test_constructor_cant_cast_datetimelikec                 C   rS  r\   rT  r   r2   r2   r3   rS   {  rT   c                 C   s   t |td}t |t}t|| t t|tdtd}t |t}t|| t |ttd}t |t}t|| d S r   )r   r<   r)   r*   r=   r   )r-   rP   r   r   r2   r2   r3   test_constructor_cast_objectt  s   
z3TestSeriesConstructors.test_constructor_cast_objectc                 C   sn   d}t |jdvrtjjdd}|j| tjt	|d t
g |d W d    d S 1 s0w   Y  d S )Nz!dtype has no unit. Please pass in)r-  r  zGH#33890 Is assigned ns unitr  rD   r%   )r'   r&   rn   rG   markxfailnode
add_markerrH   rI   r   )r-   r&   requestrK   rE  r2   r2   r3   /test_constructor_generic_timestamp_no_frequency  s   "zFTestSeriesConstructors.test_constructor_generic_timestamp_no_frequency)	psasfsYr  Wr  r  r   c                 C   s   | d| d}d}t jt|d tg |d W d    n1 s"w   Y  t jt|d tdgg|d W d    d S 1 sBw   Y  d S )Nr  r  z4dtype=.* is not supported. Supported resolutions arerD   r%   r   )rG   rH   ro   r   r   )r-   r  r  r&   rK   r2   r2   r3   0test_constructor_generic_timestamp_bad_frequency  s   "zGTestSeriesConstructors.test_constructor_generic_timestamp_bad_frequency)Nrc  r   c                 C   s4   t g d|pdd}t td|d}t|| d S )N)r   r9   r   r   r   r   r%   r   r   )r-   r&   r1   rk   r2   r2   r3   test_constructor_range_dtype  s   z3TestSeriesConstructors.test_constructor_range_dtypec                 C   sH  t dd}t|}tt|}t|| t|t|ksJ |jtjks'J t ddd}t|}tt|}t|| t|t|ksGJ |jtjksOJ t ddd}t|}tt|}	t||	 t|t|ksoJ |jtksvJ t dd dd d }
t|
}tt|
}t|| t|t|
ksJ |jtksJ d S )	Nl            l           rg  l         l        r   I   r   )	r   r   r,   r*   r=   r&   r'   uint64r<   )r-   r8  r7   r1   rng2ser2	expected2rng3ser3	expected3rng4ser4	expected4r2   r2   r3    test_constructor_range_overflows  s0   
z7TestSeriesConstructors.test_constructor_range_overflowsc                 C   s8   t dt dddg}t|}t|td}t|| d S )Nz2016-05-01 02:03:37z2016-04-30 19:03:37-0700r  r  r%   )r   r   r<   r*   r=   )r-   dt_listrk   r1   r2   r2   r3   test_constructor_tz_mixed_data  s   
z5TestSeriesConstructors.test_constructor_tz_mixed_datapydtTFc                 C   s(  |}t d|d}|r| }d}tjt|d t|gdd W d    n1 s)w   Y  tjt|d ttj|gtddd W d    n1 sLw   Y  tjt|d td|idd W d    n1 skw   Y  d}tjt	|d t|dgdd	 W d    d S 1 sw   Y  d S )
N2019r  zsCannot convert timezone-aware data to timezone-naive dtype. Use pd.Series\(values\).dt.tz_localize\(None\) instead.rD   rF   r%   r   z/Cannot unbox tzaware Timestamp to tznaive dtyper   )
r   r:   rG   rH   rI   r   r'   rJ   r<   ro   )r-   tz_aware_fixturer`  r   r?   rK   r2   r2   r3   'test_constructor_data_aware_dtype_naive  s&   "z>TestSeriesConstructors.test_constructor_data_aware_dtype_naivec                 C   s<   t dddd}t|}t|}t|jtdsJ d S )Nz1/1/2000 00:00:00z1/1/2000 1:59:5010sr4  r   )r   r'   asarrayr   
issubdtyper&   )r-   r8  r  r  r2   r2   r3   test_constructor_datetime64  s   
z2TestSeriesConstructors.test_constructor_datetime64c                 C   s8   t dg d|d}t g dg d|d}t|| d S )Nr  r   r   )r  r  r  r   )r-   nullable_string_dtyperk   r1   r2   r2   r3   4test_constructor_datetimelike_scalar_to_string_dtype  s   zKTestSeriesConstructors.test_constructor_datetimelike_scalar_to_string_dtypez
2012-01-01r>  c                 C   s>   t d}t||d}t jj||d}t|}t|| d S )NrF   r%   )r  SparseDtyper   arraysSparseArrayr*   r=   )r-   r/   r&   rk   rn  r1   r2   r2   r3   "test_constructor_sparse_datetime64  s
   
	z9TestSeriesConstructors.test_constructor_sparse_datetime64c                 C   sX   t ddd }t ddg}t|| t ddd }t ddg}t|| d S )Nr9   r   r  rr   rt   )r   r  r*   r=   r/   r  r2   r2   r3   )test_construction_from_ordered_collection  s   z@TestSeriesConstructors.test_construction_from_ordered_collectionc                 C   s*   d}t |dgd}t |}t|| d S )Nl     @=7M.cr   rO   r   )r-   r6  rk   r1   r2   r2   r3   3test_construction_from_large_int_scalar_no_overflow  s   zJTestSeriesConstructors.test_construction_from_large_int_scalar_no_overflowc                 C   sR   t ttdddd}|jdksJ t tdddtdddg}|jdks'J d S )	Nz
2000-01-01r#   r  r   r  z
2011-01-01r4  z
2011-02-01)r   r,   r   r&   r   r;  r2   r2   r3   4test_constructor_list_of_periods_infers_period_dtype  s   zKTestSeriesConstructors.test_constructor_list_of_periods_infers_period_dtypec                 C   s>   |dd t dD }t|}tt| }t|| d S )Nc                 s   s    | ]	}|d | fV  qdS )g      $@Nr2   r  r2   r2   r3   r`   (  s    zHTestSeriesConstructors.test_constructor_subclass_dict.<locals>.<genexpr>r#   )r   r   r  itemsr*   r=   )r-   dict_subclassrf   r  r1   r2   r2   r3   test_constructor_subclass_dict'  s   z5TestSeriesConstructors.test_constructor_subclass_dictc                 C   sp   t dd tdD }t|}tt| t| }t|| G dd dt }t||}t|| d S )Nc                 s   s$    | ]}d | t j fV  qdS )colN)r'   r   r   r2   r2   r3   r`   /  s   " zFTestSeriesConstructors.test_constructor_ordereddict.<locals>.<genexpr>   c                   @   s   e Zd ZdS )z>TestSeriesConstructors.test_constructor_ordereddict.<locals>.AN)r   r   r   r2   r2   r2   r3   rw   6  s    rw   )r   r   r   r,   r/   r  r*   r=   )r-   rf   r  r1   rw   r2   r2   r3   test_constructor_ordereddict-  s   z3TestSeriesConstructors.test_constructor_ordereddictc                 C   s   dddd}t | }t|}tdd |D tdd |D d}t|| d	|d
< |dd
|d
 f t|}tdd |D tdd |D ddd}|j	|j
d}t|| d S )Nr)  r   r   ))rr   rr   )rt   rr   )rt   r   c                 S      g | ]}|d  qS r5  r2   r  r2   r2   r3   r  A  r  zKTestSeriesConstructors.test_constructor_dict_multiindex.<locals>.<listcomp>c                 S   rw  r   r2   r  r2   r2   r3   r  A  r  rO   g     [@zr   c                 S   rw  r5  r2   r  r2   r2   r3   r  I  r  c                 S   rw  rx  r2   r  r2   r2   r3   r  I  r  F)tupleize_cols)r   rq  r   r   r  r*   r=   insertr   reindexrP   )r-   r   _drk   r1   r2   r2   r3    test_constructor_dict_multiindex<  s    z7TestSeriesConstructors.test_constructor_dict_multiindexc                 C   sB   dddt jd}t|}t|d d  |jd}t|| d S )Nr   r9   r   ))r   r   )r   j)r  r   r  rg  rO   )r'   r   r   to_dictrP   r*   r=   )r-   rf   r1   rk   r2   r2   r3   -test_constructor_dict_multiindex_reindex_flatN  s   zDTestSeriesConstructors.test_constructor_dict_multiindex_reindex_flatc              	   C   sr   t g dtjg dddd}t tjddddtjdddd	tjd
ddditjg dddd}t|| d S )Nr	  )r   r#   r   r   r  re   r   rw   r#   rx   r   r
  r   r  to_timedeltar*   r=   r   r2   r2   r3   %test_constructor_dict_timedelta_indexV  s   z<TestSeriesConstructors.test_constructor_dict_timedelta_indexc                 C   sd   ddg}t d d}tdddd|dtdddd|dg}t||d	}|jj|ks)J t|jd
  d S )Ng     g@g     t@i   i  r   r4  )tzinforu  re   r   )r   r   r   rP   r   repr)r-   r/   r  rP   r  r2   r2   r3   test_constructor_infer_index_tzh  s   
z6TestSeriesConstructors.test_constructor_infer_index_tzc                 C   s4   g d}t |}|jj}t ||d}t|| d S )N)r5  )r   r(  r%   )r   rJ   r&   r*   r=   )r-   r@   r7   r&   rU  r2   r2   r3   "test_constructor_with_pandas_dtypev  s
   z9TestSeriesConstructors.test_constructor_with_pandas_dtypec                 C   s0   t dgdd}t tjdgdd}t|| d S )Nr   r   r   r   )r   r'   r   r*   r=   r  r2   r2   r3   )test_constructor_int_dtype_missing_values~  s   z@TestSeriesConstructors.test_constructor_int_dtype_missing_valuesc                 C   s.   t dgdd}t ddgdd}t|| d S )Nr   r   r   Tr   r  r2   r2   r3   *test_constructor_bool_dtype_missing_values  s   zATestSeriesConstructors.test_constructor_bool_dtype_missing_valuesc                 C   s0   t g d|d}t g d|d}t|| d S )N)r  r   r   r%   r   r   )r-   any_int_dtyperk   r1   r2   r2   r3   test_constructor_int64_dtype  s   z3TestSeriesConstructors.test_constructor_int64_dtypec                 C   sB   t jtdd tdgdd W d    d S 1 sw   Y  d S )Nz/string values cannot be losslessly cast to int8rD   128rb  r%   rB  r   r2   r2   r3   5test_constructor_raise_on_lossy_conversion_of_strings  s
   "zLTestSeriesConstructors.test_constructor_raise_on_lossy_conversion_of_stringsc                 C   s6   t g ddd}t tjg ddd}t|| d S )Nr  i@ i- r+  r%   r  r  r  r  r2   r2   r3   6test_constructor_dtype_timedelta_alternative_construct  s   zMTestSeriesConstructors.test_constructor_dtype_timedelta_alternative_constructzNot clear what the correct expected behavior should be with integers now that we support non-nano. ATM (2022-10-08) we treat ints as nanoseconds, then cast to the requested dtype. xref #48312c                 C   s0   t g ddd}t g ddd}t|| d S )Nr  r+  r%   r=  r   r  r2   r2   r3   %test_constructor_dtype_timedelta_ns_s  s   z<TestSeriesConstructors.test_constructor_dtype_timedelta_ns_sc                 C   s<   t g dddd}t g dddd}t|| d S )Nr  r+  r%   r   r=  r   r  r2   r2   r3   2test_constructor_dtype_timedelta_ns_s_astype_int64  s   zITestSeriesConstructors.test_constructor_dtype_timedelta_ns_s_astype_int64z7ignore:elementwise comparison failed:DeprecationWarningfuncc              	   C   sd   d g d}tjtg D ]"}tjt|d ||ddg|d W d    n1 s*w   Y  qd S )Nr,  )z(cannot safely cast non-equivalent objectzJint\(\) argument must be a string, a bytes-like object or a (real )?numberz[Cannot cast array data from dtype\('O'\) to dtype\('float64'\) according to the rule 'safe'z-object cannot be converted to a FloatingDtypez 'values' contains non-numeric NArD   r   g      @r%   )r.  r*   NP_NAT_OBJECTSr   rG   rH   ro   )r-   r  any_numeric_ea_dtyperK   nullr2   r2   r3   /test_constructor_mismatched_null_nullable_dtype  s   zFTestSeriesConstructors.test_constructor_mismatched_null_nullable_dtypec                 C   sh   t dddtjgdd}t dddtjgdd}t|| t g ddd}t g ddd}t|| d S )	NTFInt64r%   r9   r   )TFT)r9   r   r9   )r   r  NAr*   r=   r  r2   r2   r3   (test_series_constructor_ea_int_from_bool  s   z?TestSeriesConstructors.test_series_constructor_ea_int_from_boolc                 C   sJ   t jtdd tdddtjgdd W d    d S 1 sw   Y  d S )Nzinvalid literalrD   TrueFalser  r%   )rG   rH   rI   r   r  r  r   r2   r2   r3   /test_series_constructor_ea_int_from_string_bool  s   "zFTestSeriesConstructors.test_series_constructor_ea_int_from_string_boolr  r   c                 C   sL   t t jjd }t||gdd}tt j|dgdddd}t|| d S )Nr9   UInt64r%   rS  )r'   iinforS  maxr   rJ   r*   r=   r-   r  max_valrk   r1   r2   r2   r3   (test_series_constructor_overflow_uint_ea  s   z?TestSeriesConstructors.test_series_constructor_overflow_uint_eac                 C   sd   t t jjd }t||tjgdd}ttt j|ddgddt jg dt j	d}t
|| d S )Nr9   r  r%   r   rS  )r   r   r9   )r'   r  rS  r  r   r  r  r   rJ   bool_r*   r=   r  r2   r2   r3   0test_series_constructor_overflow_uint_ea_with_na  s   zGTestSeriesConstructors.test_series_constructor_overflow_uint_ea_with_nac                 C   s`   t t jjd }t|t jgdd}ttt j|dgddt jddgt jd}t	
|| d S )Nr9   r  r%   rS  r   )r'   r  rS  r  r   r   r   rJ   r  r*   r=   )r-   r  rk   r1   r2   r2   r3   .test_series_constructor_overflow_uint_with_nan  s   zETestSeriesConstructors.test_series_constructor_overflow_uint_with_nanc                 C   sP   t tjtjgdd}t ttjddgddtjddgtjd}t|| d S )Nr  r%   r9   rS  )r   r'   r   r   rJ   r  r*   r=   r  r2   r2   r3   !test_series_constructor_ea_all_na  s   z8TestSeriesConstructors.test_series_constructor_ea_all_nac                 C   s>   t g d}|jdd}t|dd}d|jd< t|| d S )Nr   T)deepr   r%   r?  r   )r   r  r   r   r*   r>   )r-   rA   r1   r7   r2   r2   r3   0test_series_from_index_dtype_equal_does_not_copy
  s
   
zGTestSeriesConstructors.test_series_from_index_dtype_equal_does_not_copy)r   r   r   r4   r8   rB   rL   rG   rE  parametrizerl   rq   r{   r   r   r   r   r,   r  r   r   r'   r   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r  r&  r'  r.  r1  r9  r<  r   r   r   r>  r@  rD  rG  rJ  rM  r/  skip_array_manager_invalid_testr   r   r   rZ  r\  r^  r_  r`  rd  rJ   uint16uint32rS  rf  rj  rp  rt  rv  rw  ry  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r  r   r  r  r   r   r  r  r  r  r  rF  r  r  r  r  r  r  r  r  r  r  r  r  r  r  filterwarningsr   r%  r0  r1  r2  r3  r7  r9  r<  rA  rC  rD  r  r-  rJ  rP  rQ  r]  r_  rc  rg  ri  rm  rn  ro  rp  rs  rv  r~  r  r  r  r  r  r  r  r  r  r  r  r   r   r  r  r  r  r  r  r  r  r  r2   r2   r2   r3   r"   6   s$   

	&
"


		



%	!M






		



,		
3







	
	
	M			


	

r"   c                   @   s   e Zd Zdd Zdd ZdS )"TestSeriesConstructorIndexCoercionc                 C   s:   t d}ttjt||t}t	|j
trJ d S )Ni'  )r*   makeDateIndexr   r'   r   r   rj   r)   r<   r|   rP   r   )r-   rA   r7   r2   r2   r3   3test_series_constructor_datetimelike_index_coercion  s   
zVTestSeriesConstructorIndexCoercion.test_series_constructor_datetimelike_index_coercionc                 C   sv   g dg dg}t ddd |D d}t|jtsJ t d|d}t|jts)J t td|d}t|jts9J d S )N)rr   rr   rt   rt   )r   rL  r   rL  r   c                 S   r  r2   )r'   rJ   r  r2   r2   r3   r    rc   z_TestSeriesConstructorIndexCoercion.test_series_constructor_infer_multiindex.<locals>.<listcomp>rO   r   )r   r|   rP   r   r   )r-   index_listsmultir2   r2   r3   (test_series_constructor_infer_multiindex  s   zKTestSeriesConstructorIndexCoercion.test_series_constructor_infer_multiindexN)r   r   r   r  r  r2   r2   r2   r3   r    s    r  c                   @   s0   e Zd Zdd Zejdd Zejdd ZdS )TestSeriesConstructorInternalsc                 C   sD   t g d}t |j}t|| |st|jjd ts J d S d S )Nr   r   )r   rJ   r*   r=   r|   rX  rY  r!   )r-   using_array_managerr7   rk   r2   r2   r3    test_constructor_no_pandas_array)  s   
z?TestSeriesConstructorInternals.test_constructor_no_pandas_arrayc                 C   sZ   t tjddgdd}|jjd jdu sJ t tjdgdd}|jjd jdu s+J d S 	N1H2Hr+  r%   r   F2015rF   )r   r  rJ   rX  rY  is_extensionr   r2   r2   r3   test_from_array0  s   z.TestSeriesConstructorInternals.test_from_arrayc                 C   sN   t ddgdd}|jjd jdu sJ t dgdd}|jjd jdu s%J d S r  )r   rX  rY  r  r   r2   r2   r3   test_from_list_dtype8  s   z3TestSeriesConstructorInternals.test_from_list_dtypeN)r   r   r   r  r/  r  r  r  r2   r2   r2   r3   r  (  s    
r  c                 C   s&   | }t |ts	J t |jtsJ d S r\   )r|   r   rP   r   )(rand_series_with_duplicate_datetimeindexdupsr2   r2   r3   r   A  s   r   zinput_dict,expectedr%   rr   r9   c                 C   s    t t| g}t|| d S r\   )r'   rJ   r   r*   r!  )
input_dictr1   rk   r2   r2   r3   test_numpy_arrayG  s   	r  )?collectionsr   r   r   typingr   dateutil.tzr   numpyr'   r   rG   pandas._libsr   r	   pandas.errorsr
   pandas.util._test_decoratorsutil_test_decoratorsr/  pandas.core.dtypes.commonr   r   pandas.core.dtypes.dtypesr   pandasr  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   pandas._testing_testingr*   pandas.core.arraysr   r   r    pandas.core.internals.blocksr!   r"   r  r  r   rE  r  rJ   r   r<   r  r2   r2   r2   r3   <module>   sX    H               l