o
    ŀg#                     @  s   d dl mZ d dlZd dlmZmZmZ d dlZd dl	m
Z
mZ d dlmZ d dlmZ d dlmZmZmZ d dlmZmZ erVd d	lmZ d dlZd d
lmZmZmZmZ G dd deZ dddZ!G dd deZ"dS )    )annotationsN)TYPE_CHECKINGAnyCallable)libmissingAbstractMethodError)cache_readonly)is_integer_dtypeis_string_dtypepandas_dtype)BaseMaskedArrayBaseMaskedDtype)Mapping)DtypeDtypeObjSelfnptc                   @  s   e Zd ZU ded< ded< d"ddZed#d
dZed#ddZed#ddZ	d$ddZ
ed%ddZed&ddZed'dd Zd!S )(NumericDtypenp.dtype_default_np_dtypezCallable[[Any], bool]_checkerreturnstrc                 C  s   | j  dS )NzDtype())nameself r   N/var/www/html/myenv/lib/python3.10/site-packages/pandas/core/arrays/numeric.py__repr__/   s   zNumericDtype.__repr__boolc                 C  
   | j dkS )Nikindr   r   r   r   is_signed_integer2      
zNumericDtype.is_signed_integerc                 C  r"   )Nur$   r   r   r   r   is_unsigned_integer6   r'   z NumericDtype.is_unsigned_integerc                 C  s   dS )NTr   r   r   r   r   _is_numeric:   s   zNumericDtype._is_numericarray$pyarrow.Array | pyarrow.ChunkedArrayr   c           	      C  s   ddl }ddlm} |  }|| j}|j|s>|j|js>t	|j
 }|jdvr9td|  d|j d||}t||jrV|jdkrR|jg |jd}n| }||| jd	\}}|| | d
dS )zW
        Construct IntegerArray/FloatingArray from pyarrow Array/ChunkedArray.
        r   N)pyarrow_array_to_numpy_and_maskiufzExpected array of z type, got z instead)typedtypeFcopy)pyarrow%pandas.core.arrays.arrow._arrow_utilsr-   construct_array_typefrom_numpy_dtyper/   equalstypesis_nullr   to_pandas_dtyper%   	TypeErrorcast
isinstanceChunkedArray
num_chunksr+   combine_chunksnumpy_dtyper3   )	r   r+   r4   r-   array_classpyarrow_typert_dtypedatamaskr   r   r   __from_arrow__>   s&   


zNumericDtype.__from_arrow__Mapping[np.dtype, NumericDtype]c                 C     t | Nr   )clsr   r   r   _get_dtype_mappingg   s   zNumericDtype._get_dtype_mappingr1   NumericDtype | str | np.dtypec              
   C  sp   t |tr|dr| }t |ts6|  }z
|t| }W |S  ty5 } zt	d| |d}~ww |S )zS
        Convert a string representation or a numpy dtype to NumericDtype.
        )IntUIntFloatzinvalid dtype specified N)
r>   r   
startswithlowerr   rM   npr1   KeyError
ValueError)rL   r1   mappingerrr   r   r   _standardize_dtypek   s   
zNumericDtype._standardize_dtypevalues
np.ndarrayr3   c                 C  rJ   )z{
        Safely cast the values to the given dtype.

        "safe" in this context means the casting is lossless.
        r   )rL   rZ   r1   r3   r   r   r   
_safe_cast}   s   zNumericDtype._safe_castN)r   r   )r   r!   )r+   r,   r   r   )r   rI   )r1   rN   r   r   )rZ   r[   r1   r   r3   r!   r   r[   )__name__
__module____qualname____annotations__r    r
   r&   r)   propertyr*   rH   classmethodrM   rY   r\   r   r   r   r   r   +   s"   
 

)r   r3   r!   	dtype_clstype[NumericDtype]default_dtyper   c                 C  s  |j }d }d }|d u rt| dr|| jr| j}|d ur!||}| }t| |rM| j| j} }|d ur=| j|j	dd} |rG| 
 } |
 }| |||fS | }	|sWt| } ntj| |d} d }| jtksjt| jrtj| dd}|dkr|d u r|jd}
t| j d|
 n3| jjd	kr||r|stj| |d
} ntj| ||d} n| jjdvr|jd}
t| j d|
 | jdkrtd|d u r| jjdv rtjt| tjd
}nt| }n
t|t| ksJ |jdkrtd|d u r|}n|j	}t|rO| jjdkrOt| dkrO| rtj| j|d
} n0t | }t!| | |	| krOtj|	dd}|dvrH|" sHtj|	|d
} ntj|	dd
} |" r]| 
 } |j#| |< |dv rj| j||d} n|j$| |dd} | |||fS )Nr1   Fr2   T)skipnaboolean_z cannot be converted to br0   r1   r3   r.      zvalues must be a 1D list-likeiuzmask must be a 1D list-likefr   )floatingzmixed-integer-floatobject)stringunicode)%r   hasattrr1   rY   r6   r>   _data_maskastyperB   r3   rT   asarrayr+   ro   r   r   infer_dtyper]   stripr<   r%   ndimzeroslenbool_
libmissingis_numeric_nar   allonesshape	nanargmaxintany_internal_fill_valuer\   )rZ   r1   r3   rc   re   checkerrG   inferred_typerL   originalr   idxr   r   r   _coerce_to_data_and_mask   s   




&





r   c                      st   e Zd ZU dZded< 	dd fddZed ddZeddd!ddZ	edddd"ddZ
ejejfZ  ZS )#NumericArrayz8
    Base class for IntegerArray and FloatingArray.
    rd   
_dtype_clsFrZ   r[   rG   npt.NDArray[np.bool_]r3   r!   r   Nonec                   sl   | j j}t|tjr||js!| j jdkrdnd}td| d|jtjkr+tdt	 j
|||d d S )Nrm   rn   integerzvalues should be z1 numpy array. Use the 'pd.array' function insteadz0FloatingArray does not support np.float16 dtype.r2   )r   r   r>   rT   ndarrayr1   r%   r<   float16super__init__)r   rZ   rG   r3   r   descr	__class__r   r   r      s   
zNumericArray.__init__r   c                 C  s   | j  }|| jj S rK   )r   rM   rs   r1   )r   rW   r   r   r   r1     s   
zNumericArray.dtyper2   r1   r   tuple[np.ndarray, np.ndarray]c          	      C  s,   | j }|j}t|||||\}}}}||fS rK   )r   r   r   )	rL   valuer1   r3   rc   re   rZ   rG   rh   r   r   r   _coerce_to_array
  s   
zNumericArray._coerce_to_arrayNrj   Dtype | Noner   c                C  s*   ddl m} ||ddd}| j|||dS )Nr   )
to_numericraisenumpy_nullable)errorsdtype_backendrj   )pandas.core.tools.numericr   _from_sequence)rL   stringsr1   r3   r   scalarsr   r   r   _from_sequence_of_strings  s   z&NumericArray._from_sequence_of_strings)F)rZ   r[   rG   r   r3   r!   r   r   )r   r   )r1   r   r3   r!   r   r   )r1   r   r3   r!   r   r   )r]   r^   r_   __doc__r`   r   r
   r1   rb   r   r   rT   r   numbersNumber_HANDLED_TYPES__classcell__r   r   r   r   r      s   
 
r   )r3   r!   rc   rd   re   r   )#
__future__r   r   typingr   r   r   numpyrT   pandas._libsr   r   r}   pandas.errorsr	   pandas.util._decoratorsr
   pandas.core.dtypes.commonr   r   r   pandas.core.arrays.maskedr   r   collections.abcr   r4   pandas._typingr   r   r   r   r   r   r   r   r   r   r   <module>   s     
\c