a
    Of#                  &   @  s  d dl mZ d dlmZ d dlmZ d dlZd dlZd dlmZ d dl	Z	d dl
mZmZmZmZmZmZ d dlZd dlZd dlmZmZ d dlm  mZ d dlmZ d d	lmZ d d
lm Z  d dl!m"Z"m#Z# d dl$m%Z% d dl&m'Z' d dl(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4 d dl5m6Z6m7Z7 d dl8m9Z9 d dl:m;Z;m<Z<m=Z=m>Z>m?Z? d dl@mAZA d dlBmCZCmDZDmEZEmFZFmGZGmHZHmIZI d dlJmKZK d dlLmMZMmNZNmOZOmPZP d dlQmRZR d dlSmTZU d dlVmWZW erd dlXmYZYmZZZm[Z[m\Z\ d dl]m^Z^m_Z_m`Z`maZa G dd dZbejcdddfddd d!d"d#Zdddd$ejedddd%dddd ddddddddddd&dddejcdddddddd'ebjfjgejcd(%Zhdejcfd)dd*d+d,Zid9d)d-d.d/d0Zjdd1d2d3Zkd4d5 Zldd6d7d8ZmdS ):    )annotations)defaultdictcopyN)Enum)TYPE_CHECKINGAnyCallablecastfinaloverload)libparsers)STR_NA_VALUES)parsing)import_optional_dependency)ParserErrorParserWarning)find_stack_level)astype_array)ensure_objectis_bool_dtypeis_dict_likeis_extension_array_dtypeis_float_dtype
is_integeris_integer_dtypeis_list_likeis_object_dtype	is_scalaris_string_dtypepandas_dtype)CategoricalDtypeExtensionDtype)isna)
ArrowDtype	DataFrameDatetimeIndexStringDtypeconcat)
algorithms)ArrowExtensionArrayBaseMaskedArrayBooleanArrayCategoricalExtensionArrayFloatingArrayIntegerArray)BooleanDtype)Index
MultiIndexdefault_indexensure_index_from_sequencesSeries)	datetimes)is_potential_multi_index)HashableIterableMappingSequence)	ArrayLikeDtypeArgDtypeObjScalarc                   @  sb  e Zd ZU G dd deZded< ded< ded< ded< ded< ded	< d
ed< ddddZdddddZddddZe	e
ddddZe	dddddZe	dpdddd d!d"Ze	dqddd$d%d&d'Ze	drd(d)d*d+d,Ze	d-d. Ze	d/d0 Ze	d1d2 Ze	dsdd4d5d6d7Ze	dtd8dd9d:d;Ze	d<dd=d>d?d@Ze	duddAdBdCdDZe	dEdFdEdGdHdIZed4dJdKdLdMdNZeddOdPdLdQdNZe	dRdSdTdLdUdNZe	ddVddWdXdYZedZdd=d[d\d]Zed^dd^d[d_d]Ze	d`ddad[dbd]Ze	dcdddedfZe	dgdh Ze	diddjdkZe	dvdldmdndoZd#S )w
ParserBasec                   @  s   e Zd ZdZdZdZdS )zParserBase.BadLineHandleMethodr         N)__name__
__module____qualname__ERRORWARNZSKIP rK   rK   V/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pandas/io/parsers/base_parser.pyBadLineHandleMethodf   s   rM   bool_implicit_index_first_chunkkeep_default_nadayfirstcache_dateskeep_date_col
str | Noneusecols_dtypeNonereturnc                 C  s  d| _ |d| _d | _|dd | _t | _d | _d | _t	|
dd| _g | _|
dtj| _|
dd | _|
dd| _|
dd| _|d	| _|d
| _|dd| _|dd| _t|dd | _|d| _|d| _|d| _|d| _|
dd| _t| j| j| j| jd| _|d| _ t!| j ddr|drZt"d|drnt"d| jd urt#| jr| jg| _n8t!| jddrt$t%t#| jst"dnt&| j| _d| _'d| _(| )|d \| _*| _+|d| j,j-| _.d S )NFnames	index_colparse_datesdate_parserdate_formatrR   rT   	na_values
na_fvalues	na_filterrQ   Tdtype
convertersdtype_backendtrue_valuesfalse_valuesrS   )r]   r^   rR   rS   header)Z
allow_setsusecolsz;cannot specify usecols when specifying a multi-index headerz9cannot specify names when specifying a multi-index headerzLindex_col must only contain row numbers when specifying a multi-index headeron_bad_lines)/rO   getrZ   
orig_namesr[   setunnamed_colsindex_names	col_names_validate_parse_dates_argpopr\   _parse_date_colsr   
no_defaultr]   r^   rR   rT   r_   r`   ra   rQ   r   rb   rc   rd   re   rf   rS   _make_date_converter
_date_convrg   r   
ValueErrorr   allmaplist_name_processedrP   _validate_usecols_argrh   rV   rM   rI   ri   )selfkwdsrK   rK   rL   __init__s   sl    zParserBase.__init__zSequence[Hashable]r<   )columnsrY   c                   s   t | jrtj| j  }n(t| jr@tjdd | jD }ng }t|}dt	 fdd|D }|r|t
d| d fdd	|D S )
a  
        Check if parse_dates are in columns.

        If user has provided names for parse_dates, check if those columns
        are available.

        Parameters
        ----------
        columns : list
            List of names of the dataframe.

        Returns
        -------
        The names of the columns which will get parsed later if a dict or list
        is given as specification.

        Raises
        ------
        ValueError
            If column to parse_date is not in dataframe.

        c                 s  s*   | ]"}t |rt|ts|n|gV  qd S N)r   
isinstancetuple.0colrK   rK   rL   	<genexpr>   s   z<ParserBase._validate_parse_dates_presence.<locals>.<genexpr>z, c                   s"   h | ]}t |tr| vr|qS rK   r   strr   r   rK   rL   	<setcomp>   s   z<ParserBase._validate_parse_dates_presence.<locals>.<setcomp>z+Missing column provided to 'parse_dates': ''c                   s*   g | ]"}t |ts| v r|n | qS rK   r   r   r   rK   rL   
<listcomp>   s   z=ParserBase._validate_parse_dates_presence.<locals>.<listcomp>)r   r\   	itertoolschainvaluesr   from_iterablery   joinsortedrv   )r|   r   Zcols_neededZmissing_colsrK   r   rL   _validate_parse_dates_presence   s,    



	

z)ParserBase._validate_parse_dates_presencec                 C  s   d S r   rK   r|   rK   rK   rL   close   s    zParserBase.closec                 C  s6   t | jtp4t | jto4t| jdko4t | jd tS )Nr   )r   r\   dictry   lenr   rK   rK   rL   _has_complex_date_col   s    z ParserBase._has_complex_date_colint)irY   c                 C  sh   t | jrt| jS | jd ur,| j| }nd }| jd u r>|n| j| }|| jv pb|d uob|| jv S d S r   )r   is_boolr\   rN   rn   r[   )r|   r   namejrK   rK   rL   _should_parse_dates  s    


zParserBase._should_parse_datesFzSequence[Hashable] | NonezUtuple[Sequence[Hashable], Sequence[Hashable] | None, Sequence[Hashable] | None, bool])rn   passed_namesrY   c           	        s&  t |dk r|d |d|fS jdu r.g ttttjfsFgt|d}	|j\}}}t |d t
fdd|dd D stdfd	d
 tt fdd|D  }| }tD ]}||| qt rfdd|D }ndgt | }d}||||fS )a  
        Extract and return the names, index_names, col_names if the column
        names are a MultiIndex.

        Parameters
        ----------
        header: list of lists
            The header rows
        index_names: list, optional
            The names of the future index
        passed_names: bool, default False
            A flag specifying if names where passed

        rE   r   Nc                 3  s   | ]}t | kV  qd S r   )r   )r   Zheader_iter)field_countrK   rL   r   D      z<ParserBase._extract_multi_indexer_columns.<locals>.<genexpr>rD   z1Header rows must have an equal number of columns.c                   s   t  fddtD S )Nc                 3  s   | ]}|vr | V  qd S r   rK   )r   r   )rsicrK   rL   r   H  r   zMParserBase._extract_multi_indexer_columns.<locals>.extract.<locals>.<genexpr>)r   ranger   )r   r   r   rL   extractG  s    z:ParserBase._extract_multi_indexer_columns.<locals>.extractc                 3  s   | ]} |V  qd S r   rK   r   r   )r   rK   rL   r   J  r   c                   s>   g | ]6}| d   dur6| d   j vr6| d   ndqS )r   N)rm   r   )icr|   rK   rL   r   Q  s   z=ParserBase._extract_multi_indexer_columns.<locals>.<listcomp>T)r   r[   r   ry   r   npndarrayrl   rq   _clean_index_namesrw   r   zipr   r   insert)	r|   rg   rn   r   _r   rZ   Z	single_icro   rK   )r   r   r   r|   r   rL   _extract_multi_indexer_columns  s2    

z)ParserBase._extract_multi_indexer_columnsNzSequence[Hashable] | MultiIndex)r   ro   rY   c                 C  s(   t |r$ttt |}tj||dS |S )NrZ   )r:   r
   ry   r   r4   from_tuples)r|   r   ro   Zlist_columnsrK   rK   rL   _maybe_make_multi_index_columns^  s    z*ParserBase._maybe_make_multi_index_columnszlist[Scalar] | Nonez4tuple[Index | None, Sequence[Hashable] | MultiIndex])indexnamerowrY   c           
      C  s   t | jr| jsd }nf| js4| ||}| |}nH| jr|| jsb| t|| j\| _}| _d| _| 	||}| j|dd}|rt
|t
| }	|d usJ ||d |	 }| || j}||fS )NTF)try_parse_dates)is_index_colr[   r   _get_simple_index
_agg_indexrz   r   ry   rn   _get_complex_date_indexr   Z	set_namesr   ro   )
r|   dataZalldatar   r   indexZsimple_indexr   Z
date_indexZcoffsetrK   rK   rL   _make_indexj  s&    
zParserBase._make_indexc                 C  sl   dd }g }g }| j D ]$}||}|| |||  qt|ddD ]}|| | jsH|| qH|S )Nc                 S  s"   t | ts| S td|  dd S )NzIndex z invalid)r   r   rv   r   rK   rK   rL   ix  s    
z(ParserBase._get_simple_index.<locals>.ixTreverse)r[   appendr   rq   rO   )r|   r   r   r   	to_remover   idxr   rK   rK   rL   r     s    


zParserBase._get_simple_indexc           	        sj    fdd}g }g }| j D ]$}||}|| |||  qt|ddD ]}||  | qL|S )Nc                   sL   t | tr| S  d u r&td| dt D ]\}}|| kr.|  S q.d S )Nz Must supply column order to use z	 as index)r   r   rv   	enumerate)Zicolr   cro   rK   rL   	_get_name  s    
z5ParserBase._get_complex_date_index.<locals>._get_nameTr   )r[   r   r   rq   remove)	r|   r   ro   r   r   r   r   r   r   rK   r   rL   r     s    


z"ParserBase._get_complex_date_indexc                   s   t  ts S i }| jdus J   D ].\}}t |trN|| jvrN| j| }|||< q(t  trt| jt|  }| fdd|D  |S )zconverts col numbers to namesNc                   s   i | ]}| | qS rK   rK   r   mappingrK   rL   
<dictcomp>  r   z-ParserBase._clean_mapping.<locals>.<dictcomp>)	r   r   rk   itemsr   r   rl   keysupdate)r|   r   cleanr   vZremaining_colsrK   r   rL   _clean_mapping  s    



zParserBase._clean_mappingTr3   )r   rY   c                 C  sd  g }|  | j}t|D ]4\}}|rR| |rR| j|| jd urJ| j| nd d}| jrf| j}| j}nt	 }t	 }t
| jtr| jd usJ | j| }	|	d urt|	| j| j| j\}}|  | j}
d }d}| jd urt
|
tr|
| j| d }t
|tr|| j| d u}|r"t|p$| }| |||B |d u |\}}|| q| j}t||}|S )Nr   F)r   rc   r   r   ru   rn   ra   r_   r`   rl   r   r   _get_na_valuesrQ   rb   rj   r    _infer_typesr   r6   )r|   r   r   Zarraysrc   r   arrcol_na_valuescol_na_fvaluescol_nameZclean_dtypes	cast_typeZindex_convertertry_num_boolr   rZ   rK   rK   rL   r     sJ    


zParserBase._agg_indexr=   )dctverbosec              	   C  s  i }|  D ] \}}	|d u r"d n
||d }
t|trF||d }n|}| jrft|||| j\}}nt t  }}|| jv rt	
|	t||B }t|	|tj |	||< q|
d urH|d urtjd| dtt d zt|	|
}	W n: ty"   t	
|	t|tj}t|	|
|}	Y n0 | j|	t||B |d u dd\}}nt|}|p\t|}|of| }| |	t||B |d u |\}}|d urt|}|r|j|ks|r|s|dkrt|rtd| | |||}|||< |r|rt d| d	| q|S )
Nz5Both a converter and dtype were specified for column z# - only the converter will be used.
stacklevelF)r   r   z$Bool column has NA values in column zFilled z NA values in column )!r   rj   r   r   ra   r   rQ   rl   rr   r*   isinr   putmasknanwarningswarnr   r   r   Z	map_inferrv   ry   viewuint8Zmap_infer_maskr   r   r    r!   rb   r   _cast_typesprint)r|   r   r_   r`   r   rc   Zdtypesresultr   r   Zconv_fr   r   r   maskZcvalsna_countZis_eaZis_str_or_ea_dtyper   rK   rK   rL   _convert_to_ndarrays  sp    





	



zParserBase._convert_to_ndarraysz	list[int]zset[int])col_indicesrZ   rY   c                   s@  t  }| jdkrt| jnt| js0| jdvr6 nddd fdd}t| jtr| jD ]6}t|tr|D ]}||| qtqb||| qbnt| jt	r| j
 D ]6}t|tr|D ]}||| qq||| qnP| jr<t| jtr | jD ]}||| qn| jdur<||| j |S )a  
        Set the columns that should not undergo dtype conversions.

        Currently, any column that is involved with date parsing will not
        undergo such conversions. If usecols is specified, the positions of the columns
        not to cast is relative to the usecols not to all columns.

        Parameters
        ----------
        col_indices: The indices specifying order and positions of the columns
        names: The column names which order is corresponding with the order
               of col_indices

        Returns
        -------
        A set of integers containing the positions of the columns not to convert.
        integer)emptyNNr   rX   c                   s2   d urt | r|  } t | s. |  } | S r   )r   r   )xr   rZ   rh   rK   rL   _set|  s
    z5ParserBase._set_noconvert_dtype_columns.<locals>._set)rl   rV   r   rh   callabler   r\   ry   addr   r   r[   )r|   r   rZ   Znoconvert_columnsr   valkrK   r   rL   _set_noconvert_dtype_columnsY  s4    
	



z'ParserBase._set_noconvert_dtype_columnsztuple[ArrayLike, int])r   rY   c              	   C  s  d}t |jjtjtjfrtdd |D }t||}|j	ddd
 }|dkrxt|rh|	tj}t||tj ||fS | j}|o|tju}|rt|jrztj||d|d\}	}
W n& ttfy   t||}|}	Y n0 |rx|
du r
tj|	jtjd	}
|
 r.ttj|
jtjd	|
}	n@t|	rDt|	|
}	n*t|	rZt|	|
}	nt |	rnt!|	|
}	|

 }nt"|	
 }n|}	|jtj#krt||}|	jtj#krT|rTt$j%t&|| j'| j(|d
\}	}|	jtjkr|r|du rtj|	jtjd	}t|	|}	n@|	jtj#krT|rTtj)|	ddsTt* }|+ }|j,||d	}	|dkrt-d}t.|	tj/rt0|j|	dd}	n`t.|	t1r|	j2 rt0|dgt3|	 }	nt0|j|	j4|	j2d}	nt0|j|	5 dd}	|	|fS )a  
        Infer types of values, possibly casting

        Parameters
        ----------
        values : ndarray
        na_values : set
        no_dtype_specified: Specifies if we want to cast explicitly
        try_num_bool : bool, default try
           try to cast values to numeric (first preference) or boolean

        Returns
        -------
        converted : ndarray or ExtensionArray
        na_count : int
        r   c                 S  s   g | ]}t |ts|qS rK   r   )r   r   rK   rK   rL   r     r   z+ParserBase._infer_types.<locals>.<listcomp>r   Fr   )convert_to_masked_nullableNrb   )re   rf   r   Tskipnapyarrow)Zfrom_pandas)r   )6
issubclassrb   typer   numberZbool_arrayr*   r   astypesumr   Zfloat64r   r   rd   r   rs   r   Zmaybe_convert_numericrv   	TypeErrorr   Zsanitize_objectsZzerosshaperw   r1   ZonesZint64r   r-   r   r0   r$   Zobject_libopsZmaybe_convert_boolasarrayre   rf   Zis_datetime_arrayr(   construct_array_typeZ_from_sequencer   r   r   r+   r,   Z_maskr   _datato_numpy)r|   r   r_   Zno_dtype_specifiedr   r   r   rd   Znon_default_dtype_backendr   Zresult_maskZ	bool_maskrb   clsparK   rK   rL   r     s    










zParserBase._infer_typesr?   rA   )r   r   rY   c              
   C  sp  t |tr`|jdu}t|js2|s2tj|ddd}t| 	 }t
j||||| jd}nt |tr| }z6t |tr|j||| j| jdW S |j||dW S W n6 ty } ztd| d|W Y d}~n
d}~0 0 nt |tr|j|dd	}npt|jtrtj|d
dd}nPzt||d
d	}W n< tyj } z"td| d| |W Y d}~n
d}~0 0 |S )ar  
        Cast values to specified type

        Parameters
        ----------
        values : ndarray or ExtensionArray
        cast_type : np.dtype or ExtensionDtype
           dtype to cast values to
        column : string
            column name - used only for error reporting

        Returns
        -------
        converted : ndarray or ExtensionArray
        NF)r   Zconvert_na_value)re   )rb   re   rf   r   zExtension Array: zO must implement _from_sequence_of_strings in order to be used in parser methodsr   TzUnable to convert column z	 to type )r   r"   
categoriesr   rb   r   Zensure_string_arrayr3   uniqueZdropnar.   Z_from_inferred_categoriesZget_indexerre   r#   r  r2   Z_from_sequence_of_stringsrf   NotImplementedErrorr/   r   r   r   r   r   rv   )r|   r   r   columnZ
known_catsZcatsZ
array_typeerrrK   rK   rL   r     sT    






zParserBase._cast_typesr&   z,tuple[Sequence[Hashable] | Index, DataFrame])rZ   r   rY   c                 C  s   d S r   rK   r|   rZ   r   rK   rK   rL   _do_date_conversionsW  s    zParserBase._do_date_conversionszMapping[Hashable, ArrayLike]z7tuple[Sequence[Hashable], Mapping[Hashable, ArrayLike]]c                 C  s   d S r   rK   r  rK   rK   rL   r  _  s    zSequence[Hashable] | Indexz(Mapping[Hashable, ArrayLike] | DataFramezKtuple[Sequence[Hashable] | Index, Mapping[Hashable, ArrayLike] | DataFrame]c              
   C  s:   | j d ur2t|| j| j | j| j|| j| jd\}}||fS )N)rT   rd   )r\   _process_date_conversionru   r[   rn   rT   rd   r  rK   rK   rL   r  g  s    

zSequence[ArrayLike])r   r   rY   c                 C  sz   | j svt|t|krv|rvt|d o0|d dk}|t|d B }t|t|d krdt|rddS tjdtt	 d dS )ae  Checks if length of data is equal to length of column names.

        One set of trailing commas is allowed. self.index_col not False
        results in a ParserError previously when lengths do not match.

        Parameters
        ----------
        columns: list of column names
        data: list of array-likes containing the data column-wise.
        r    rD   NzkLength of header or names does not match length of data. This leads to a loss of data with index_col=False.r   )
r[   r   r   r$   r   rw   r   r   r   r   )r|   r   r   Z	empty_strZempty_str_or_narK   rK   rL   _check_data_length}  s    zParserBase._check_data_lengthz'set[int] | Callable[[Hashable], object])rh   rZ   rY   c                 C  s   d S r   rK   r|   rh   rZ   rK   rK   rL   _evaluate_usecols  s    zParserBase._evaluate_usecolszset[str]c                 C  s   d S r   rK   r  rK   rK   rL   r    s    z2Callable[[Hashable], object] | set[str] | set[int]zset[str] | set[int]c                   s"   t  r fddt|D S  S )a  
        Check whether or not the 'usecols' parameter
        is a callable.  If so, enumerates the 'names'
        parameter and returns a set of indices for
        each entry in 'names' that evaluates to True.
        If not a callable, returns 'usecols'.
        c                   s   h | ]\}} |r|qS rK   rK   )r   r   r   rh   rK   rL   r     r   z/ParserBase._evaluate_usecols.<locals>.<setcomp>)r   r   r  rK   r  rL   r    s    r>   r   c                   s0    fdd|D }t |dkr,td| |S )ai  
        Validates that all usecols are present in a given
        list of names. If not, raise a ValueError that
        shows what usecols are missing.

        Parameters
        ----------
        usecols : iterable of usecols
            The columns to validate are present in names.
        names : iterable of names
            The column names to check against.

        Returns
        -------
        usecols : iterable of usecols
            The `usecols` parameter if the validation succeeds.

        Raises
        ------
        ValueError : Columns were missing. Error message will list them.
        c                   s   g | ]}| vr|qS rK   rK   r   r   r   rK   rL   r     r   z6ParserBase._validate_usecols_names.<locals>.<listcomp>r   z>Usecols do not match columns, columns expected but not found: )r   rv   )r|   rh   rZ   missingrK   r   rL   _validate_usecols_names  s    z"ParserBase._validate_usecols_namesc                 C  sb   d}|durZt |r|dfS t|s,t|tj|dd}|dvrJt|t|}||fS |dfS )as  
        Validate the 'usecols' parameter.

        Checks whether or not the 'usecols' parameter contains all integers
        (column selection by index), strings (column by name) or is a callable.
        Raises a ValueError if that is not the case.

        Parameters
        ----------
        usecols : list-like, callable, or None
            List of columns to use when parsing or a callable that can be used
            to filter a list of table columns.

        Returns
        -------
        usecols_tuple : tuple
            A tuple of (verified_usecols, usecols_dtype).

            'verified_usecols' is either a set if an array-like is passed in or
            'usecols' if a callable or None is passed in.

            'usecols_dtype` is the inferred dtype of 'usecols' if an array-like
            is passed in or None if a callable or None is passed in.
        z['usecols' must either be list-like of all strings, all unicode, all integers or a callable.NFr   )r   r   string)r   r   rv   r   Zinfer_dtyperl   )r|   rh   msgrV   rK   rK   rL   r{     s    z ParserBase._validate_usecols_argztuple[list | None, list, list]c           	      C  s   t |sd ||fS t|}|s2d gt| ||fS t|}g }t|}t|D ]j\}}t|tr|| t|D ]&\}}||krr|||< ||  qqrqN|| }|| || qNt|D ]$\}}t|tr|| jv rd ||< q|||fS r   )	r   ry   r   r   r   r   r   r   rm   )	r|   r   r[   Zcp_colsrn   r   r   r   r   rK   rK   rL   r     s.    





zParserBase._clean_index_nameszDtypeArg | Noner   c           
        s   t   | j}| j}t|s6|p"ttfddn*tt|}tdd  fdd| D |d u sx|du sx|d u rt	d}nFfdd	|D }t
||d
}|  t|D ]\}} ||  qfdd D }	| |	fS )Nc                     s    S r   rK   rK   )default_dtyperK   rL   <lambda>@  r   z,ParserBase._get_empty_meta.<locals>.<lambda>c                   S  s   t S r   )objectrK   rK   rK   rL   r  D  r   c                   s&   i | ]\}}t |r | n||qS rK   )r   )r   r   r   r   rK   rL   r   E  r   z.ParserBase._get_empty_meta.<locals>.<dictcomp>Fr   c                   s   g | ]}t g  | d qS r   r7   )r   r   
dtype_dictrK   rL   r   U  r   z.ParserBase._get_empty_meta.<locals>.<listcomp>r   c                   s   i | ]}|t g  | d qS r  r7   )r   r   r   rK   rL   r   \  s   )ry   r[   rn   r   r  r   r
   r   r   r5   r6   sortr   rq   )
r|   r   rb   r[   rn   r   r   r   nZcol_dictrK   )r   r  r!  rL   _get_empty_meta2  s,    


zParserBase._get_empty_meta)F)N)N)T)FNN)T)N) rF   rG   rH   r   rM   __annotations__r~   r   r   r   propertyr   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r{   r   r$  rK   rK   rK   rL   rC   e   s   
L= F  


3   VD pG
1%rC   FTrN   z dict[Hashable, str] | str | None)rR   rS   r^   c                   s\   t jurtjdtt d t jur6d ur6tddd dd fdd	}|S )
NzThe argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.r   z/Cannot use both 'date_parser' and 'date_format'c                 S  s.   t | tjr*| jdkr*t| dkr*| d S | S )NrD   r   )r   r   r   ndimr   )argrK   rK   rL   unpack_if_single_elementu  s    "z6_make_date_converter.<locals>.unpack_if_single_elementr;   r   c                   sH  t |dkr$|d jjdv r$|d S tju rt|}ttrL	| n}t
 j t
jddtd t|}ztj||d d}W n( ttfy   | Y W  d    S 0 W d    n1 s0    Y  t|tr| }d	|j_|S |jS zt
 f t
jddtd fd
d|D  }ztj| d}W n ttfyV   |}Y n0 W d    n1 sn0    Y  t|tjrtd|W S  tyB   t
  t
jddtd tjt|d}zt|W W  d     Y S  ttfy   | Y W  d     Y S 0 W d    n1 s40    Y  Y n0 d S )NrD   r   ZMmignorez=.*parsing datetimes with mixed time zones will raise an error)categoryF)formatutcrR   cacheTc                 3  s   | ]} |V  qd S r   rK   )r   r(  )r)  rK   rL   r     r   z:_make_date_converter.<locals>.converter.<locals>.<genexpr>)r.  zscalar parser)parser)r   rb   kindr   rs   r   Zconcat_date_colsr   r   rj   r   catch_warningsfilterwarningsFutureWarningr   toolsto_datetimerv   r  r'   r  flagsZ	writeableZ_valuesdatetime	Exceptionr   )r   	date_colsstrsZdate_fmtZstr_objsr   r   Z
pre_parsedrS   r^   r]   rR   r)  rK   rL   	converter{  s~    



6


*
z'_make_date_converter.<locals>.converter)r   rs   r   r   r3  r   r  )r]   rR   rS   r^   r<  rK   r;  rL   rt   c  s    
Lrt   "Zinfer.strict)%	delimiter
escapechar	quotecharquotingdoublequoteskipinitialspacelineterminatorrg   r[   rZ   ZskiprowsZ
skipfooterZnrowsr_   rQ   re   rf   rc   rb   rS   Z	thousandscommentdecimalr\   rT   rR   r]   r^   rh   	chunksizer   encodingcompressionZskip_blank_linesZencoding_errorsri   rd   r	   )r<  rT   c                   s*   fdd}g }	i }
|}t |}t }|d u s:t|trB| |fS t|t r8|D ]}t|sht|trt|tr|| vr|| }||rqRnB|dkrdd l}| | j}t|t	r|j
|jsR|j
|jrqR|t| | |d| |< qRt||| |\}}}|| v rtd| ||
|< |	| || qRnt|tr| D ]r\}}|| v rntd| dt||| ||d	\}}}||
|< t|d
kr||
|d < |	| || qLt| trtt|
| gd
dd} n
| |
 |	| |s"t |D ]}| | |	| q| |	fS )Nc                   s$   t  tr|  v p"t to"| v S r   )r   ry   )colspecr[   rn   rK   rL   _isindex  s    z*_process_date_conversion.<locals>._isindexr   r   r   z New date column already in dict zDate column z already in dict)target_namerD   F)Zaxisr   )ry   rl   r   rN   r   r   r   r   rb   r%   typesZis_timestampZpyarrow_dtypeZis_dater   r  _try_convert_datesrv   r   r   r   r   r   r&   r)   extendrq   r   )	data_dictr<  Z
parse_specr[   rn   r   rT   rd   rN  Znew_colsZnew_datark   r9  rL  r	  rb   new_namer   Z	old_namesr   r   rK   rM  rL   r    sx    










r  rU   )r/  rO  c                   s   t |}g }|D ]D}||v r(|| qt|trJ||vrJ|||  q|| qtdd |D r~ttdjt| }nddd |D } fdd|D }	| |	d|d u r|n|i}
||
|fS )Nc                 s  s   | ]}t |tV  qd S r   )r   r   r   r   rK   rK   rL   r   e  r   z%_try_convert_dates.<locals>.<genexpr>r   c                 S  s   g | ]}t |qS rK   )r   rU  rK   rK   rL   r   h  r   z&_try_convert_dates.<locals>.<listcomp>c                   s"   g | ]}| v rt  | qS rK   )r   r  r  rS  rK   rL   r   i  r   r   )	rl   r   r   r   rw   r   rx   r   r   )r/  rL  rS  r   rO  ZcolsetZcolnamesr   rT  Zto_parseZnew_colrK   rV  rL   rQ  V  s    rQ  )rQ   c                 C  sJ   t |tr>| |v r"||  ||  fS |r0tt fS t t fS n||fS dS )a  
    Get the NaN values for a given column.

    Parameters
    ----------
    col : str
        The name of the column.
    na_values : array-like, dict
        The object listing the NaN values as strings.
    na_fvalues : array-like, dict
        The object listing the NaN values as floats.
    keep_default_na : bool
        If `na_values` is a dict, and the column is not mapped in the
        dictionary, whether to return the default NaN values or the empty set.

    Returns
    -------
    nan_tuple : A length-two tuple composed of

        1) na_values : the string NaN values for that column.
        2) na_fvalues : the float NaN values for that column.
    N)r   r   r   rl   )r   r_   r`   rQ   rK   rK   rL   r   o  s    

r   c                 C  s0   d}| du s,t | s,t| ttfs,t|| S )z
    Check whether or not the 'parse_dates' parameter
    is a non-boolean scalar. Raises a ValueError if
    that is the case.
    zSOnly booleans, lists, and dictionaries are accepted for the 'parse_dates' parameterN)r   r   r   ry   r   r  )r\   r  rK   rK   rL   rp     s    rp   rX   c                 C  s   | d uo| duS )NFrK   r   rK   rK   rL   r     s    r   )N)n
__future__r   collectionsr   r   csvr7  enumr   r   typingr   r   r	   r
   r   r   r   numpyr   Zpandas._libsr   r   Zpandas._libs.opsZ_libsopsr  Zpandas._libs.parsersr   Zpandas._libs.tslibsr   Zpandas.compat._optionalr   Zpandas.errorsr   r   Zpandas.util._exceptionsr   Zpandas.core.dtypes.astyper   Zpandas.core.dtypes.commonr   r   r   r   r   r   r   r   r   r   r    r!   Zpandas.core.dtypes.dtypesr"   r#   Zpandas.core.dtypes.missingr$   Zpandasr%   r&   r'   r(   r)   Zpandas.corer*   Zpandas.core.arraysr+   r,   r-   r.   r/   r0   r1   Zpandas.core.arrays.booleanr2   Zpandas.core.indexes.apir3   r4   r5   r6   Zpandas.core.seriesr8   Zpandas.core.toolsr9   r4  Zpandas.io.commonr:   collections.abcr;   r<   r=   r>   Zpandas._typingr?   r@   rA   rB   rC   rs   rt   QUOTE_MINIMALrM   rI   Zparser_defaultsr  rQ  r   rp   r   rK   rK   rK   rL   <module>   s    8$	        h2b #