
     	i                    6   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 d6 d7          Z G d8 d9          ZdDd>ZdEdCZdS )FzE
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                  ^    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     U/srv/django_bis/venv311/lib/python3.11/site-packages/pandas/core/interchange/utils.pyr3   r3   =   s{          DDDEEFEFEFGGGFLFF &IDDDrM   r3   c                  "    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)r5   r6   r7   r8   LITTLEBIGNATIVENArL   rM   rN   rP   rP   _   s(        88F
CF	BBBrM   rP   dtyper   returnstrc                F   t          | t                    rt          j        S | t	          j        d          k    rt          j        S t          | t                    rddl}| j	        }|j
                            |          rd|j         d|j         S |j
                            |          r|j        d|j        d          d|j         S t"                              t'          |          d          }||S t)          t          | j                                        d          }||S t          | t.          j                  rt          j        S t3          j        | d          rAt	          j        |           d         d         }t          j                            |d	
          S t          | t<                    r1t          j                            | j        d         | j        
          S t          | t.          j                  rt          j         S tC          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   r3   rA   nprY   rF   r   pyarrowpyarrow_dtypetypes
is_decimal	precisionscaleis_timestamprd   unitPYARROW_CTYPESgetr[   getattrnameupperpdStringDtyper   is_np_dtypedatetime_datarJ   formatr   BooleanDtyper:   NotImplementedError)rY   papa_type
format_strrc   s        rN   dtype_to_arrow_c_fmtr~   h   s    %)**   	"(3--		!!	E:	&	& 
%8w'' 	7;);;GM;;;X""7++ 	7
0F6Q66'*666#''Gd;;
!ej&6&6&8&8$??J%((   !!		$	$ 
  %e,,Q/2
$++zb+III	E?	+	+  $++uz!}+RRR	E2?	+	+  
MMMM  rM   series	pd.Series
allow_copypd.Series | Nonec               (   t          | j        t          j                  sdS | j        j        }t          |j                  dk    rdS |st          d          |	                                }t          j
        || j        | j        | j                  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`.)rY   rr   index)re   rY   rt   r   array	_pa_arraylenchunksRuntimeErrorcombine_chunksSeriesrr   r   )r   r   chunked_arrayarrs       rN   maybe_rechunkr      s     flBM22 tL*M
=  A%%t 
!
 
 	

 
&
&
(
(C9S6;flSSSSrM   )rY   r   rZ   r[   )r   r   r   r   rZ   r   )r8   
__future__r   typingnumpyrf   pandas._libsr   pandas.core.dtypes.dtypesr   r   r   pandasrt   TYPE_CHECKINGpandas._typingr   ro   r3   rP   r~   r   rL   rM   rN   <module>r      s9    # " " " " "                        	 (''''''

C
C S c	
 c c C S S S  S c c C  c!" #$ =  D       D       5 5 5 5pT T T T T TrM   