o
    $j                     @  s  d Z ddlmZ ddlZddlZddlmZ ddlm	Z	m
Z
mZ ddlZejr-ddlmZ i ddd	d
ddddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5ZG d6d7 d7ZG d8d9 d9ZdFd>d?ZdGdDdEZdS )HzE
Utility functions and objects for implementing the interchange API.
    )annotationsN)lib)
ArrowDtypeCategoricalDtypeDatetimeTZDtype)DtypeObjnullnboolbZuint8CZuint16SZuint32IZuint64LZint8cZint16Zint32iZint64lZ	halffloatefloatfdoublegstringuZlarge_stringUbinaryzz	time32[s]ZttsZttmZttuZttntdDtdmztss:ztsm:ztsu:ztsn:ZtDsZtDmZtDuZtDn)z
time32[ms]z
time64[us]z
time64[ns]zdate32[day]z
date64[ms]ztimestamp[s]ztimestamp[ms]ztimestamp[us]ztimestamp[ns]zduration[s]zduration[ms]zduration[us]zduration[ns]c                   @  s\   e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdZdZdZdZdZdZdS )ArrowCTypesz
    Enum for Apache Arrow C type format strings.

    The Arrow C data interface:
    https://arrow.apache.org/docs/format/CDataInterface.html#data-type-description-format-strings
    r	   r   r   r   sr   r   r   r   r   r   r   r   r   r   r   r   zts{resolution}:{tz}ztt{resolution}N)__name__
__module____qualname____doc__ZNULLBOOLZINT8ZUINT8ZINT16ZUINT16ZINT32ZUINT32INT64ZUINT64ZFLOAT16ZFLOAT32ZFLOAT64STRINGZLARGE_STRINGZDATE32ZDATE64	TIMESTAMPZTIME r)   r)   ^/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/pandas/core/interchange/utils.pyr   =   s*    r   c                   @  s    e Zd ZdZdZdZdZdZdS )
Endiannessz.Enum indicating the byte-order of a data-type.<>=|N)r!   r"   r#   r$   ZLITTLEZBIGZNATIVEZNAr)   r)   r)   r*   r+   _   s    r+   dtyper   returnstrc                 C  sH  t | trtjS | tdkrtjS t | trSddl}| j	}|j
|r.d|j d|j S |j
|rE|jdurEd|jd  d|j S tt|d}|durS|S tt| j d}|durb|S t | tjrktjS t| drt| d d }tjj|d	d
S t | trtjj| jd | jd
S t | tjrtj S t!d|  d)a   
    Represent pandas `dtype` as a format string in Apache Arrow C notation.

    Parameters
    ----------
    dtype : np.dtype
        Datatype of pandas DataFrame to represent.

    Returns
    -------
    str
        Format string in Apache Arrow C notation of the given `dtype`.
    Or   Nzd:,ts:M )
resolutiontzzConversion of z- to Arrow C format string is not implemented.)"
isinstancer   r   r&   npr0   r'   r   ZpyarrowZpyarrow_dtypetypesZ
is_decimal	precisionscaleZis_timestampr:   unitPYARROW_CTYPESgetr2   getattrnameupperpdZStringDtyper   Zis_np_dtypeZdatetime_datar(   formatr   ZBooleanDtyper%   NotImplementedError)r0   paZpa_type
format_strr9   r)   r)   r*   dtype_to_arrow_c_fmth   s:   



rK   series	pd.Series
allow_copypd.Series | Nonec                C  sX   t | jtjs	dS | jj}t|jdkrdS |std|	 }tj
|| j| j| jdS )a  
    Rechunk a multi-chunk pyarrow array into a single-chunk array, if necessary.

    - Returns `None` if the input series is not backed by a multi-chunk pyarrow array
      (and so doesn't need rechunking)
    - Returns a single-chunk-backed-Series if the input is backed by a multi-chunk
      pyarrow array and `allow_copy` is `True`.
    - Raises a `RuntimeError` if `allow_copy` is `False` and input is a
      based by a multi-chunk pyarrow array.
    N   zFound multi-chunk pyarrow array, but `allow_copy` is False. Please rechunk the array before calling this function, or set `allow_copy=True`.)r0   rD   index)r;   r0   rF   r   arrayZ	_pa_arraylenchunksRuntimeErrorZcombine_chunksZSeriesrD   rQ   )rL   rN   Zchunked_arrayZarrr)   r)   r*   maybe_rechunk   s   rV   )r0   r   r1   r2   )rL   rM   rN   r
   r1   rO   )r$   
__future__r   typingnumpyr<   Zpandas._libsr   Zpandas.core.dtypes.dtypesr   r   r   ZpandasrF   TYPE_CHECKINGZpandas._typingr   rA   r   r+   rK   rV   r)   r)   r)   r*   <module>   s|    	
""
	8