U
    *if#                 
   @   s  d dl mZ d dlmZ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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/m0Z0 d dl1m2Z2m3Z3 d dl4m5Z5 G dd dZ6G dd dZ7G dd dZ8dd Z9e
j:;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e
j:j?edddd Z@e
j:j?e dddd ZAdS )     )OrderedDict)datetime	timedelta)tzoffsetN)iNaTlib)np_version_under1p19np_version_under1p20)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)
Int64Index)IntervalArrayperiod_array)NumericBlockc                   @   s	  e Zd Zejddd dfdd dfdd dfdd dfd	d dfd
d dfdd dfdd dfdd dfdd dfdd df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%d&d'd(d)d*d+d,gejd-d.eg gd/d0 Zd1d2 Zd3d4 Zejd5d6d7d8gd9d: Zd;d< Zd=d> Zd?d@ ZdAdB ZdCdD ZdEdF ZdGdH Z ejd%dIdJdKdLgdMdN Z!ejdOdPdQgdRdSgee"dTdQdUdVee"dTdQdUdWdXe#dYdZd[ggd\d] Z$d^d_ Z%d`da Z&dbdc Z'ddde Z(dfdg Z)dhdi Z*djdk Z+dldm Z,dndo Z-dpdq Z.drds Z/dtdu Z0dvdw Z1dxdy Z2dzd{ Z3d|d} Z4d~d Z5ejddPdQdgdee6de7dddgdd e6dD e8dd e6dgdd Z9dd Z:dd Z;dd Z<dd Z=dd Z>e?j@ejjd-e"dddWde"dddeAdddeBddddVeedeCdPdQdgeDdYdgdd ddd ZEdd ZFdd ZGdd ZHdd ZIdd ZJdd ZKdd ZLdd ZMdd ZNdd ZOdd ZPdd ZQdd ZRdd ZSdd ZTdd ZUdd ZVdd ZWddĄ ZXddƄ ZYddȄ ZZddʄ Z[dd̄ Z\dd΄ Z]ddЄ Z^dd҄ Z_ddԄ Z`ddք Zaejdejbejcgejd%ddgejddddddddgdd Zdejddeeejd.gdd Zfdd Zgejdeheigdd Zjejjdeejkgddgddd Zlejjdeejkgddgddd Zmdd Znejjdeejkgddgddd Zoejjpdddd Zqdd Zrdd Zsd d Ztdd Zudd Zvdd ZwejddQejd.ed"gd	d
 Zxdd Zydd Zzdd Z{dd Z|dd Z}dd Z~e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eAdd-deBd.d-ddVgd/d dd0d1 Zejjd-e"d,d-deAdd-deBd.d-ddVgd2d dd3d4 Zejd%ejejgd5d6 Zejd7d8d9gd:d; Zejd%d.d<d*gd=d> Zd?d@ ZdAdB ZejdCddgdDdE ZdFdG ZdHdI ZejdJedKedLgdKdLggdMdN ZdOdP ZdQdR ZdSdT ZdUdV ZdWdX ZdYdZ Zd[d\ Zd]d^ Zd_d` Zdadb Zdcdd Zdedf Zejdgejjpedhdejdieeeejkgdjdk Zd.S (l  TestSeriesConstructorszconstructor,check_index_typec                   C   s   t  S Nr    r$   r$   X/home/mars/bis/venv/lib/python3.8/site-packages/pandas/tests/series/test_constructors.py<lambda>@       zTestSeriesConstructors.<lambda>Tc                   C   s   t d S r"   r#   r$   r$   r$   r%   r&   A   r'   c                   C   s   t i S r"   r#   r$   r$   r$   r%   r&   B   r'   c                   C   s   t dS )Nr$   r#   r$   r$   r$   r%   r&   C   r'   Fc                   C   s   t g S r"   r#   r$   r$   r$   r%   r&   D   r'   c                   C   s   t dd dD S )Nc                 s   s   | ]
}|V  qd S r"   r$   .0_r$   r$   r%   	<genexpr>E   s     2TestSeriesConstructors.<lambda>.<locals>.<genexpr>r$   r#   r$   r$   r$   r%   r&   E   r'   c                   C   s
   t d dS Ndatar#   r$   r$   r$   r%   r&   F   r'   c                   C   s
   t i dS r-   r#   r$   r$   r$   r%   r&   G   r'   c                   C   s
   t ddS )Nr$   r.   r#   r$   r$   r$   r%   r&   H   r'   c                   C   s
   t g dS r-   r#   r$   r$   r$   r%   r&   I   r'   c                   C   s   t dd dD dS )Nc                 s   s   | ]
}|V  qd S r"   r$   r(   r$   r$   r%   r+   J   s     r,   r$   r.   r#   r$   r$   r$   r%   r&   J   r'   c              	   C   sH   t t t }| }W 5 Q R X t|jdks4tt j|||d d S )Nr   check_index_type)tmassert_produces_warningFutureWarningr   lenindexAssertionErrorassert_series_equal)selfconstructorr1   expectedresultr$   r$   r%   test_empty_constructor9   s
    z-TestSeriesConstructors.test_empty_constructorc              
   C   sD   d}t dtg}|D ],}tjt|d tg d|d W 5 Q R X qd S )Nznot understoodr   matchtime)namedtype)r   listpytestraises	TypeErrorr   )r9   msgZinvalid_listrB   r$   r$   r%   test_invalid_dtypeV   s
    
z)TestSeriesConstructors.test_invalid_dtypec              	   C   sN   t ddg}t jddg|d}tjtdd t|dd	gd
 W 5 Q R X d S )N)ai8)bZf4)   g?)   irB   zUse DataFrame insteadr>   ABr6   )nprB   arrayrD   rE   
ValueErrorr   )r9   Zc_dtypeZcdt_arrr$   r$   r%   test_invalid_compound_dtype^   s    z2TestSeriesConstructors.test_invalid_compound_dtypec                 C   sF   t d}t|trttt dgdks,ttt dgdksBtd S )Ng      ?      ?rL   )r   
isinstancefloatr7   int)r9   Zscalarr$   r$   r%   test_scalar_conversionf   s    z-TestSeriesConstructors.test_scalar_conversionc                 C   sH   |\}}t |tdd}t |gd |d}|j|ks8tt|| d S )N   rQ   rN   )r   rangerB   r7   r2   r8   )r9   ea_scalar_and_dtype	ea_scalarea_dtypeserr;   r$   r$   r%   test_scalar_extension_dtypep   s
    z2TestSeriesConstructors.test_scalar_extension_dtypec           	   	   C   sh  t t t }W 5 Q R X |jjs(tt|}|jjs<tt |j|jsPtt|jt|jkshttdt	j
gddgd}|jt	jkst|d t	j
kst|jjrtt t t jjrtW 5 Q R X tjtdd" tt	jddt	dd W 5 Q R X d|_t|j}d}||ks(ttdd	gdd
gg}d}tjt|d t| W 5 Q R X d S )NZhellor   rL   rQ   zData must be 1-dimensionalr>   r[   r         z8initializing a Series from a MultiIndex is not supported)r2   r3   r4   r   r6   Z_is_all_datesr7   ZequalContentsidrR   NaNrB   object_rD   rE   rT   randomrandnarangerA   r   Zfrom_arraysNotImplementedError)	r9   datetime_seriesZempty_seriesZderivedmixedrsZxpmrG   r$   r$   r%   test_constructor{   s.    &
z'TestSeriesConstructors.test_constructorc              	   C   sT   t ddgddgddggdddgd}tjtd	d
 tdddg|d W 5 Q R X d S )NrL   rb   r[   rc         	   rQ   z Index data must be 1-dimensionalr>   )r   rD   rE   rT   r   )r9   dfr$   r$   r%   'test_constructor_index_ndim_gt_1_raises   s    $z>TestSeriesConstructors.test_constructor_index_ndim_gt_1_raisesinput_classc              	   C   s6  t t t }t| }W 5 Q R X 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k	r2t t& ttdd}t| tdd}W 5 Q R X 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 )NFr0   float64rN   category
   rQ   r6   rB    r[   rB   r6   )
r2   r3   r4   r   r8   rC   r\   rR   nanstr)r9   ru   emptyempty2r$   r$   r%   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 )Nrv   rx   r{   rQ   Fr0   r   r\   r2   r8   )r9   r   r~   r   r$   r$   r%   test_constructor_nan   s    z+TestSeriesConstructors.test_constructor_nanrB   f8rJ   M8[ns]m8[ns]rw   objectzdatetime64[ns, UTC]r6   Nc                 C   s.   t ||d}|j|kstt|dks*td S )Nr{   r   )r   rB   r7   r5   )r9   rB   r6   r<   r$   r$   r%   test_constructor_dtype_only   s    z2TestSeriesConstructors.test_constructor_dtype_onlyc              	   C   sB   t t tdddgd}W 5 Q R X |j dddgks>td S )NrK   rI   crQ   )r2   r3   r4   r   r6   tolistr7   r9   r<   r$   r$   r%   $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"td S NrL   ry   r   )r   r}   rR   isnanilocr7   r   r$   r$   r%   $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&td S r   )r   r}   r   r7   )r9   r   r<   r$   r$   r%   +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 ksBtt dtjg|d}t|jd shtd S )NxrN   FTrL   )	r   r   r2   r8   r   r7   rR   r|   r   )r9   string_dtyper`   r<   r;   r$   r$   r%   $test_constructor_dtype_str_na_values   s    z;TestSeriesConstructors.test_constructor_dtype_str_na_valuesc                 C   sH   ddddg}t |}tddddg|d	}t||d	}t||  d S )
NdrK   rI   r   rc      r[   rQ   )sortedr   r2   r8   Z
sort_index)r9   Zindex1index2s1s2r$   r$   r%   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d ZdS )z>TestSeriesConstructors.test_constructor_iterable.<locals>.Iterc                 s   s   t dE d H  d S )Nrx   )r\   r9   r$   r$   r%   __iter__  s    zGTestSeriesConstructors.test_constructor_iterable.<locals>.Iter.__iter__N)__name__
__module____qualname__r   r$   r$   r$   r%   Iter  s   r   rx   int64rN   r   rC   r\   r2   r8   )r9   r   r;   r<   r$   r$   r%   test_constructor_iterable   s    z0TestSeriesConstructors.test_constructor_iterablec                 C   s4   t ttddd}t tddd}t|| d S )Nrx   r   rN   r   r9   r;   r<   r$   r$   r%   test_constructor_sequence
  s    z0TestSeriesConstructors.test_constructor_sequencec                 C   s"   t dg}t d}t|| d S )Nabcr   r2   r8   r   r$   r$   r%   test_constructor_single_str  s    
z2TestSeriesConstructors.test_constructor_single_strc                 C   sZ   t dddgdd}dddgdtjdddgddfD ]"}t |dddgd}t|| q2d S )	NrL   rb   r[   r   rN   rL   rb   r[   r   rQ   )r   rR   rS   r2   r8   )r9   r;   objr<   r$   r$   r%   test_constructor_list_like  s    $z1TestSeriesConstructors.test_constructor_list_likec                 C   sZ   t dddgdddgd}|dk}t dddg|d}t dddgdd	dgd}t|| d S )
NrL   rb   r[   rc   rp   rq   rQ   FTr   )r9   r   r6   r<   r;   r$   r$   r%   test_constructor_boolean_index   s
    z5TestSeriesConstructors.test_constructor_boolean_indexboolint32r   rv   c                 C   s(   t tdddg|d}|j|ks$td S )Nr   rb   rc   rN   )r   r   rB   r7   )r9   rB   sr$   r$   r%   test_constructor_index_dtype)  s    z3TestSeriesConstructors.test_constructor_index_dtype
input_valsrL   rb   12z1/1/2011Hperiodsfreq
US/Eastern)r   r   tzr   rp   )leftrightc                 C   s*   t ||d}t ||}t|| d S NrN   r   astyper2   r8   )r9   r   r   r<   r;   r$   r$   r%   test_constructor_list_str0  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 sFtd S )NrV          @rN   z1.0z2.0rb   )r   rR   r|   r   r2   r8   r   r7   )r9   r   r<   r;   r$   r$   r%   test_constructor_list_str_naB  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   s   | ]
}|V  qd S r"   r$   r)   ir$   r$   r%   r+   I  s     zDTestSeriesConstructors.test_constructor_generator.<locals>.<genexpr>rx   c                 s   s   | ]
}|V  qd S r"   r$   r   r$   r$   r%   r+   P  s        rQ   )r\   r   r2   r8   r6   )r9   genr<   expr$   r$   r%   test_constructor_generatorH  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   | S r"   r$   r   r$   r$   r%   r&   W  r'   z=TestSeriesConstructors.test_constructor_map.<locals>.<lambda>rx   c                 S   s   | S r"   r$   r   r$   r$   r%   r&   ^  r'   r   rQ   )mapr\   r   r2   r8   r6   )r9   rn   r<   r   r$   r$   r%   test_constructor_mapU  s    z+TestSeriesConstructors.test_constructor_mapc                 C   sn   t ddddddgdddgdd}t|}t|j| tt ddd	gd
d}tddd	gd
d}t|| d S )Nr   rL   rb   rI   rK   r   T)Zfastpathr[   r   rN   )r   r   r2   Zassert_categorical_equalvaluesr8   )r9   catresr<   r;   r$   r$   r%   test_constructor_categoricalc  s     z3TestSeriesConstructors.test_constructor_categoricalc                 C   s4   t tdddgdd}t|s"tt|js0td S NrL   rb   r[   rw   rN   )r   r   r
   r7   rB   )r9   r   r$   r$   r%   *test_construct_from_categorical_with_dtypem  s    zATestSeriesConstructors.test_construct_from_categorical_with_dtypec                 C   s0   t dddgdd}t|stt|js,td S r   )r   r
   r7   rB   )r9   r`   r$   r$   r%   ,test_construct_intlist_values_category_dtypes  s    zCTestSeriesConstructors.test_construct_intlist_values_category_dtypec              	   C   sz  t ddddddddg}t|dd}|jdks2tt|t|ksFtt|j t| td|i}|d }t	|| |j
d d df }t	|| t|t|kstt|j t| td|i}|d }t	|| t|t|kstt|j t| t||dd	}|d }|d
 }t	|| tj	||dd |jd
ksNtt|t|ksdtt|j t| d S )NrI   rK   r   rO   rA   rw   r   rL   )rO   rP   CrP   F)Zcheck_names)r   r   rB   r7   r5   r}   r   r   r2   r8   r   rA   )r9   factorr   rs   r<   Zresult1Zresult2r$   r$   r%   *test_constructor_categorical_with_coercionx  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sTt|jd }||ksjt|jjd }||kstd S )	NrL   zJohn P. Doerb   z	Jane DoveZ	person_idperson_name)columnsr   )r   r   r   r   r7   loc)r9   r   r;   r<   r$   r$   r%   +test_constructor_categorical_with_coercion2  s    
zBTestSeriesConstructors.test_constructor_categorical_with_coercion2c                 C   s<   t dddg}t |dd}t dddgdd}t|| d S )NrI   rK   r   rw   rN   r   )r9   seriesr<   r;   r$   r$   r%   &test_constructor_series_to_categorical  s    z=TestSeriesConstructors.test_constructor_series_to_categoricalc                 C   s   t ddgtdddgddd}t|jdks0tt|jjt	dddg |jj
sVtt ddgtddgd}t|js|tt|jjt	ddg |jj
dkst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 )NrI   rK   r   T)orderedrN   Fr   rL   ry   )r   r   r
   rB   r7   r2   assert_index_equalr   
categoriesr   r   r8   r9   r<   r;   r$   r$   r%   "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 )NZdabcT)r   r   ZabcabcrN   rw   )r   rC   r   r   r2   r8   )r9   Zcdtr;   r   r<   r$   r$   r%   #test_constructor_categorical_string  s    z:TestSeriesConstructors.test_constructor_categorical_stringc                 C   sx  t ddddg}t|dd}|j|k	s*tdddg|j_tjddddgtjd	}tjddddgtjd	}t	
| | t	
| | d|d
< tjddddgtjd	}t	
| | t	
| | t ddddg}t|}|j|kstdddg|j_tjddddgtjd	}t	
| | t	
| | d|d
< tjddddgtjd	}t	
| | t	
| | d S )NrI   rK   r   T)copyrL   rb   r[   rN   r   )r   r   r   r7   r   rR   rS   r   rf   r2   assert_numpy_array_equalZ	__array__r   )r9   r   r   Zexp_sZexp_catZexp_s2r$   r$   r%   !test_categorical_sideeffects_free  s.    z8TestSeriesConstructors.test_categorical_sideeffects_freec                 C   sF   t dddgtddgd}t tddtjgddgd}t|| d S )NrI   rK   r   rN   )r   )r   r   r   rR   r|   r2   r8   )r9   r   r   r$   r$   r%   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< ddd	g}t||d
}tdtjdg|d
}t|| d|d< t||d
}tdddg|d
}t|| t jdtd}t|}ttjtjtjgtd}t|| d|d< d|d< ddd	g}t||d
}tdtjdg|td}t|| d|d< t||d
}tdddg|td}t|| t jdt	d}t|}ttjtjtjgt
d}t|| d|d< d|d< ddd	g}t||d
}tdtjdg|t
d}t|| d|d< t||d
}tdddg|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< ddd	g}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[   rN           r   r   rb   rI   rK   r   rQ   rV   rL   ry   TFr     r[   )ma
masked_allrX   r   rR   r|   r2   r8   rY   r   r   r   r   )r9   r/   r<   r;   r6   r$   r$   r%   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   rN   )	r   r   rX   Zharden_maskr   rR   r|   r2   r8   r9   r/   r<   r;   r$   r$   r%   %test_constructor_maskedarray_hardenedP  s    z<TestSeriesConstructors.test_constructor_maskedarray_hardenedc                 C   s:   t dddd}dd |D }t||d}|j|ks6td S )NZ20090415Z20090519rP   r   c                 S   s   i | ]
}|d qS rL   r$   )r)   kr$   r$   r%   
<dictcomp>Y  s      zNTestSeriesConstructors.test_series_ctor_plus_datetimeindex.<locals>.<dictcomp>rQ   )r   r   r6   r7   )r9   rngr/   r<   r$   r$   r%   #test_series_ctor_plus_datetimeindexW  s    z:TestSeriesConstructors.test_series_ctor_plus_datetimeindexc                 C   s,   t dddg}tj|jttddd d S )Nr   rL   rb   r[   T)exact)r   r2   r   r6   r   r\   r9   r   r$   r$   r%   test_constructor_default_index^  s    z5TestSeriesConstructors.test_constructor_default_indexinputr[   r   rI   rK   c                 c   s   | ]
}|V  qd S r"   r$   r   r$   r$   r%   r+   i  s     z TestSeriesConstructors.<genexpr>c                 C   s   | S r"   r$   r   r$   r$   r%   r&   j  r'   c              	   C   s4   d}t jt|d t|tdd W 5 Q R X d S )Nz;Length of values \(3\) does not match length of index \(4\)r>   rc   rQ   )rD   rE   rT   r   rR   ri   )r9   r   rG   r$   r$   r%   test_constructor_index_mismatchb  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   rc   r   ry   )r   rR   rS   ri   r2   r8   r   r$   r$   r%   test_constructor_numpy_scalaru  s    z4TestSeriesConstructors.test_constructor_numpy_scalarc              	   C   s6   d}t jt|d tdgdddgd W 5 Q R X d S )Nz;Length of values \(1\) does not match length of index \(3\)r>   foorI   rK   r   rQ   rD   rE   rT   r   r9   rG   r$   r$   r%   test_constructor_broadcast_list}  s    z6TestSeriesConstructors.test_constructor_broadcast_listc                 C   s2   t  }||g}t|ddgd}t|ts.td S )Nr   rL   rQ   )r2   ZmakeTimeDataFramer   rW   r7   )r9   rs   objsr   r$   r$   r%   test_constructor_corner  s    z.TestSeriesConstructors.test_constructor_cornerc              	   C   s~   t tdddgdd}|jtdks,td}tjt|d" t tddtjgddd}W 5 Q R X |jtd	ksztd S )
NrV   g       @rJ   rN   z6float-dtype values containing NaN and an integer dtyper>   Tr   rB   r   )	r   rR   rS   rB   r7   r2   r3   r4   r|   )r9   r   rG   r`   r$   r$   r%   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< ||rNt|d dks^t|d dkstqd S )NrV   Tr  r   r   )rR   rS   r   rX   r2   r8   equalsr7   )r9   r/   r   yr$   r$   r%   test_constructor_copy  s    z,TestSeriesConstructors.test_constructor_copyZ20170101r   r   r   z1 dayZ2012Q1Qr   c                 C   s
   t | jS r"   typer   r   r$   r$   r%   r&     r'   )Zidsc                 C   s"   t |}|jjd j|k	std S )Nr   )r   _mgrblocksr   r7   )r9   r6   r   r$   r$   r%   test_constructor_limit_copies  s    z4TestSeriesConstructors.test_constructor_limit_copiesc              	   C   s   t t td tdd}W 5 Q R X |jtjks6ttd tdt	d}|jtj
ksXtt t( ttd gd}ttd gd}W 5 Q R X t || d S )Nrp   rQ   ry   )r2   r3   r4   r   r\   rB   rR   rv   r7   r   rf   rS   r   r8   r9   r   r;   r$   r$   r%   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&ttt tjtjg| tt ttjtjg| t t	t	g}|jdksvt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 )NrN   datetime64[ns])
r   rR   r|   rv   rB   r7   r2   r8   rS   r   )r9   r   r$   r$   r%   test_constructor_pass_nan_nat  s    z4TestSeriesConstructors.test_constructor_pass_nan_natc              	   C   s4   d}t jt|d tdddgtd W 5 Q R X d S )Nz!could not convert string to floatr>   rI   rK   r   rN   )rD   rE   rT   r   rX   r  r$   r$   r%   test_constructor_cast  s    z,TestSeriesConstructors.test_constructor_castc              	   C   s   d}t jt|d tdddgdd}W 5 Q R X tddd	gdd}t || t jt|d tdddgd
d}W 5 Q R X tddd	gd
d}t || d S )Nz*Values are too large to be losslessly castr>   rL      i2 Zint8rN   i2   uint8)r2   r3   r4   r   r8   )r9   rG   r`   r;   r$   r$   r%   0test_constructor_signed_int_overflow_deprecation  s    zGTestSeriesConstructors.test_constructor_signed_int_overflow_deprecationc              	   C   s0   d}t jt|d tdg|d W 5 Q R X d S )Nz5Trying to coerce negative values to unsigned integersr>   rN   )rD   rE   OverflowErrorr   )r9   Zany_unsigned_int_numpy_dtyperG   r$   r$   r%   (test_constructor_unsigned_dtype_overflow  s    z?TestSeriesConstructors.test_constructor_unsigned_dtype_overflowc              	   C   s4   d}t jt|d tdddg|d W 5 Q R X d S )Nz)Trying to coerce float values to integersr>   rL   rb         @rN   r  r9   Zany_int_numpy_dtyperG   r$   r$   r%   "test_constructor_coerce_float_fail  s    z9TestSeriesConstructors.test_constructor_coerce_float_failc                 C   s6   t dddg|d}t dddg|}t|| d S )NrL   rb   r  rN   r   )r9   Zfloat_numpy_dtyper   r;   r$   r$   r%   #test_constructor_coerce_float_valid  s    z:TestSeriesConstructors.test_constructor_coerce_float_validc              	   C   s6   d}t jt|d tddtjg|d W 5 Q R X d S )Nz#cannot convert float NaN to integerr>   rL   rb   rN   )rD   rE   rT   r   rR   r|   r   r$   r$   r%   3test_constructor_invalid_coerce_ints_with_float_nan   s    zJTestSeriesConstructors.test_constructor_invalid_coerce_ints_with_float_nanc                 C   s8   t dddg}t |tjd}d|d< |d dks4td S )NrL   rb   r[   rN   rp   )r   rR   r   r7   )r9   r   r   r$   r$   r%   test_constructor_dtype_no_cast  s    z5TestSeriesConstructors.test_constructor_dtype_no_castc                 C   sN   t tddgtd}|jd tdks*t|jd dks<t|jtksJtd S )N20130101ZNOVrN   r   rL   )r   r   r   r   r7   rB   r   r$   r$   r%   "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sRt|jd }|jtksjtd S )	Nz216 3T19z	2T15 4H19z416 4T20z2016-01-22 2019-09-07)wing1wing2matrQ   Z3T19Z216)splitpdto_datetimer   r   rB   r   r7   )r9   Zbellyr'  r(  r)  rs   r<   r$   r$   r%   #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 )Nrr   rx   r   rN   )r   r   valuer2   Zassert_equal)r9   Zframe_or_seriesr  r<   r;   r$   r$   r%   (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s0tq0d S Nr   )rR   rS   r   nowr   rB   r7   )r9   arrr<   r$   r$   r%   %test_constructor_datetimes_with_nulls/  s
    z<TestSeriesConstructors.test_constructor_datetimes_with_nullsc                 C   s   t tdtdd}t| s"tt ttdd}t| rBtt tjdtdd}t| sftt tdddddtgdd	}t|d st|j	dkstt tdddddtjgdd	}t|d st|j	dkstd S )
Nr   rp   r{   rQ   r   rL   rb   r   rN   )
r   r   r\   r   allr7   rR   r|   r   rB   r   r$   r$   r%   !test_constructor_dtype_datetime648  s    z8TestSeriesConstructors.test_constructor_dtype_datetime64c              	   C   s  t tdddt tdddt tdddg}t|}|jdksJtt j|jd< |jdksdtttdddtdddtdddg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
|| t|dd}|d d}tjt|d |d W 5 Q R X t|t j	d}t|t j	}t
|| d S )Ni  rL   rb   r[   r   r   r  rN   i@B zM8[ms]r   zCcannot astype a datetimelike from \[datetime64\[ns\]\] to \[int32\]r>   r   )rR   
datetime64r   r   rB   r7   r|   r   viewr   r2   r8   r   r   rD   rE   rF   )r9   datesr   r;   r<   dtsrG   r$   r$   r%   $test_constructor_dtype_datetime64_10M  s<      
z;TestSeriesConstructors.test_constructor_dtype_datetime64_10c                 C   s`   t tdddg}|d tdddddks.tt tdddg}|d tdddddks\td S )Nrb   rL   r   i  )r   r   r7   r   r$   r$   r%   #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,t|d dks<td S )Nr%  rL   rI   rK   rQ   )r   r   r7   r   r$   r$   r%   #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 ]4}|tjd| d	}t||}t|| q0t||td
}dD ]8}|tjd| d	}t||td
}t|| qxtj	dd |
 D td}t||}t|j| |jtkstd S )Nz01-Jan-2015z01-Dec-2015Mr   r  rQ   )r   DmsusnszM8[]ry   c                 S   s   g | ]}|  qS r$   )date)r)   r   r$   r$   r%   
<listcomp>  s     zNTestSeriesConstructors.test_constructor_dtype_datetime64_7.<locals>.<listcomp>rN   )r   r7  rR   ndarrayr   r   r2   r8   r   rS   to_pydatetimer   r   rB   r7   )	r9   r8  Zvalues2r;   rB   Zvalues1r<   Zdates2Zseries1r$   r$   r%   #test_constructor_dtype_datetime64_7  s     

z:TestSeriesConstructors.test_constructor_dtype_datetime64_7c              	   C   s   d}t jt|d td tdg}W 5 Q R X |jdks:tt jt|d ttjtdg}W 5 Q R X |jdksrtt jt|d ttd dg}W 5 Q R X |jdkstt jt|d tttjdg}W 5 Q R X |jdkstd S )N containing strings is deprecatedr>   z2013-08-05 15:30:00.000001r  )	r2   r3   r4   r   r   rB   r7   rR   r|   )r9   rG   r`   r$   r$   r%   #test_constructor_dtype_datetime64_6  s    z:TestSeriesConstructors.test_constructor_dtype_datetime64_6c                 C   s|   t ddd}t|jd jd ks$tt dddd}tt|jd jdksNtt dddd}tt|jd jdksxtd S )Nr%  r[   r  r   UTCr  r   )r   r   r   r   r7   r}   )r9   drr$   r$   r%   #test_constructor_dtype_datetime64_5  s    z:TestSeriesConstructors.test_constructor_dtype_datetime64_5c                 C   s@   t ddtg}|jdkst|d tks,tdt|ks<td S )Nl   *}aiZlr   rb   r   )r   r   rB   r7   r}   r   r$   r$   r%   #test_constructor_dtype_datetime64_4  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,t|d tks<tdt|ksLtd S )N  rL   rb   r   r   )r   r   r   rB   r7   r}   r   r$   r$   r%   #test_constructor_dtype_datetime64_3  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.t|d tjks@tdt|ksPtd S )NrN  rL   rb   r   re   )r   r   rR   r|   rB   r7   r}   r   r$   r$   r%   #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&t|jdks4tt|jsBtdt|ksRt|j}t|t	j
sht|jdksvtt|}|dj|jjd}t|| |jd	 }|td
ddkst|d	 }|td
ddkst|tdddg|jd }t||d	d  |jd	d }t|t|d	d  t|jd	d |jdd  g}t|| dt|kslt| }dt|kstdt|ksttt dddd}dt|kstt|dd}t|| d S )Nr%  r[   r   r  datetime64[ns, US/Eastern]r  rJ  r   r   z2013-01-01 00:00:00-0500TFrQ   rb   rL   r     Zinferr   )r   r   rB   rA   r7   r   r}   r   rW   rR   rE  r   tz_localize
tz_convertdtr   r2   r   r   r   r6   r8   r+  concatshift)r9   rK  r   r<   r   tr$   r$   r%   !test_constructor_with_datetime_tz  s<    
"z8TestSeriesConstructors.test_constructor_with_datetime_tzc                 C   sD   t tdddtdddg}|jdks*ttj|dddks@td S )	N2013-01-01 13:00:00-0800
US/PacificrR  2013-01-02 14:00:00-0800zdatetime64[ns, US/Pacific]TZskipnar6  r   r   rB   r7   r   Zinfer_dtyper   r$   r$   r%   "test_constructor_with_datetime_tz4  s    

z9TestSeriesConstructors.test_constructor_with_datetime_tz4c                 C   sD   t tdddtdddg}|jdks*ttj|ddd	ks@td S )
Nr[  r\  rR  r]  r   r   Tr^  r   r_  r   r$   r$   r%   "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   rL   rQ  ry   r   r   rR  )r   r   r   r2   r8   r  r$   r$   r%   "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>t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   | ]} | | kV  qd S r"   r$   r   r`   valsr$   r%   r+   2  s     zVTestSeriesConstructors.test_constructor_no_partial_datetime_casting.<locals>.<genexpr>)r   r   r4  r\   r5   r7   r   r$   rc  r%   ,test_constructor_no_partial_datetime_casting(  s    zCTestSeriesConstructors.test_constructor_no_partial_datetime_casting	arr_dtypeZM8Zm8unitrA  r@  r?  r   hrn   r>  c                 C   sT   | d| d}t jdddg|d}t|}||}t||}t|| d S )N[rB  rL   rb   r[   rN   )rR   rS   r   r   r2   r8   )r9   rf  rB   rg  r2  r   r<   r;   r$   r$   r%   &test_construction_to_datetimelike_unit4  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]rN   ZCET)r   r   rV  rT  r2   r8   )r9   rk  r<   r;   r$   r$   r%   7test_constructor_with_naive_string_and_datetimetz_dtypeB  s    zNTestSeriesConstructors.test_constructor_with_naive_string_and_datetimetz_dtypec                 C   sJ   t dd}t jt ddgdd}t|}tt|g}t|| d S )NrL   r?  z>M8[ms]rN   )rR   r6  rS   r   r   r2   r8   )r9   r?  r2  r<   r;   r$   r$   r%   %test_constructor_datetime64_bigendianI  s
    z<TestSeriesConstructors.test_constructor_datetime64_bigendianinterval_constructorc                 C   sD   |j tddd}t|}|jdks*ttt|j	t| d S )Nr[   r   closedzinterval[int64, right])
Zfrom_breaksrR   ri   r   rB   r7   r2   r   r   r   )r9   rn  Z	intervalsr<   r$   r$   r%   test_construction_intervalR  s    z1TestSeriesConstructors.test_construction_intervaldata_constructorrC   zndarray[object]c                 C   sL   t ddt ddd g}t||}tt|}|jdks<tt|| d S )Nr   rL   rb   zinterval[float64, right])r   r   r   rB   r7   r2   r8   r9   rr  r/   r<   r;   r$   r$   r%   test_constructor_infer_intervalZ  s
    z6TestSeriesConstructors.test_constructor_infer_intervalc                 C   sJ   t ddddt ddddg}t||}|jtks6t| |ksFtd S )Nr   rL   Zbothro  rb   Zneither)r   r   rB   r   r7   r   )r9   rr  r/   r<   r$   r$   r%   &test_constructor_interval_mixed_closede  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|| d}tjt|d t |j	|jd}W 5 Q R X t|| td ( t |j	j
d}|j|jj}W 5 Q R X t|| td  t |j	d	|jd}W 5 Q R X t|| d S )
Nr%  r[   r   r  rN   rJ  z%will interpret the data as wall-timesr>   r   )r   r   rB   r2   r8   rV  rU  r3   r4   r   rT  r   r7  )r9   r`   r<   rG   middler$   r$   r%   test_construction_consistencyo  s      z4TestSeriesConstructors.test_construction_consistencyc                 C   sL   t ddt ddd g}t||}tt|}t|| |jdksHtd S )N2000r>  2001	Period[D])r   r   r   r2   r8   rB   r7   rs  r$   r$   r%   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,t||d< t|d sDtd S )Nr   rS    z	period[D]rN   r[   rb   )r   r+  Z_libsr   r   r7   r9   r   valr$   r$   r%   ;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*t| |ks:td S )Nrx  r>  ry  rO   )r   r   rB   r   r7   r   )r9   r/   r<   r$   r$   r%   .test_constructor_period_incompatible_frequency  s    zETestSeriesConstructors.test_constructor_period_incompatible_frequencyc                 C   sB   t dddd}t|}|jdks$tt|t}t|| d S )Nr%  rp   r>  r   rz  )r   r   rB   r7   r   r   r2   r8   )r9   pir   r;   r$   r$   r%   test_constructor_periodindex  s
    z3TestSeriesConstructors.test_constructor_periodindexc                 C   s   dddd}t |}t |t| d}t|| t |dddd	gd}t d
dtjdgdddd	g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   rV   r   )rI   rK   r   rQ   rK   r   r   rI   rL   rb   r   r   rN   )
r   r   keysr2   r8   rR   r|   ZmakePeriodIndexrv   r   )r9   r   r<   r;   Zpidxr$   r$   r%   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 )NrI   rb   r[   rc   r   ry   rQ   r   r9   r   r<   r;   r$   r$   r%   /test_constructor_dict_list_value_explicit_dtype  s    zFTestSeriesConstructors.test_constructor_dict_list_value_explicit_dtypec                 C   s:   dddd}t |}t dddgtdd}t|| d S )NrL   r   rb   )rK   rI   r   ZbacrQ   )r   rC   r2   r8   r  r$   r$   r%   test_constructor_dict_order  s    z2TestSeriesConstructors.test_constructor_dict_orderc                 C   sL   |\}}d|i}t |dgd}t |dg|d}|j|ks<tt|| d S )NrI   rQ   ry   )r   rB   r7   r2   r8   )r9   r]   r^   r_   r   r<   r;   r$   r$   r%   test_constructor_dict_extension  s    z6TestSeriesConstructors.test_constructor_dict_extensionr.  c                 C   s   dd|dt ddddi}t| }tddddgd|tjdgd}t|| d	dd
tjfdd|fdi}t| }tdddgtd	d
tjfd|fgd}t|| d S )NrL   rI   rK   r|   r   rc   r   rQ   rL   rL   rb   r[   )rX   r   sort_valuesrR   r|   r2   r8   r   )r9   r.  r   r<   r;   r$   r$   r%   test_constructor_dict_nan_key  s     z4TestSeriesConstructors.test_constructor_dict_nan_keyc           	         s   ddddg ddddg fd	d
}|t j}|dd }|t}tdd  D }t|}t|}t|}t|| t|| t|| d S )Nz
1984-02-19z
1988-11-06z
1989-12-03z
1990-03-15g{\IAi gtyZQAr  c                    s   t t fddD S )Nc                 3   s   | ]} |V  qd S r"   r$   r)   r   r:   r$   r%   r+     s     zeTestSeriesConstructors.test_constructor_dict_datetime64_index.<locals>.create_data.<locals>.<genexpr>)dictzipr  Zdates_as_strr   r  r%   create_data  s    zRTestSeriesConstructors.test_constructor_dict_datetime64_index.<locals>.create_datac                 S   s   t | dS )Nz%Y-%m-%d)r   strptimer   r$   r$   r%   r&     r'   zOTestSeriesConstructors.test_constructor_dict_datetime64_index.<locals>.<lambda>c                 s   s   | ]}t |V  qd S r"   )r   r  r$   r$   r%   r+     s     zPTestSeriesConstructors.test_constructor_dict_datetime64_index.<locals>.<genexpr>)rR   r6  r   r   r2   r8   )	r9   r  Zdata_datetime64Zdata_datetimeZdata_Timestampr;   Zresult_datetime64Zresult_datetimeZresult_Timestampr$   r  r%   &test_constructor_dict_datetime64_index  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)rL   rL   Ng      rL   r   r  )ZlevelscodesrQ   )r   r   rR   r|   r2   r8   r   r$   r$   r%   #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[   threerQ   r   )r9   Znon_dict_mapping_subclassZndmr<   r;   r$   r$   r%   test_constructor_mapping  s    z/TestSeriesConstructors.test_constructor_mappingc                 C   s&   dddg}t |}t||ks"td S )Nr  rb   rb   rb   r[   )r   rC   r7   r9   r/   r   r$   r$   r%   test_constructor_list_of_tuples  s    
z6TestSeriesConstructors.test_constructor_list_of_tuplesc                 C   s    d}t |}t||kstd S )N)r  r  r  )r   tupler7   r  r$   r$   r%    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[   rq   )rL   rb   Nrp   r  r  rQ   )r   r  r   from_tuplesr2   r8   r   r$   r$   r%   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sLt	ddddd}t |}|jtjksrt	d	dd
}t |t
d}|jtjkst	d S )Nr   rL   rb   r[   )rI   rK   r   r   r   r   30rI   rK   rN   )r   r2   Zassert_is_sortedr6   r   r1  rB   rR   rf   r7   rX   rv   )r9   r/   r   r$   r$   r%   test_fromDict&  s    
z$TestSeriesConstructors.test_fromDictc                 C   s   t tj|jtjd}|jtjks$tt|t|ks8tt d|jd}|jtj	ksVtt|t|ksjtt
 }t ||jd}|jdkstt|t|kstt d|jdd}t d|jdd}|jdkstt|t|kstt|| d S )Nry   r   rQ   r   r   rw   )r   rR   re   r6   rv   rB   Zfloat_r7   r5   rf   r   r1  r   r2   r8   )r9   rk   Znansstringsr   r8  Zcategoricalr;   r$   r$   r%   test_fromValue9  s    z%TestSeriesConstructors.test_fromValuec              	   C   s  t dd tdD }|jdks$tt tddg}|jdksBtt tddtddtddg}|jdksrtt tddtgd	d
}|jdkstt tddtjgd	d
}|jdkstt tdtgd	d
}|jdkstt tdtg}|jdkstt tdt	g}|jdks$tt tdtjg}|jdksHtt ttdg}|jdksjtt tddg}|jdkst|
d d}tjt|d |
d W 5 Q R X dddg}tjt|d t tdddgd	d
 W 5 Q R X t dd tdD dg }|jdks(td}tjt|d t d tdg}W 5 Q R X |jdksdttjt|d t tjtdg}W 5 Q R X |jdksttjt|d t td dg}W 5 Q R X |jdksttjt|d t ttjdg}W 5 Q R X |jdkstd S )Nc                 S   s   g | ]}t |d qS daysr   r   r$   r$   r%   rD  S  s     zMTestSeriesConstructors.test_constructor_dtype_timedelta64.<locals>.<listcomp>r[   timedelta64[ns]rL   r  rb   r   r   rN   i r   r   zDcannot astype a datetimelike from \[timedelta64\[ns\]\] to \[int32\]r>   r   |z+Could not convert object to NumPy timedeltaz*Could not convert 'foo' to NumPy timedeltar   c                 S   s   g | ]}t |d qS r  r  r   r$   r$   r%   rD    s     rH  z1 Day)r   r\   rB   r7   r   rR   timedelta64r   r|   r   r   rD   rE   rF   joinrT   r2   r3   r4   )r9   tdrG   r`   r$   r$   r%   "test_constructor_dtype_timedelta64P  s`    "
 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 )Nr%  r   rR  r   rN   )r   r   r2   r8   r  r$   r$   r%   test_constructor_mixed_tz  s    z0TestSeriesConstructors.test_constructor_mixed_tzc                 C   sD   t dddtgdd}|d }t|s(t||d< t|d s@td S )Nr   rS  r~  r   rN   r[   rb   )r   r   r   r7   r  r$   r$   r%   test_NaT_scalar  s
    z&TestSeriesConstructors.test_NaT_scalarc                 C   s,   t tjgd}t tg}t|| d S r0  )r   rR   r|   r   r   r2   r8   r   r$   r$   r%   test_NaT_cast  s    
z$TestSeriesConstructors.test_NaT_castc                 C   s^   dddt dddddfD ]@}dd	d
gtd
dddfD ]}t||d}|j|ks8tq8qd S )Ni	  g     H@rA   r      r   u   אrL   rb   r[   r   r  r   )r   rR   onesr   rA   r7   )r9   nr/   r   r$   r$   r%   test_constructor_name_hashable  s     z5TestSeriesConstructors.test_constructor_name_hashablec                 C   sf   d}dgt dddifD ]F}dgt dddifD ]*}tjt|d t||d W 5 Q R X q4qd S )Nz$Series\.name must be a hashable type	name_listrb   rL   r>   r   )rR   r  rD   rE   rF   r   )r9   rG   r  r/   r$   r$   r%    test_constructor_name_unhashable  s
    z7TestSeriesConstructors.test_constructor_name_unhashablec                 C   s&   t ttddd}|jdks"td S )N1/1/2000rx   r  r   )r   rC   r   rB   r7   r9   r   r$   r$   r%   test_auto_conversion  s    z+TestSeriesConstructors.test_auto_conversionc                 C   s   t jdddgdd}t|}ttdddd}t|| t jd	d
dgdd}t|}ttdddd}t|| t jdddgdd}t|}ttdddd}t|| d S )NrL   rb   r[   ztimedelta64[s]rN   z00:00:01r   r   
2013-01-01z
2013-01-02z
2013-01-03zdatetime64[D]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)rR   rS   r   r   r2   r8   r   )r9   r2  r   r;   r`   r$   r$   r%   test_convert_non_ns  s$     z*TestSeriesConstructors.test_convert_non_nsr  rx   z2000-Q1c                 C   s
   t | jS r"   r  r   r$   r$   r%   r&     r'   c              	   C   sl   dt |jd d}tjt|d t|td W 5 Q R X t|tj	d}t|
tj	}t|| d S )NzCannot cast r   z.*? to r>   rN   )r  r   rstriprD   rE   rF   r   rX   rR   r   r   r2   r8   )r9   r6   rG   r<   r;   r$   r$   r%   'test_constructor_cant_cast_datetimelike  s    z>TestSeriesConstructors.test_constructor_cant_cast_datetimelikec                 C   s
   t | jS r"   r  r   r$   r$   r%   r&     r'   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   r2   r8   r   )r9   r6   r   r   r$   r$   r%   test_constructor_cast_object  s    
z3TestSeriesConstructors.test_constructor_cast_objectc              	   C   sX   d}t |jdkr.tjjdd}|j| tjt	|d t
g |d W 5 Q R X d S )Nz!dtype has no unit. Please pass in)r  r6  zGH#33890 Is assigned ns unitr|  r>   rN   )rR   rB   rA   rD   markxfailnodeZ
add_markerrE   rT   r   )r9   rB   requestrG   r  r$   r$   r%   /test_constructor_generic_timestamp_no_frequency  s    zFTestSeriesConstructors.test_constructor_generic_timestamp_no_frequencyz	dtype,msg)zm8[ps]zcannot convert timedeltalike)zM8[ps]zcannot convert datetimelikec              	   C   s*   t jt|d tg |d W 5 Q R X d S )Nr>   rN   )rD   rE   rF   r   )r9   rB   rG   r$   r$   r%   0test_constructor_generic_timestamp_bad_frequency  s    
zGTestSeriesConstructors.test_constructor_generic_timestamp_bad_frequencyr  c                 C   s:   t dddddg|pdd}t td|d}t|| d S )	Nr   rL   rb   r[   rc   r   rN   rp   r   )r9   rB   r;   r<   r$   r$   r%   test_constructor_range_dtype+  s    z3TestSeriesConstructors.test_constructor_range_dtypec                 C   sL  t dd}t|}tt|}t|| t|t|ks>t|jtjksNtt ddd}t|}tt|}t|| t|t|kst|jtjkstt ddd}t|}tt|}	t||	 t|t|kst|jt	kstt dd dd d }
t|
}tt|
}t|| t|t|
ks8t|jt	ksHtd S )	Nl            l           r  l         l        rb   I   rc   )
r\   r   rC   r2   r8   r7   rB   rR   Zuint64r   )r9   r   r`   r;   Zrng2ser2Z	expected2Zrng3Zser3Z	expected3Zrng4Zser4Z	expected4r$   r$   r%    test_constructor_range_overflows2  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\  rR  rN   )r   r   r   r2   r8   )r9   Zdt_listr<   r;   r$   r$   r%   test_constructor_tz_mixed_dataP  s    
z5TestSeriesConstructors.test_constructor_tz_mixed_datapydtc              	   C   s   |}t d|d}|r| }t d}tt t|gdd}W 5 Q R X t|g}t|| tt ttj|gt	ddd}W 5 Q R X t|| tt td|idd}W 5 Q R X t|| tt t|dgdd}W 5 Q R X t|| d S )NZ2019rR  r  rN   r   ry   )
r   rF  r2   r3   r4   r   r8   rR   rS   r   )r9   Ztz_aware_fixturer  r   tsZts_naiver<   r;   r$   r$   r%   'test_constructor_data_aware_dtype_naiveZ  s$    
"z>TestSeriesConstructors.test_constructor_data_aware_dtype_naivec                 C   s<   t dddd}t|}t|}t|jtds8td S )Nz1/1/2000 00:00:00z1/1/2000 1:59:50Z10sr   r   )r   rR   Zasarrayr   Z
issubdtyperB   r7   )r9   r   r8  r   r$   r$   r%   test_constructor_datetime64t  s    
z2TestSeriesConstructors.test_constructor_datetime64c                 C   s>   t ddddg|d}t dddgdddg|d}t|| d S )Nr=  rL   rb   r[   ry   r   )r9   Znullable_string_dtyper<   r;   r$   r$   r%   4test_constructor_datetimelike_scalar_to_string_dtype{  s    zKTestSeriesConstructors.test_constructor_datetimelike_scalar_to_string_dtyper   z
2012-01-01r  c                 C   s>   t d}t||d}t jj||d}t|}t|| d S )Nr  rN   )r+  ZSparseDtyper   ZarraysZSparseArrayr2   r8   )r9   r   rB   r<   r2  r;   r$   r$   r%   "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 )NrL   rb   r  rI   rK   )r   r  r2   r8   r   r   r$   r$   r%   )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   rQ   r   )r9   r  r<   r;   r$   r$   r%   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$tt tdddtdddg}|jdksNtd S )	Nz
2000-01-01rx   r>  r   rz  z
2011-01-01r   z
2011-02-01)r   rC   r   rB   r7   r   r  r$   r$   r%   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      $@Nr$   r  r$   r$   r%   r+     s     zHTestSeriesConstructors.test_constructor_subclass_dict.<locals>.<genexpr>rx   )r\   r   r  itemsr2   r8   )r9   Zdict_subclassr/   r   r;   r$   r$   r%   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)rR   rg   r   r$   r$   r%   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   r$   r$   r$   r%   rO     s   rO   )r   r\   r   rC   r   r  r2   r8   )r9   r/   r   r;   rO   r$   r$   r%   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   rV   r   ))rI   rI   )rK   rI   )rK   r   c                 S   s   g | ]}|d  qS r   r$   r  r$   r$   r%   rD    s     zKTestSeriesConstructors.test_constructor_dict_multiindex.<locals>.<listcomp>c                 S   s   g | ]}|d  qS r   r$   r  r$   r$   r%   rD    s     rQ   g     [@zr   c                 S   s   g | ]}|d  qS r   r$   r  r$   r$   r%   rD    s     c                 S   s   g | ]}|d  qS r  r$   r  r$   r$   r%   rD    s     F)Ztupleize_cols)r   r  r   r   r  r2   r8   insertr   Zreindexr6   )r9   r   Z_dr<   r;   r$   r$   r%    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   rL   rb   ))r   r   )r   j)r  r   r  r  rQ   )rR   r|   r   to_dictr6   r2   r8   )r9   r/   r;   r<   r$   r$   r%   -test_constructor_dict_multiindex_reindex_flat  s    zDTestSeriesConstructors.test_constructor_dict_multiindex_reindex_flatc              	   C   sx   t dddgtjdddg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dddgddd	}t|| d S )
NrO   rP   r   r   rx   r   r   )rg  r/   r6   )r   r+  Zto_timedeltar2   r8   r   r$   r$   r%   %test_constructor_dict_timedelta_index  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sRtt|jd
  d S )Ng     g@g     t@i   i  rp   r  )tzinfor  r  r   )r   r   r   r6   r   r7   repr)r9   r   r  r6   r   r$   r$   r%   test_constructor_infer_index_tz  s    
z6TestSeriesConstructors.test_constructor_infer_index_tzc                 C   s6   dddg}t |}|jj}t ||d}t|| d S )Nr   )rb   r   rN   )r   rS   rB   r2   r8   )r9   rd  r`   rB   r  r$   r$   r%   "test_constructor_with_pandas_dtype  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   ry   rv   )r   rR   r|   r2   r8   r   r$   r$   r%   )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   ry   Tr   r   r$   r$   r%   *test_constructor_bool_dtype_missing_values	  s    zATestSeriesConstructors.test_constructor_bool_dtype_missing_valuesz7ignore:elementwise comparison failed:DeprecationWarningz(np.array([td64nat, float, float]) raisesfuncc              
   C   sV   d dddddg}tjtg D ]0}tjt|d ||dd	g|d
 W 5 Q R X 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 NAr>   rV   g      @rN   )r  r2   ZNP_NAT_OBJECTSr   rD   rE   rF   )r9   r  Zany_numeric_ea_dtyperG   nullr$   r$   r%   /test_constructor_mismatched_null_nullable_dtype  s    zFTestSeriesConstructors.test_constructor_mismatched_null_nullable_dtype)r   r   r   rD   r  parametrizer=   rH   rU   rZ   ra   ro   rt   rC   r  r   r   rR   r|   rX   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
  r  skip_array_manager_invalid_testr   r   r   r   r  r  r  r  r  r  r!  r"  r#  r$  r&  r-  r/  r3  r5  r:  r;  r<  rG  rI  rL  rM  rO  rP  rZ  r`  ra  rb  re  r   rv   rj  r   rl  rm  r   r   rq  rS   rt  ru  rw  r{  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  filterwarningsr  r  r  r  r  r  r  r  r  r  r  r  r6  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!   8   s  











	
%
$



	



%	"M

	


	
	1
4

	
  
  
  

	
	
	R			


	 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 	t
 |jjs>tW 5 Q R X t|jtsXtd S )Ni'  )r2   ZmakeDateIndexr   rR   rg   rh   r5   r   r   r3   r4   r6   Zis_all_datesr7   rW   r   )r9   idxr`   r$   r$   r%   3test_series_constructor_datetimelike_index_coercion,  s
    
zVTestSeriesConstructorIndexCoercion.test_series_constructor_datetimelike_index_coercionc                 C   s~   ddddgddddgg}t ddd |D d}t|jts>tt d|d}t|jtsZtt td	|d}t|jtsztd S )
NrI   rK   r   r	  rV   c                 S   s   g | ]}t |qS r$   )rR   rS   r  r$   r$   r%   rD  6  s     z_TestSeriesConstructorIndexCoercion.test_series_constructor_infer_multiindex.<locals>.<listcomp>rQ   rc   )r   rW   r6   r   r7   r\   )r9   Zindex_listsmultir$   r$   r%   (test_series_constructor_infer_multiindex3  s    zKTestSeriesConstructorIndexCoercion.test_series_constructor_infer_multiindexN)r   r   r   r  r  r$   r$   r$   r%   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   sB   t dddg}t |j}t|| |s>t|jjd ts>td S )NrL   rb   r[   r   )	r   rS   r2   r8   rW   r  r  r    r7   )r9   Zusing_array_managerr`   r<   r$   r$   r%    test_constructor_no_pandas_arrayA  s
    
z?TestSeriesConstructorInternals.test_constructor_no_pandas_arrayc                 C   sZ   t tjddgdd}|jjd jdks,tt tjdgdd}|jjd jdksVtd S 	NZ1HZ2Hr  rN   r   FZ2015r  )r   r+  rS   r  r  is_extensionr7   r   r$   r$   r%   test_from_arrayH  s    z.TestSeriesConstructorInternals.test_from_arrayc                 C   sN   t ddgdd}|jjd jdks&tt dgdd}|jjd jdksJtd S r  )r   r  r  r  r7   r   r$   r$   r%   test_from_list_dtypeP  s    z3TestSeriesConstructorInternals.test_from_list_dtypeN)r   r   r   r  r  r  r  r  r$   r$   r$   r%   r  @  s
   
r  c                 C   s&   | }t |tstt |jts"td S r"   )rW   r   r7   r6   r   )Z(rand_series_with_duplicate_datetimeindexZdupsr$   r$   r%   ro   Y  s    ro   zinput_dict,expectedrN   rI   rL   zfails on numpy below 1.19r|  c                 C   s    t t| g}t|| d S r"   )rR   rS   r   r2   r   )Z
input_dictr;   r<   r$   r$   r%   test_numpy_array_  s    
r  z!check failure on numpy below 1.19c                	   C   s2   t jtdd ttddig W 5 Q R X d S )Nr  r>   rL   )rD   rE   KeyErrorrR   rS   r   r$   r$   r$   r%   test_numpy_array_np_v1p19m  s    r   )Bcollectionsr   r   r   Zdateutil.tzr   numpyrR   Znumpy.mar   rD   Zpandas._libsr   r   Zpandas.compat.numpyr   r	   Zpandas.util._test_decoratorsutilZ_test_decoratorsr  Zpandas.core.dtypes.commonr
   r   Zpandas.core.dtypes.dtypesr   Zpandasr+  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Zpandas._testingZ_testingr2   Zpandas.core.apir   Zpandas.core.arraysr   r   Zpandas.core.internals.blocksr    r!   r  r  ro   r  r  rS   r   r   Zskipifr  r   r$   r$   r$   r%   <module>   s`   H               