U
    c	4                     @  s  d dl mZ d dlmZmZ d dlZd dlZd dlm	Z
mZ d dlmZmZ d dlmZmZ d dlmZ d dlmZmZmZmZmZmZmZmZ d d	lmZ d d
lm Z m!Z! G dd de Z"i Z#de#d< G dd de"Z$G dd de$Z%G dd de$Z&G dd de"Z'dS )    )annotations)CallableHashableN)indexlib)Dtypenpt)cache_readonlydoc)find_stack_level)is_dtype_equalis_float_dtypeis_integer_dtypeis_numeric_dtype	is_scalaris_signed_integer_dtypeis_unsigned_integer_dtypepandas_dtype)	ABCSeries)Indexmaybe_extract_namec                      s0  e Zd ZU dZdZded< dZded< edfZd	ed
< dZ	dZ
dZded< eejejeejejeejejeejejeejejeejejeejejeejejeejej eej!ej"eej#ej$eej%ej&iZ'ded< e(ddddZ)e*ddddZ+d<dd dddZ,e-ddddZ.e-dddd d!Z/e-dddd"d#Z0e*e1e2j3ddd$d%Z3e1e2j4d&dd' fd(d)Z4e1e2j5e6j7fdd*d+d,Z5e1e2j8e6j7fd-d. fd/d0Z8 fd1d2Z9e-dddd3d4d5Z:d6dd7dd8d9d fd:d;Z;  Z<S )=NumericIndexa!  
    Immutable numeric sequence used for indexing and alignment.

    The basic object storing axis labels for all pandas objects.
    NumericIndex is a special case of `Index` with purely numpy int/uint/float labels.

    .. versionadded:: 1.4.0

    Parameters
    ----------
    data : array-like (1-dimensional)
    dtype : NumPy dtype (default: None)
    copy : bool
        Make a copy of input ndarray.
    name : object
        Name to be stored in the index.

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

    Methods
    -------
    None

    See Also
    --------
    Index : The base pandas Index type.
    Int64Index : Index of purely int64 labels (deprecated).
    UInt64Index : Index of purely uint64 labels (deprecated).
    Float64Index : Index of  purely float64 labels (deprecated).

    Notes
    -----
    An NumericIndex instance can **only** contain numpy int64/32/16/8, uint64/32/16/8 or
    float64/32/16 dtype. In particular, ``NumericIndex`` *can not* hold Pandas numeric
    dtypes (:class:`Int64Dtype`, :class:`Int32Dtype` etc.).
    Znumericindexz
np.ndarray_valuesNznp.dtype | None_default_dtypeznumeric typeztuple[Callable[..., bool], str]_dtype_validation_metadataTFbool(_is_backward_compat_public_numeric_indexz*dict[np.dtype, type[libindex.IndexEngine]]_engine_typesztype[libindex.IndexEngine]returnc                 C  s   | j | j S N)r   dtypeself r$   ?/tmp/pip-unpacked-wheel-g7fro6k3/pandas/core/indexes/numeric.py_engine_typem   s    zNumericIndex._engine_typestrc                 C  s   ddddd| j j S )NintegerZfloatingcomplex)iufc)r!   kindr"   r$   r$   r%   inferred_types   s    zNumericIndex.inferred_typezDtype | None)r!   r   c                 C  s(   t ||| }| |||}| j||dS )Nname)r   _ensure_array_simple_new)clsdatar!   copyr1   subarrr$   r$   r%   __new__|   s    zNumericIndex.__new__)r6   c              	   C  sB  |  | t|tjtfst|r,| |t|ttt	fsDt|}|}tj
||d}|dkr|jjdkr| tkr|dk rtj
|tjd}t|jjtr| | | |}|st|j|sz tj|||d}|  |j W n* ttfk
r   td| j Y nX | || n|}|jdkr4tdt
|}|S )	zF
        Ensure we have a valid array to pass to _simple_new.
        )r!   Nr,   r   )r!   r6   zdata is not compatible with    z Index data must be 1-dimensional)_validate_dtype
isinstancenpZndarrayr   r   Z_scalar_data_errorr   listtupleZasarrayr!   r.   UInt64Indexalluint64
issubclasstyper'   Z_string_data_error_ensure_dtyper   array	TypeError
ValueError__name___assert_safe_castingndim)r4   r5   r!   r6   origr7   r$   r$   r%   r2      s4    




zNumericIndex._ensure_arrayNonec                 C  s6   |d krd S | j \}}||s2td| d| d S )Nz#Incorrect `dtype` passed: expected z, received )r   rG   )r4   r!   Zvalidation_funcexpectedr$   r$   r%   r:      s    
zNumericIndex._validate_dtypec                 C  s:   |dkr| j S t|}t|tjs&t| jr0|S | j S dS )z
        Ensure int64 dtype for Int64Index etc. but allow int32 etc. for NumericIndex.

        Assumes dtype has already been validated.
        N)r   r   r;   r<   r!   AssertionErrorr   )r4   r!   r$   r$   r%   rD      s    zNumericIndex._ensure_dtypec                 C  s   dS )NFr$   r"   r$   r$   r%   _should_fallback_to_positional   s    z+NumericIndex._should_fallback_to_positionalslice)keyr.   c                   s:   t | jr*|dkst| |j|j|jS t j||dS )N)locgetitem)r.   )	r   r!   rN   Zslice_indexerstartstopstepsuper_convert_slice_indexer)r#   rQ   r.   	__class__r$   r%   rX      s    
z#NumericIndex._convert_slice_indexer)sidec                 C  s.   |ddd t jfkst| |dd | |S )NrR   rS   r.   _maybe_cast_slice_bound)r   
no_defaultrN   Z_deprecated_argZ_maybe_cast_indexer)r#   labelr[   r.   r$   r$   r%   r\      s    z$NumericIndex._maybe_cast_slice_boundr   r0   c                   sD   | j s4|jjdkr4|tjkr"| jn|}tj||dS t j	||dS )Nr,   r0   )valuesr1   )
Z_can_hold_nar!   r.   r   r]   _nameFloat64Indexr3   rW   _shallow_copy)r#   r_   r1   rY   r$   r%   rb      s    zNumericIndex._shallow_copyc                   sb   t  ||}t|jtjs^|jdkr@tdt| j	 dntdt| j	 dt
| |S )Nr   ztolerance argument for z1 must contain numeric elements if it is list typez$ must be numeric if it is a scalar: )rW   _convert_tolerancer<   Z
issubdtyper!   numberrJ   rG   rC   rH   repr)r#   Z	tolerancetargetrY   r$   r%   rc      s    
zNumericIndex._convert_tolerance)r5   r7   r   c                 C  s"   t |jrt||stddS )z
        Ensure incoming data can be represented with matching signed-ness.

        Needed if the process of casting data from some accepted dtype to the internal
        dtype(s) bears the risk of truncation (e.g. float to int).
        z.Unsafe NumPy casting, you must explicitly castN)r   r!   r<   Zarray_equalrF   )r4   r5   r7   r$   r$   r%   rI     s    
z!NumericIndex._assert_safe_casting .na_repfloat_formatdecimalquotingznpt.NDArray[np.object_]c                  sP   ddl m} t| jr4|| j||||dd}| S t jf ||||d|S )Nr   )FloatArrayFormatterF)rj   rk   rl   rm   Zfixed_widthri   )Zpandas.io.formats.formatrn   r   r!   r   Zget_result_as_arrayrW   _format_native_types)r#   rj   rk   rl   rm   kwargsrn   	formatterrY   r$   r%   ro     s&    
z!NumericIndex._format_native_types)NNFN)=rH   
__module____qualname____doc___typ__annotations__r   r   r   Z_is_numeric_dtypeZ_can_hold_stringsr   r<   r!   Zint8libindexZ
Int8EngineZint16ZInt16EngineZint32ZInt32Engineint64Int64EngineZuint8ZUInt8EngineZuint16ZUInt16EngineZuint32ZUInt32EnginerA   UInt64EngineZfloat32ZFloat32Enginefloat64Float64EngineZ	complex64ZComplex64EngineZ
complex128ZComplex128Enginer   propertyr&   r	   r/   r8   classmethodr2   r:   rD   r
   r   rO   rX   r\   r   r]   rb   rc   rI   ro   __classcell__r$   r$   rY   r%   r   +   s   
'
 
 
 
 
 
 
 
 
 
 
 
 	       0
	   r   a  
    Immutable sequence used for indexing and alignment.

    .. deprecated:: 1.4.0
        In pandas v2.0 %(klass)s will be removed and :class:`NumericIndex` used instead.
        %(klass)s will remain fully functional for the duration of pandas 1.x.

    The basic object storing axis labels for all pandas objects.
    %(klass)s is a special case of `Index` with purely %(ltype)s labels. %(extra)s.

    Parameters
    ----------
    data : array-like (1-dimensional)
    dtype : NumPy dtype (default: %(dtype)s)
    copy : bool
        Make a copy of input ndarray.
    name : object
        Name to be stored in the index.

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

    Methods
    -------
    None

    See Also
    --------
    Index : The base pandas Index type.
    NumericIndex : Index of numpy int/uint/float data.

    Notes
    -----
    An Index instance can **only** contain hashable objects.
class_descrc                   @  s0   e Zd ZU dZdZded< eddddZd	S )
IntegerIndexz@
    This is an abstract class for Int64Index, UInt64Index.
    Fr   r   znpt.NDArray[np.int64]r   c                 C  s    t jdtt d | j| jS )NzAIndex.asi8 is deprecated and will be removed in a future version.)
stacklevel)warningswarnFutureWarningr   r   viewr   r"   r$   r$   r%   asi8e  s    zIntegerIndex.asi8N)rH   rr   rs   rt   r   rv   r}   r   r$   r$   r$   r%   r   ^  s   
r   c                   @  sP   e Zd Zd ddddZed e ZdZeej	Z
edfZedd	d
dZdS )
Int64Indexr(   rx   rg   klassltyper!   extrar   Z
int64indexzsigned integerztype[libindex.Int64Engine]r   c                 C  s   t jS r    )rw   ry   r"   r$   r$   r%   r&   }  s    zInt64Index._engine_typeN)rH   rr   rs   _index_descr_args_num_index_shared_docsrt   ru   r<   r!   rx   r   r   r   r}   r&   r$   r$   r$   r%   r   p  s   r   c                   @  sP   e Zd Zd ddddZed e ZdZeej	Z
edfZeddd	d
ZdS )r?   zunsigned integerrA   rg   r   r   Zuint64indexztype[libindex.UInt64Engine]r   c                 C  s   t jS r    )rw   rz   r"   r$   r$   r%   r&     s    zUInt64Index._engine_typeN)rH   rr   rs   r   r   rt   ru   r<   r!   rA   r   r   r   r}   r&   r$   r$   r$   r%   r?     s   r?   c                   @  s^   e Zd ZU d ddddZed e ZdZeej	Z
edfZdZded	< ed
dddZdS )ra   r{   floatrg   )r   r!   r   r   r   Zfloat64indexFr   r   ztype[libindex.Float64Engine]r   c                 C  s   t jS r    )rw   r|   r"   r$   r$   r%   r&     s    zFloat64Index._engine_typeN)rH   rr   rs   r   r   rt   ru   r<   r!   r{   r   r   r   r   rv   r}   r&   r$   r$   r$   r%   ra     s   
ra   )(
__future__r   typingr   r   r   Znumpyr<   Zpandas._libsr   rw   r   Zpandas._typingr   r   Zpandas.util._decoratorsr	   r
   Zpandas.util._exceptionsr   Zpandas.core.dtypes.commonr   r   r   r   r   r   r   r   Zpandas.core.dtypes.genericr   Zpandas.core.indexes.baser   r   r   r   r   r   r?   ra   r$   r$   r$   r%   <module>   s,   (
  
(