o
    d!                     @  sp   d dl mZ d dlmZ d dlmZ d dlmZ d dlZ	d dlm
Z
 d dlmZ d dlmZ G d	d
 d
eZdS )    )annotations)
ReadBuffer)import_optional_dependency)
is_integerN)	DataFrame)_arrow_dtype_mapping)
ParserBasec                      sH   e Zd ZdZd fddZdd	 Zdd
dZdddZdddZ  Z	S )ArrowParserWrapperz7
    Wrapper for the pyarrow engine for read_csv()
    srcReadBuffer[bytes]returnNonec                   s$   t  | || _|| _|   d S )N)super__init__kwdsr
   _parse_kwds)selfr
   r   	__class__ k/var/www/html/visualizacion-main/env/lib/python3.10/site-packages/pandas/io/parsers/arrow_parser_wrapper.pyr      s   zArrowParserWrapper.__init__c                 C  sf   | j d}|du rdn|| _| | j d \| _| _| j d }t|tr)tdt	| j d | _
dS )z?
        Validates keywords before passing to pyarrow.
        encodingNzutf-8usecols	na_valuesz?The pyarrow engine doesn't support passing a dict for na_values)r   getr   _validate_usecols_argr   usecols_dtype
isinstancedict
ValueErrorlistr   )r   r   r   r   r   r   r      s   

zArrowParserWrapper._parse_kwdsc                 C  s   dddddd}|  D ]\}}|| jv r&| j|dur&| j|| j|< qdd	 | j  D | _d
d	 | j  D | _| jdu | jdurI| jn| jd | jd| _dS )z:
        Rename some arguments to pass to pyarrow
        include_columnsnull_valuesescape_charignore_empty_linesdecimal_point)r   r   
escapecharskip_blank_linesdecimalNc                 S  &   i | ]\}}|d ur|dv r||qS )N)	delimiter
quote_charr#   r$   r   .0option_nameoption_valuer   r   r   
<dictcomp>;       z;ArrowParserWrapper._get_pyarrow_options.<locals>.<dictcomp>c                 S  r)   )N)r!   r"   true_valuesfalse_valuesr%   r   r,   r   r   r   r0   B   r1   skiprows)autogenerate_column_names	skip_rowsr   )	itemsr   r   popparse_optionsconvert_optionsheaderr   read_options)r   mappingpandas_namepyarrow_namer   r   r   _get_pyarrow_options,   s,   z'ArrowParserWrapper._get_pyarrow_optionsframer   c              
   C  sX  t |j}d}| jdu r7| jdu r| jdu rt|| _t | j|kr3tt|t | j | j | _d}| j|_| |j|\|_}| jdurt| jD ]\}}t	|r\|j| | j|< qK||jvrit
d| dqK|j| jddd | jdu r|sdgt |jj |j_| jddurz|| jd}W |S  ty } zt
|d}~ww |S )z
        Processes data read in based on kwargs.

        Parameters
        ----------
        frame: DataFrame
            The DataFrame to process.

        Returns
        -------
        DataFrame
            The processed DataFrame.
        TNFzIndex z invalid)dropinplacedtype)lencolumnsr;   namesranger    _do_date_conversions	index_col	enumerater   r   	set_indexindexr   r   astype	TypeError)r   rA   num_colsmulti_index_namediitemer   r   r   _finalize_pandas_outputW   s<   






z*ArrowParserWrapper._finalize_pandas_outputc                 C  s   t d}|   |j| j|jdi | j|jdi | j|jdi | j	d}| j
d dkr6|jtjd}n| j
d dkrF|jt jd}n| }| |S )	z
        Reads the contents of a CSV file into a DataFrame and
        processes it according to the kwargs passed in the
        constructor.

        Returns
        -------
        DataFrame
            The DataFrame created from the CSV file.
        zpyarrow.csv)r<   r9   r:   dtype_backendpyarrow)types_mappernumpy_nullableNr   )r   r@   read_csvr
   ReadOptionsr<   ParseOptionsr9   ConvertOptionsr:   r   	to_pandaspd
ArrowDtyper   r   rU   )r   pyarrow_csvtablerA   r   r   r   read   s   
zArrowParserWrapper.read)r
   r   r   r   )r   r   )rA   r   r   r   )r   r   )
__name__
__module____qualname____doc__r   r   r@   rU   rc   __classcell__r   r   r   r   r	      s    

+3r	   )
__future__r   pandas._typingr   pandas.compat._optionalr   pandas.core.dtypes.inferencer   pandasr_   r   pandas.io._utilr   pandas.io.parsers.base_parserr   r	   r   r   r   r   <module>   s    