
    <>iL                       % S SK Jr  S SKJrJr  S SKJrJrJr  S SK	r
S SKrS SKJr  S SKJr  \r\r\r\R&                  \
R(                  " 5       \
R*                  " 5       \
R,                  " 5       \
R.                  " 5       S.\R0                  \
R2                  " 5       \
R4                  " 5       \
R6                  " 5       \
R8                  " 5       S.\R:                  \
R<                  " 5       \
R>                  " 5       \
R@                  " 5       S.\RB                  \
RD                  " 5       \
R2                  " 5       S.\RF                  S	\
RH                  " 5       00r%S
\&S'   SSS jjr'SSS jjr( S     SS jjr) S     SS jjr* S     SS jjr+ S     SS jjr,S r-S r.  S             SS jjr/  S             SS jjr0  S             S S jjr1g)!    )annotations)AnyTuple)	DtypeKindColumnBuffersColumnNullTypeN)Dtype)          @   )r   r   r   )   r
   r
   zdict[DtypeKind, dict[int, Any]]_PYARROW_DTYPESc                (   [        U [        R                  5      (       a  U $ [        U [        R                  5      (       a   [        R                  R	                  U /5      $ [        U S5      (       d  [        S5      e[        U R                  US9US9$ )a  
Build a ``pa.Table`` from any DataFrame supporting the interchange protocol.

Parameters
----------
df : DataFrameObject
    Object supporting the interchange protocol, i.e. `__dataframe__`
    method.
allow_copy : bool, default: True
    Whether to allow copying the memory to perform the conversion
    (if false then zero-copy approach is requested).

Returns
-------
pa.Table

Examples
--------
>>> import pyarrow
>>> from pyarrow.interchange import from_dataframe

Convert a pandas dataframe to a pyarrow table:

>>> import pandas as pd
>>> df = pd.DataFrame({
...         "n_attendees": [100, 10, 1],
...         "country": ["Italy", "Spain", "Slovenia"],
...     })
>>> df
   n_attendees   country
0          100     Italy
1           10     Spain
2            1  Slovenia
>>> from_dataframe(df)
pyarrow.Table
n_attendees: int64
country: large_string
----
n_attendees: [[100,10,1]]
country: [["Italy","Spain","Slovenia"]]
__dataframe__z#`df` does not support __dataframe__)
allow_copy)	
isinstancepaTableRecordBatchfrom_batcheshasattr
ValueError_from_dataframer   )dfr   s     a/var/www/html/land-tabula/venv/lib/python3.13/site-packages/pyarrow/interchange/from_dataframe.pyfrom_dataframer   ?   s|    T "bhh		B	'	'xx$$bT**2''>??2++z+B&02 2    c                    / nU R                  5        H  n[        X15      nUR                  U5        M!     U(       d  [        U 5      nUR                  U5        [        R                  R                  U5      $ )al  
Build a ``pa.Table`` from the DataFrame interchange object.

Parameters
----------
df : DataFrameObject
    Object supporting the interchange protocol, i.e. `__dataframe__`
    method.
allow_copy : bool, default: True
    Whether to allow copying the memory to perform the conversion
    (if false then zero-copy approach is requested).

Returns
-------
pa.Table
)
get_chunksprotocol_df_chunk_to_pyarrowappendr   r   r   )r   r   batcheschunkbatchs        r   r   r   u   s_    " G,U?u ! ,R0u88  ))r   c                   0 nU R                  5        GH  n[        U[        5      (       d  [        SU S35      eX2;   a  [        SU S35      eU R	                  U5      nUR
                  S   nU[        R                  [        R                  [        R                  [        R                  [        R                  4;   a  [        XA5      X#'   M  U[        R                  :X  a  [        XA5      X#'   M  U[        R                  :X  a  [!        XA5      X#'   GM  [#        SU S35      e   [$        R&                  R)                  U5      $ )ap  
Convert interchange protocol chunk to ``pa.RecordBatch``.

Parameters
----------
df : DataFrameObject
    Object supporting the interchange protocol, i.e. `__dataframe__`
    method.
allow_copy : bool, default: True
    Whether to allow copying the memory to perform the conversion
    (if false then zero-copy approach is requested).

Returns
-------
pa.RecordBatch
zColumn z is not a stringz is not uniquer   z
Data type z not handled yet)column_namesr   strr   get_column_by_namedtyper   INTUINTFLOATSTRINGDATETIMEcolumn_to_arrayBOOLbool_column_to_arrayCATEGORICAL categorical_column_to_dictionaryNotImplementedErrorr   r   from_pydict)r   r   columnsnamecolr*   s         r   r!   r!      s   * $&G!$$$wtf,<=>>?wtfN;<<##D)		!MMNNOO
 
 ,C<GMinn$0AGMi+++<SMGM%
5'9I&JKK) ", >>%%g..r   c                    U R                  5       nU R                  n[        X#U R                  5       U R                  U R
                  U5      nU$ )ab  
Convert a column holding one of the primitive dtypes to a PyArrow array.
A primitive type is one of: int, uint, float, bool (1 bit).

Parameters
----------
col : ColumnObject
allow_copy : bool, default: True
    Whether to allow copying the memory to perform the conversion
    (if false then zero-copy approach is requested).

Returns
-------
pa.Array
)get_buffersr*   buffers_to_arraysizedescribe_nulloffset)r9   r   buffers	data_typedatas        r   r0   r0      sH    & ooG		IGHHJ--JJ&	(D
 Kr   c                D   U R                  5       nUS   S   S   nUS:X  a  U(       d  [        S5      eU R                  n[        X$U R	                  5       U R
                  U R                  5      nUS:X  a*  [        R                  " U[        R                  " 5       5      nU$ )a  
Convert a column holding boolean dtype to a PyArrow array.

Parameters
----------
col : ColumnObject
allow_copy : bool, default: True
    Whether to allow copying the memory to perform the conversion
    (if false then zero-copy approach is requested).

Returns
-------
pa.Array
rB   r   r
   zfBoolean column will be casted from uint8 and a copy is required which is forbidden by allow_copy=False)r;   RuntimeErrorr*   r<   r=   r>   r?   pccastr   bool_)r9   r   r@   r=   rA   rB   s         r   r2   r2      s    $ ooG6?1a D qyA
 	

 		IGHHJ--JJ(D qywwtRXXZ(Kr   c                X   U(       d  [        S5      eU R                  nUS   (       d  [        S5      eUS   n[        U5      nU R	                  5       nUS   u  pg[        XWU R                  5       U R                  U R                  5      n[        R                  R                  X5      n	U	$ )a*  
Convert a column holding categorical data to a pa.DictionaryArray.

Parameters
----------
col : ColumnObject
allow_copy : bool, default: True
    Whether to allow copying the memory to perform the conversion
    (if false then zero-copy approach is requested).

Returns
-------
pa.DictionaryArray
zjCategorical column will be casted from uint8 and a copy is required which is forbidden by allow_copy=Falseis_dictionaryz-Non-dictionary categoricals not supported yet
categoriesrB   )rD   describe_categoricalr5   r0   r;   r<   r=   r>   r?   r   DictionaryArrayfrom_arrays)
r9   r   categorical
cat_column
dictionaryr@   _rA   indices
dict_arrays
             r   r4   r4     s    $ A
 	

 **K'!;= 	= \*J ,J ooG6?LAw"xxz"00"zz+G ##//DJr   c                    [         R                  " SU 5      nU(       a/  UR                  S5      UR                  S5      p2US:w  a  US-  nX#4$ [        SU  35      e)z4Parse datetime `format_str` to interpret the `data`.zts([smun]):(.*)r      sz DateTime kind is not supported: )rematchgroupr5   )
format_strtimestamp_metaunittzs       r   parse_datetime_format_strr^   5  sa     XX0*=N!''*N,@,@,Cb3; CKDx
 @M
NNr   c                    U u  pp4U[         R                  :X  a!  [        U5      u  pV[        R                  " XVS9$ [
        R                  U0 5      R                  US5      nU(       a  U$ [        SU  S35      e)z+Map column date type to pyarrow date type. )r]   NzConversion for  is not yet supported.)r   r/   r^   r   	timestampr   getr5   )rA   kind	bit_widthf_stringrQ   r\   r]   pa_dtypes           r   map_date_typerg   G  sz    #, DXy!!!,X6||D(("&&tR044YE O%!),BCE Er   c                   U S   u  pg U S   u  p U S   u  p[        R                  " UR                  UR                  US9nU(       a  [        UW	UUUU5      nO[        UUUUUU5      n[        U5      nU
(       a  Wu  p  n[        R                  " U
R                  U
R                  U
S9nUS   S:X  a  [        R                  " 5       nO1US:X  a  [        R                  " 5       nO[        R                  " 5       n[        R                  R                  UUUUU/US	9nU$ [        R                  R                  UUX/US	9nU$ ! [          a    Sn GNCf = f! [          a    Sn
 GNNf = f)
a  
Build a PyArrow array from the passed buffer.

Parameters
----------
buffer : ColumnBuffers
    Dictionary containing tuples of underlying buffers and
    their associated dtype.
data_type : Tuple[DtypeKind, int, str, str],
    Dtype description of the column as a tuple ``(kind, bit-width, format string,
    endianness)``.
length : int
    The number of values in the array.
describe_null: ColumnNullType
    Null representation the column dtype uses,
    as a tuple ``(kind, value)``
offset : int, default: 0
    Number of elements to offset from the start of the buffer.
allow_copy : bool, default: True
    Whether to allow copying the memory to perform the conversion
    (if false then zero-copy approach is requested).

Returns
-------
pa.Array

Notes
-----
The returned array doesn't own the memory. The caller of this function
is responsible for keeping the memory owner object alive as long as
the returned PyArrow array is being used.
rB   validityNoffsetsbaserU   Ur   r?   )	TypeErrorr   foreign_bufferptrbufsizevalidity_buffer_from_maskvalidity_buffer_nan_sentinelrg   large_stringstringArrayfrom_buffers)r@   rA   lengthr>   r?   r   	data_buffrQ   validity_buffvalidity_dtypeoffset_buffoffset_dtypedata_pa_buffervalidity_pa_buff
data_dtypeoffset_bit_widthoffset_pa_bufferstring_typearrays                      r   r<   r<   Y  s   P 6?LI(/
(;%$+I$6!
 &&y}}i6G6G,57N 4]5C5B5;5;5?A 88A8E8>8>8BD y)J$0!Q ,,[__-8-@-@2=? Q<3//+K2% oo/ iik%%/@	 & 
 L %%.	 & 
 Lw    s"   E E EEE'&E'c                   Uu  pgUu  n    n	U[         R                  :X  d   eU[        R                  :X  a  gU[        R                  :X  d  U[        R
                  :X  Ga  US:X  Ga  [        R                  " U R                  U R                  U S9n
U[        R                  :X  ar  U(       d  [        S5      e[        R                  R                  [        R                  " 5       USU
/US9n[        R                  " U[        R                   " 5       5      nO5[        R                  R                  [        R                   " 5       USU
/US9nUS:X  a  [        R"                  " U5      nUR%                  5       S   $ U[        R
                  :X  a0  US:X  a*  [        R                  " U R                  U R                  U S9$ ['        U S35      e)a  
Build a PyArrow buffer from the passed mask buffer.

Parameters
----------
validity_buff : BufferObject
    Tuple of underlying validity buffer and associated dtype.
validity_dtype : Dtype
    Dtype description as a tuple ``(kind, bit-width, format string,
    endianness)``.
describe_null : ColumnNullType
    Null representation the column dtype uses,
    as a tuple ``(kind, value)``
length : int
    The number of values in the array.
offset : int, default: 0
    Number of elements to offset from the start of the buffer.
allow_copy : bool, default: True
    Whether to allow copying the memory to perform the conversion
    (if false then zero-copy approach is requested).

Returns
-------
pa.Buffer
Nr   rk   YTo create a bitmask a copy of the data is required which is forbidden by allow_copy=Falsern   r   * null representation is not yet supported.)r   r1   r   NON_NULLABLEUSE_BYTEMASKUSE_BITMASKr   rp   rq   rr   rD   rw   rx   int8rE   rF   rG   invertr@   r5   )r{   r|   r>   ry   r?   r   	null_kindsentinel_valvalidity_kindrQ   buffmask	mask_bools                r   rs   rs     s   B ,I+M1aINN***N/// 	n11	1^///LA4E  !2!2!.!6!6&35 333"F  88((F*.06 ) 8D bhhj1I--bhhj&/3Tl5; . =I 1		),I  "1%%	n00	0\Q5F  !2!2!.!6!6&35 	5 "oGHJ 	Jr   c                <   Uu  pg  n[        U5      n	Uu  pU
[        R                  :X  a  U(       d  [        S5      eU[        R
                  :X  a  US:X  a  [        U SU
 S35      e[        R                  R                  U	USU /US9n[        R                  " U5      n[        R                  " U5      nUR                  5       S   $ U
[        R                  :X  a  U(       d  [        S5      eU[        R                  :X  a  [        R                   " 5       nOU	n[        R                  R                  UUSU /US9n[        R"                  " X5      n[        R                  " U5      nUR                  5       S   $ U
[        R$                  :X  a  g[        U S35      e)	a  
Build a PyArrow buffer from NaN or sentinel values.

Parameters
----------
data_pa_buffer : pa.Buffer
    PyArrow buffer for the column data.
data_type : Dtype
    Dtype description as a tuple ``(kind, bit-width, format string,
    endianness)``.
describe_null : ColumnNullType
    Null representation the column dtype uses,
    as a tuple ``(kind, value)``
length : int
    The number of values in the array.
offset : int, default: 0
    Number of elements to offset from the start of the buffer.
allow_copy : bool, default: True
    Whether to allow copying the memory to perform the conversion
    (if false then zero-copy approach is requested).

Returns
-------
pa.Buffer
r   r   z with r`   Nrn   r   r   )rg   r   USE_NANrD   r   r-   r5   r   rw   rx   rE   is_nanr   r@   USE_SENTINELr/   int64equalr   )r   rA   r>   ry   r?   r   rc   rd   rQ   r   r   r   pyarrow_datar   sentinel_dtypesentinel_arrr   s                    r   rt   rt     s   B &DQy)J+I N***B 
 9??"yB &+VI;.DEG G 8800~&	 1 L 99\*D99T?D<<>!$$ 
n11	1B 
 9%%%XXZN'Nxx,,^-3.2N-C4: - < xx;IIl+	  "1%%	n11	1!oGHJ 	Jr   )T)r   DataFrameObjectreturnzpa.Table)r   r   )r   r   r   boolr   zpa.RecordBatch)r9   ColumnObjectr   r   r   pa.Array)r9   r   r   r   r   zpa.DictionaryArray)r   T)r@   r   rA   zTuple[DtypeKind, int, str, str]ry   intr>   r   r?   r   r   r   r   r   )r{   BufferObjectr|   r	   r>   r   ry   r   r?   r   r   r   r   	pa.Buffer)r   r   rA   r	   r>   r   ry   r   r?   r   r   r   r   r   )2
__future__r   typingr   r   pyarrow.interchange.columnr   r   r   pyarrowr   rW   pyarrow.computecomputerE   r	   r   r   r   r+   r   int16int32r   r,   uint8uint16uint32uint64r-   float16float32float64r1   rG   r.   rv   r   __annotations__r   r   r!   r0   r2   r4   r^   rg   r<   rs   rt    r   r   <module>r      s  $ #
   	  ,
  MMrwwy


$ NN
& OO"**,**,**,( NN

$q"))+&40 $32l*> ,/,/,/ ,/b 	 > $	$$ $R -	-- -`O$E. ff.f f "	f
 f f f\ LJLJLJ "LJ 	LJ
 LJ LJ LJh UJ UJUJ "UJ 	UJ
 UJ UJ UJr   