o
    ôT·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ÚbÚuint8ÚCÚuint16ÚSÚuint32ÚIÚuint64ÚLÚint8ÚcÚint16Úint32ÚiÚint64ÚlÚ	halffloatÚeÚfloatÚfÚdoubleÚgÚstringÚuÚlarge_stringÚUÚbinaryÚzz	time32[s]ÚttsÚttmÚttuÚttnÚtdDÚtdmztss:ztsm:ztsu:ztsn:ÚtDsÚtDmÚtDuÚ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__ÚNULLÚBOOLÚINT8ÚUINT8ÚINT16ÚUINT16ÚINT32ÚUINT32ÚINT64ÚUINT64ÚFLOAT16ÚFLOAT32ÚFLOAT64ÚSTRINGÚLARGE_STRINGÚDATE32ÚDATE64Ú	TIMESTAMPÚTIME© rJ   rJ   ú`/home/dinkstrade/pdmp-scanner/venv/lib/python3.10/site-packages/pandas/core/interchange/utils.pyr1   =   s*    r1   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)r3   r4   r5   r6   ÚLITTLEÚBIGÚNATIVEÚNArJ   rJ   rJ   rK   rL   _   s    rL   Ú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¡r‚t | ¡d d }tjj|d	d
�S t | tƒr“tjj| jd | jd
�S t | tjƒrœt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   r1   r?   ÚnprU   rD   r   ÚpyarrowÚpyarrow_dtypeÚtypesÚ
is_decimalÚ	precisionÚscaleÚis_timestampr_   ÚunitÚPYARROW_CTYPESÚgetrW   ÚgetattrÚnameÚupperÚpdÚStringDtyper   Úis_np_dtypeÚdatetime_datarH   Úformatr   ÚBooleanDtyper8   ÚNotImplementedError)rU   ÚpaÚpa_typeÚ
format_strr^   rJ   rJ   rK   Údtype_to_arrow_c_fmth   s:   



ÿry   Ú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é   zŒFound multi-chunk pyarrow array, but `allow_copy` is False. Please rechunk the array before calling this function, or set `allow_copy=True`.)rU   rm   Úindex)r`   rU   ro   r   ÚarrayÚ	_pa_arrayÚlenÚchunksÚRuntimeErrorÚcombine_chunksÚSeriesrm   r   )rz   r|   Úchunked_arrayÚarrrJ   rJ   rK   Úmaybe_rechunk    s   ÿr‰   )rU   r   rV   rW   )rz   r{   r|   r
   rV   r}   )r6   Ú
__future__r   ÚtypingÚnumpyra   Úpandas._libsr   Úpandas.core.dtypes.dtypesr   r   r   Úpandasro   ÚTYPE_CHECKINGÚpandas._typingr   rj   r1   rL   ry   r‰   rJ   rJ   rJ   rK   Ú<module>   s|    ÿþýüûúùø	÷
öõôóòñðïâ""
	8