U
    sVc                     @   s  d dl Zd dlZd dlZd dlmZ d dlm	Z	 d dl
mZ d dlmZmZmZ ejejejgddd Zdd	 Zd
d Zdd Zdd Zdd Zejdddgdejgfdgejgfdejgejejgfejejgejejgfgdd Zejdddgdddejdddedgddgddggejddiggd d! Zd"d# Zd$d% Z d&d' Z!d(d) Z"ejd*d+d,gd dge e fd+d,gd dgd-e fd+d,ejgd dejge e fgd.d/ Z#ejd0ejdgd1d2defedejgdefedejgd3efgd4d5 Z$dS )6    N)
is_integer)IntegerArray)	Int8Dtype
Int32Dtype
Int64Dtype)paramsc                 C   s   | j S )zjFixture returning parametrized IntegerArray from given sequence.

    Used to test dtype conversions.
    )param)request r
   Q/tmp/pip-unpacked-wheel-xj8nt62q/pandas/tests/arrays/integer/test_construction.pyconstructor   s    r   c                  C   s*   t jdd gt d} | d t jks&td S )N   dtype)pdarrayr   NAAssertionError)ar
   r
   r   test_uses_pandas_na   s    r   c                 C   s   | j }t| }tj| jtjddt|d}t|| t| }tjt	| 
 t|d}t|| t|  jdd}t	|  t |j}tj|t|d}t|| d S )Nfloat)Zna_valuer   r   T)Zdrop)r   r   SeriesZto_numpynpnanstrtmassert_series_equalr   tolistZdropnaZreset_indexastypetype)datar   expectedresultZdroppedr
   r
   r   test_from_dtype_from_float   s    

r#   c                 C   s   t d| i}|d d}t jtjtjdgtddd}t	|| |d dj
}tjt jdgtd}t|| t||D ]d\}}t |rt |stqt|r||kstt|stq||kstt|t|kstqd S )NAobjectr   r   )name)r   Z	DataFramer   r   r   r   r   r%   r   r   valuesr   Zassert_numpy_array_equalzipZisnullr   r   r   )Zdata_missingZdfr"   r!   rer
   r
   r   test_conversions2   s    
r+   c               	   C   s  t jddddgdd} t jddddgd	d}t| |}tjdddt jgd
d}t|| d}tjt	|d t| 
 | W 5 Q R X tjt	|d t| |
  W 5 Q R X tjt	|d t| t| W 5 Q R X d}tjt	|d t|  W 5 Q R X d S )Nr            int64r   FTboolInt64z@.* should be .* numpy array. Use the 'pd.array' function insteadmatchz;__init__\(\) missing 1 required positional argument: 'mask')r   r   r   r   r   r   assert_extension_array_equalpytestraises	TypeErrorr   r   r   )r'   maskr"   r!   msgr
   r
   r   test_integer_array_constructorK   s    
r:   c                  C   s   t jddddgdd} t jddddgd	d}t| |}|j| ksDt|j|ksRtt| |dd
}|j| k	snt|j|k	s|td S )Nr   r,   r-   r.   r/   r   FTr0   )copy)r   r   r   _datar   Z_mask)r'   r8   r"   r
   r
   r   #test_integer_array_constructor_copya   s    
r=   za, br   c                 C   s,   t j| dd}t j|dd}t|| d S )Nr1   r   )r   r   r   r4   )r   br"   r!   r
   r
   r   !test_to_integer_array_none_is_nann   s    
r?   r'   Zfoobar      ?Z20130101r,   )Zperiodsr-   r.   r   c              	   C   sl   d dddddg}tjttf|d tj| dd	 W 5 Q R X tjttf|d t|  W 5 Q R X d S )
N|z#cannot be converted to IntegerDtypez)invalid literal for int\(\) with base 10:zvalues must be a 1D list-likezCannot pass scalarz!int\(\) argument must be a stringr2   r1   r   )	joinr5   r6   
ValueErrorr7   r   r   r   _from_sequence)r'   r9   r
   r
   r   test_to_integer_array_error}   s    	rF   c                 C   sl   | t jddgdd}|jt ks&t| t jddgdd}|jt ksLt| ddg}|jt kshtd S )Nr   r,   int8r   Zint32)r   r   r   r   r   r   r   r   r"   r
   r
   r   $test_to_integer_array_inferred_dtype   s    rI   c                 C   sN   | ddgdd}|j t ks t| tjddgdddd}|j t ksJtd S )Nr   r,   ZInt8r   rG   ZInt32)r   r   r   r   r   r   rH   r
   r
   r   #test_to_integer_array_dtype_keyword   s    rJ   c               	   C   s   t ddg} tjddgdd}t| | tjtdd t d	dg W 5 Q R X t t	jddgd
d} | j
t ks|td S )NrA   g       @r   r,   r1   r   z!cannot safely cast non-equivalentr2   g      ?Zfloat32)r   rE   r   r   r   r4   r5   r6   r7   r   r   r   r   r"   r!   r
   r
   r   test_to_integer_array_float   s    rL   c               	   C   s   t ddd g} tjddtjgdd}t| | tj	t
dd t ddd	g W 5 Q R X tj	t
dd t d
dg W 5 Q R X d S )N12r   r,   r1   r   z,invalid literal for int\(\) with base 10: .*r2    z1.5z2.0)r   rE   r   r   r   r   r   r4   r5   r6   rD   rK   r
   r
   r   test_to_integer_array_str   s      rP   z5bool_values, int_values, target_dtype, expected_dtypeFTr1   c                 C   s8   | ||d}|j |ksttj||d}t|| d S Nr   )r   r   r   r   r   r4   )r   Zbool_valuesZ
int_valuesZtarget_dtypeZexpected_dtyper"   r!   r
   r
   r   test_to_integer_array_bool   s    rR   zvalues, to_dtype, result_dtyper/   r   rG   c                 C   s>   t j| |d}|j| ksttj| | d}t|| d S rQ   )r   rE   r   r   r   r   r   r4   )r'   Zto_dtypeZresult_dtyper"   r!   r
   r
   r   test_to_integer_array   s    
rS   )%Znumpyr   r5   Zpandasr   Zpandas._testingZ_testingr   Zpandas.api.typesr   Zpandas.core.arraysr   Zpandas.core.arrays.integerr   r   r   Zfixturer   rE   r   r   r#   r+   r:   r=   markZparametrizer   r?   Z
date_rangerF   rI   rJ   rL   rP   rR   rS   r
   r
   r
   r   <module>   sn   
	


	
	