
    q-Ph                        d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dl
mZ erd dlmZ d d	lmZ d dlmZ  G d
 de          ZdS )    )annotations)Sequence)
accumulate)TYPE_CHECKING)PolarsColumn)CopyNotAllowedError)	DataFrame)Iterator)Anyc                      e Zd ZdZdZddd,dZ	 	 d-d.dZed/d            Zd0dZ	d0dZ
d0dZd1dZd2dZd3dZd4dZd5d!Zd6d$Zd7d8d)Zd9d+Zd%S ):PolarsDataFramea9  
    A dataframe object backed by a Polars DataFrame.

    Parameters
    ----------
    df
        The Polars DataFrame backing the dataframe object.
    allow_copy
        Allow data to be copied during operations on this column. If set to `False`,
        a RuntimeError is raised if data would be copied.
    r   T
allow_copydfr	   r   boolreturnNonec               "    || _         || _        d S N)_df_allow_copy)selfr   r   s      \/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/polars/interchange/dataframe.py__init__zPolarsDataFrame.__init__!   s    %    Fnan_as_nullc                T    |rd}t          |          t          | j        |          S )a[  
        Construct a new dataframe object, potentially changing the parameters.

        Parameters
        ----------
        nan_as_null
            Overwrite null values in the data with `NaN`.

            .. warning::
                This functionality has not been implemented and the parameter will be
                removed in a future version.
                Setting this to `True` will raise a `NotImplementedError`.
        allow_copy
            Allow memory to be copied to perform the conversion. If set to `False`,
            causes conversions that are not zero-copy to fail.
        zfunctionality for `nan_as_null` has not been implemented and the parameter will be removed in a future version

Use the default `nan_as_null=False`.r   )NotImplementedErrorr   r   )r   r   r   msgs       r   __dataframe__zPolarsDataFrame.__dataframe__%   s;    *  	+; 
 &c***txJ????r   dict[str, Any]c                    i S )zThe metadata for the dataframe. r   s    r   metadatazPolarsDataFrame.metadataC   s	     	r   intc                    | j         j        S )z.Return the number of columns in the dataframe.)r   widthr$   s    r   num_columnszPolarsDataFrame.num_columnsH   s    x~r   c                    | j         j        S )z+Return the number of rows in the dataframe.)r   heightr$   s    r   num_rowszPolarsDataFrame.num_rowsL   s    xr   c                6    | j                             d          S )aQ  
        Return the number of chunks the dataframe consists of.

        It is possible for a Polars DataFrame to consist of columns with a varying
        number of chunks. This method returns the number of chunks of the first
        column.

        See Also
        --------
        polars.dataframe.frame.DataFrame.n_chunks
        first)r   n_chunksr$   s    r   
num_chunkszPolarsDataFrame.num_chunksP   s     x  )))r   	list[str]c                    | j         j        S )zReturn the column names.)r   columnsr$   s    r   column_nameszPolarsDataFrame.column_names^   s    xr   ir   c                b    | j                             |          }t          || j                  S )z
        Return the column at the indicated position.

        Parameters
        ----------
        i
            Index of the column.
        r   )r   	to_seriesr   r   )r   r5   ss      r   
get_columnzPolarsDataFrame.get_columnb   s/     Hq!!A$*:;;;;r   namestrc                b    | j                             |          }t          || j                  S )z
        Return the column with the given name.

        Parameters
        ----------
        name
            Name of the column.
        r   )r   r9   r   r   )r   r:   r8   s      r   get_column_by_namez"PolarsDataFrame.get_column_by_namen   s/     H%%A$*:;;;;r   Iterator[PolarsColumn]c              #  r   K   | j                                         D ]}t          || j                  V  dS )z(Return an iterator yielding the columns.r   N)r   get_columnsr   r   )r   columns     r   r@   zPolarsDataFrame.get_columnsz   sP      h**,, 	D 	DFv$2BCCCCCCC	D 	Dr   indicesSequence[int]c                    t          |t                    sd}t          |          t          |t                    st          |          }t	          | j        dd|f         | j                  S )z
        Create a new dataframe by selecting a subset of columns by index.

        Parameters
        ----------
        indices
            Column indices
        z`indices` is not a sequenceNr   )
isinstancer   	TypeErrorlistr   r   r   )r   rB   r   s      r   select_columnszPolarsDataFrame.select_columns   ss     '8,, 	!/CC.. '4(( 	$7mmGHQQQZ '
 
 
 	
r   namesSequence[str]c                    t          |t                    sd}t          |          t          | j                            |          | j                  S )z
        Create a new dataframe by selecting a subset of columns by name.

        Parameters
        ----------
        names
            Column names.
        z`names` is not a sequencer   )rE   r   rF   r   r   selectr   )r   rI   r   s      r   select_columns_by_namez&PolarsDataFrame.select_columns_by_name   sU     %** 	!-CC.. HOOE""'
 
 
 	
r   Nr/   
int | NoneIterator[PolarsDataFrame]c              #    K   |                                  }|                                 }|||k    r|D ]}t          || j                  V  dS |dk    s	||z  dk    rd| d}t	          |          ||z  }|D ]b}t          |          }||z  }||z  dk    r|dz  }t          d||z  |          D ])}	t          ||	|	|z   ddf         | j                  V  *cdS )a{  
        Return an iterator yielding the chunks of the dataframe.

        Parameters
        ----------
        n_chunks
            The number of chunks to return. Must be a multiple of the number of chunks
            in the dataframe. If set to `None` (default), returns all chunks.

        Notes
        -----
        When the columns in the dataframe are chunked unevenly, or when `n_chunks` is
        higher than the number of chunks in the dataframe, a slice must be performed
        that is not on the chunk boundary. This will trigger some compute for columns
        that contain null values and boolean columns.
        Nr   r   zI`n_chunks` must be a multiple of the number of chunks of this dataframe ()   )r0   _get_chunks_from_col_chunksr   r   
ValueErrorlenrange)
r   r/   total_n_chunkschunkschunkr   subchunks_per_chunksizestepstarts
             r   
get_chunkszPolarsDataFrame.get_chunks   sz     " **1133(n"<"< J J%e8HIIIIIIIJ J !mmN!:a!?!?1-1 1 1  S//! #+n"< 	 	5zz22--22AID"1d-@&@$GG  E)eedl2AAA56#'#3      	 	r   Iterator[DataFrame]c              #    K   |                      d                                          }d |D             }dgt          t          |                    z   }t	          t          |          dz
            D ]}|||dz            \  }}| j        ||ddf         }t          d |                    d          D                       s,| j	        sd}t          |          |                                }|V  dS )	z
        Return chunks of this dataframe according to the chunks of the first column.

        If columns are not all chunked identically, they will be rechunked like the
        first column. If copy is not allowed, this raises a RuntimeError.
        r   c                6    g | ]}|                                 S r#   )r[   ).0rY   s     r   
<listcomp>z?PolarsDataFrame._get_chunks_from_col_chunks.<locals>.<listcomp>   s     <<<uzz||<<<r   rR      Nc              3  "   K   | ]
}|d k    V  dS )rR   Nr#   )rb   xs     r   	<genexpr>z>PolarsDataFrame._get_chunks_from_col_chunks.<locals>.<genexpr>   s&      ==!qAv======r   allz*unevenly chunked columns must be rechunked)r9   r^   rG   r   rV   rU   r   rh   r/   r   r   rechunk)	r   
col_chunkschunk_sizesstartsr5   r]   endrY   r   s	            r   rS   z+PolarsDataFrame._get_chunks_from_col_chunks   s      __Q''2244
<<<<<tJ{33444s6{{Q'' 
	 
	AAE	*JE3HU3Y\*E==u~~e'<'<===== (' 3FC-c222KKKK
	 
	r   )r   r	   r   r   r   r   )FT)r   r   r   r   r   r   )r   r!   )r   r&   )r   r1   )r5   r&   r   r   )r:   r;   r   r   )r   r>   )rB   rC   r   r   )rI   rJ   r   r   r   )r/   rN   r   rO   )r   r_   )__name__
__module____qualname____doc__versionr   r    propertyr%   r)   r,   r0   r4   r9   r=   r@   rH   rM   r^   rS   r#   r   r   r   r      sr       
 
 G<@ & & & & & & "@ @ @ @ @<    X      * * * *       
< 
< 
< 
<
< 
< 
< 
<D D D D

 
 
 
(
 
 
 
$* * * * *X     r   r   N)
__future__r   collections.abcr   	itertoolsr   typingr   polars.interchange.columnr   polars.interchange.protocolr   r	   InterchangeDataFramer
   r   polarsr   r#   r   r   <module>r|      s    " " " " " " $ $ $ $ $ $                         2 2 2 2 2 2 ; ; ; ; ; ; I I I I I I !((((((      T T T T T* T T T T Tr   