
    'hk                        S SK Jr  S SKJr  S SKJrJrJrJr  S SK	J
r
  S SKJrJrJrJrJr  S SKJr  \(       a  S SKJr  S SKJr  S S	KJr  S S
KJrJrJr   " S S\5      rg)    )annotations)TYPE_CHECKING)BooleanCategoricalEnumString)PolarsBuffer)ColumnColumnNullTypeCopyNotAllowedError	DtypeKind
Endianness)polars_dtype_to_dtype)Iterator)Any)Series)CategoricalDescriptionColumnBuffersDtypec                      \ rS rSrSrSS.SS jjrSS jr\SS j5       r\SS j5       r	\SS	 j5       r
\SS
 j5       r\SS j5       r\SS j5       rSS jrSSS jjrSS jrSS jr    SS jr    SS jrSrg) PolarsColumn   a  
A column object backed by a Polars Series.

Parameters
----------
column
    The Polars Series backing the column object.
allow_copy
    Allow data to be copied during operations on this column. If set to `False`,
    a RuntimeError will be raised if data would be copied.
T
allow_copyc                   Xl         X l        g N)_col_allow_copy)selfcolumnr   s      lC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\polars/interchange/column.py__init__PolarsColumn.__init__%   s    	%    c                6    U R                   R                  5       $ )zSize of the column in elements.)r   lenr   s    r!   sizePolarsColumn.size)   s    yy}}r$   c                z    U R                   R                  [        :X  a  U R                   R                  5       S   $ g)zOOffset of the first element with respect to the start of the underlying buffer.   r   )r   dtyper   _get_buffer_infor'   s    r!   offsetPolarsColumn.offset-   s/     99??g%99--/22r$   c                D    U R                   R                  n[        U5      $ )zData type of the column.)r   r,   r   )r   pl_dtypes     r!   r,   PolarsColumn.dtype5   s     99??$X..r$   c                
   U R                   R                  nU[        :X  a'  U R                   R                  R	                  5       nSnO&U[
        :X  a  UR                  nSnOSn[        U5      eUS[        X R                  S9S.$ )z
Description of the categorical data type of the column.

Raises
------
TypeError
    If the data type of the column is not categorical.
FTz8`describe_categorical` only works on categorical columnsr   )
is_orderedis_dictionary
categories)
r   r,   r   catget_categoriesr   r6   	TypeErrorr   r   )r   r,   r6   r4   msgs        r!   describe_categorical!PolarsColumn.describe_categorical;   sz     		K557JJd]))JJLCC.  %!&z>N>NO
 	
r$   c                j    U R                   S:X  a  [        R                  S4$ [        R                  S4$ )z7Description of the null representation the column uses.r   N)
null_countr   NON_NULLABLEUSE_BITMASKr'   s    r!   describe_nullPolarsColumn.describe_nullV   s2     ??a!..44!--q00r$   c                6    U R                   R                  5       $ )zThe number of null elements.)r   r>   r'   s    r!   r>   PolarsColumn.null_count^   s     yy##%%r$   c                    0 $ )zThe metadata for the column. r'   s    r!   metadataPolarsColumn.metadatac   s	     	r$   c                6    U R                   R                  5       $ )z3Return the number of chunks the column consists of.)r   n_chunksr'   s    r!   
num_chunksPolarsColumn.num_chunksh   s    yy!!##r$   Nc              #    #    U R                  5       nU R                  R                  5       nUb  X:X  a  U H  n[        X@R                  S9v   M     gUS::  d  X-  S:w  a  SU S3n[        U5      eX-  nU HO  n[        U5      nXv-  nXv-  S:w  a  US-  n[        SX-  U5       H  n	[        XIX-    U R                  S9v   M     MQ     g7f)a  
Return an iterator yielding the column chunks.

Parameters
----------
n_chunks
    The number of chunks to return. Must be a multiple of the number of chunks
    in the column.

Notes
-----
When `n_chunks` is higher than the number of chunks in the column, a slice
must be performed that is not on the chunk boundary. This will trigger some
compute if the column contains null values or if the column is of data type
boolean.
Nr   r   zF`n_chunks` must be a multiple of the number of chunks of this column ()r+   )rK   r   
get_chunksr   r   
ValueErrorr&   range)
r   rJ   total_n_chunkschunkschunkr:   subchunks_per_chunkr(   stepstarts
             r!   rO   PolarsColumn.get_chunksl   s     " *%%'("<"55E5EFF   !m!:a!?#$A'  S/! #+"<5z2-2AID"1d&@$GE&el3@P@P  H  s   CCc                *   U R                   R                  nU[        :X  a  U R                  (       d  Sn[	        U5      eU R                   R                  5       nU R                  US   5      U R                  US   5      U R                  US   5      S.$ )z6Return a dictionary containing the underlying buffers.z string buffers must be convertedvaluesvalidityoffsets)datar[   r\   )	r   r,   r   r   r   _get_buffers_wrap_data_buffer_wrap_validity_buffer_wrap_offsets_buffer)r   r,   r:   bufferss       r!   get_buffersPolarsColumn.get_buffers   s    		F?4#3#34C%c**))((* **78+<=227:3FG001CD
 	
r$   c                X    [        XR                  S9n[        UR                  5      nX#4$ )Nr   )r	   r   r   r,   r   bufferinterchange_bufferr,   s       r!   r_   PolarsColumn._wrap_data_buffer   s*    )&=M=MN%fll3!((r$   c                z    Uc  g [        XR                  S9n[        R                  SS[        R
                  4nX#4$ )Nr   r+   b)r	   r   r   BOOLr   NATIVErf   s       r!   r`   "PolarsColumn._wrap_validity_buffer   s>     >)&=M=MNC):):;!((r$   c                z    Uc  g [        XR                  S9n[        R                  SS[        R
                  4nX#4$ )Nr   @   l)r	   r   r   INTr   rm   rf   s       r!   ra   !PolarsColumn._wrap_offsets_buffer   s>     >)&=M=MNC):):;!((r$   )r   r   )r    r   r   boolreturnNone)ru   int)ru   r   )ru   r   )ru   z!tuple[ColumnNullType, int | None])ru   zdict[str, Any]r   )rJ   z
int | Noneru   zIterator[PolarsColumn])ru   r   )rg   r   ru   ztuple[PolarsBuffer, Dtype])rg   zSeries | Noneru   z!tuple[PolarsBuffer, Dtype] | None)__name__
__module____qualname____firstlineno____doc__r"   r(   propertyr.   r,   r;   rA   r>   rG   rK   rO   rc   r_   r`   ra   __static_attributes__rF   r$   r!   r   r      s    
 >B &   / /
 
 
4 1 1 & &  $)V
 )
)#)	*))#)	*)r$   r   N)
__future__r   typingr   polars.datatypesr   r   r   r   polars.interchange.bufferr	   polars.interchange.protocolr
   r   r   r   r   polars.interchange.utilsr   collections.abcr   r   polarsr   r   r   r   r   rF   r$   r!   <module>r      sC    "   ? ? 2  ;(XXf)6 f)r$   