U
    c                  	   @  s4  U d dl mZ d dlZd dlmZ d dlmZ d dlm	Z	m
Z
 G dd de
ZG dd	 d	e	Zd
ZeG dd deZeG dd deZeG dd deZeG dd deZeG dd deZeG dd deZeG dd deZeG dd deZe e e e e e e e dZded< dS )    )annotationsN)register_extension_dtype)is_integer_dtype)NumericArrayNumericDtypec                   @  sV   e Zd ZdZeejZeZ	e
ddddZe
dd Ze
dd	d
ddddZdS )IntegerDtypea&  
    An ExtensionDtype to hold a single size & kind of integer dtype.

    These specific implementations are subclasses of the non-public
    IntegerDtype. For example we have Int8Dtype to represent signed int 8s.

    The attributes name & type are set when these subclasses are created.
    ztype[IntegerArray])returnc                 C  s   t S )zq
        Return the array type associated with this dtype.

        Returns
        -------
        type
        )IntegerArraycls r   >/tmp/pip-unpacked-wheel-g7fro6k3/pandas/core/arrays/integer.pyconstruct_array_type   s    	z!IntegerDtype.construct_array_typec                 C  s   t S )N)INT_STR_TO_DTYPEr
   r   r   r   _str_to_dtype_mapping&   s    z"IntegerDtype._str_to_dtype_mappingz
np.ndarrayznp.dtypebool)valuesdtypecopyr   c              
   C  s~   z|j |d|dW S  tk
rx } zH|j ||d}||k rJ| W Y $S td|j dt| |W 5 d}~X Y nX dS )z
        Safely cast the values to the given dtype.

        "safe" in this context means the casting is lossless. e.g. if 'values'
        has a floating dtype, each value must be an integer.
        safe)Zcastingr   )r   z"cannot safely cast non-equivalent z to N)Zastype	TypeErrorallr   np)r   r   r   r   errZcastedr   r   r   
_safe_cast*   s    zIntegerDtype._safe_castN)__name__
__module____qualname____doc__r   r   int64Z_default_np_dtyper   Z_checkerclassmethodr   r   r   r   r   r   r   r      s   	

r   c                   @  s    e Zd ZdZeZdZdZdZdS )r	   a>  
    Array of integer (optional missing) values.

    .. versionchanged:: 1.0.0

       Now uses :attr:`pandas.NA` as the missing value rather
       than :attr:`numpy.nan`.

    .. warning::

       IntegerArray is currently experimental, and its API or internal
       implementation may change without warning.

    We represent an IntegerArray with 2 numpy arrays:

    - data: contains a numpy integer array of the appropriate dtype
    - mask: a boolean array holding a mask on the data, True is missing

    To construct an IntegerArray from generic array-like input, use
    :func:`pandas.array` with one of the integer dtypes (see examples).

    See :ref:`integer_na` for more.

    Parameters
    ----------
    values : numpy.ndarray
        A 1-d integer-dtype array.
    mask : numpy.ndarray
        A 1-d boolean-dtype array indicating missing values.
    copy : bool, default False
        Whether to copy the `values` and `mask`.

    Attributes
    ----------
    None

    Methods
    -------
    None

    Returns
    -------
    IntegerArray

    Examples
    --------
    Create an IntegerArray with :func:`pandas.array`.

    >>> int_array = pd.array([1, None, 3], dtype=pd.Int32Dtype())
    >>> int_array
    <IntegerArray>
    [1, <NA>, 3]
    Length: 3, dtype: Int32

    String aliases for the dtypes are also available. They are capitalized.

    >>> pd.array([1, None, 3], dtype='Int32')
    <IntegerArray>
    [1, <NA>, 3]
    Length: 3, dtype: Int32

    >>> pd.array([1, None, 3], dtype='UInt16')
    <IntegerArray>
    [1, <NA>, 3]
    Length: 3, dtype: UInt16
       r   N)	r   r   r   r   r   Z
_dtype_clsZ_internal_fill_valueZ_truthy_valueZ_falsey_valuer   r   r   r   r	   >   s
   Cr	   z
An ExtensionDtype for {dtype} integer data.

.. versionchanged:: 1.0.0

   Now uses :attr:`pandas.NA` as its missing value,
   rather than :attr:`numpy.nan`.

Attributes
----------
None

Methods
-------
None
c                   @  s"   e Zd ZejZdZejddZ	dS )	Int8DtypeZInt8int8r   N)
r   r   r   r   r#   typename_dtype_docstringformatr   r   r   r   r   r"      s   r"   c                   @  s"   e Zd ZejZdZejddZ	dS )
Int16DtypeZInt16int16r$   N)
r   r   r   r   r*   r%   r&   r'   r(   r   r   r   r   r   r)      s   r)   c                   @  s"   e Zd ZejZdZejddZ	dS )
Int32DtypeZInt32int32r$   N)
r   r   r   r   r,   r%   r&   r'   r(   r   r   r   r   r   r+      s   r+   c                   @  s"   e Zd ZejZdZejddZ	dS )
Int64DtypeZInt64r   r$   N)
r   r   r   r   r   r%   r&   r'   r(   r   r   r   r   r   r-      s   r-   c                   @  s"   e Zd ZejZdZejddZ	dS )
UInt8DtypeZUInt8uint8r$   N)
r   r   r   r   r/   r%   r&   r'   r(   r   r   r   r   r   r.      s   r.   c                   @  s"   e Zd ZejZdZejddZ	dS )UInt16DtypeZUInt16uint16r$   N)
r   r   r   r   r1   r%   r&   r'   r(   r   r   r   r   r   r0      s   r0   c                   @  s"   e Zd ZejZdZejddZ	dS )UInt32DtypeZUInt32uint32r$   N)
r   r   r   r   r3   r%   r&   r'   r(   r   r   r   r   r   r2      s   r2   c                   @  s"   e Zd ZejZdZejddZ	dS )UInt64DtypeZUInt64uint64r$   N)
r   r   r   r   r5   r%   r&   r'   r(   r   r   r   r   r   r4      s   r4   )r#   r*   r,   r   r/   r1   r3   r5   zdict[str, IntegerDtype]r   )
__future__r   Znumpyr   Zpandas.core.dtypes.baser   Zpandas.core.dtypes.commonr   Zpandas.core.arrays.numericr   r   r   r	   r'   r"   r)   r+   r-   r.   r0   r2   r4   r   __annotations__r   r   r   r   <module>   sB    0M