a
    Sic                     @  sV  d dl mZ d dlmZmZ d dlZd dlmZ d dlZd dl	Z	d dl
mZmZmZmZmZmZmZmZmZmZ d dlZd dlZd dlm  mZ d dlmZmZmZ d dlm Z m!Z! d dl"m#Z# d d	l$m%Z% d d
l&m'Z' d dl(m)Z)m*Z* erd dl+m,Z,m-Z- dZ.G dd de)Z/G dd dejZ0G dd de/Z1ddddZ2dddddZ3dS )    )annotations)abcdefaultdictN)StringIO)
IOTYPE_CHECKINGDefaultDictHashableIteratorListLiteralMappingSequencecast)	ArrayLikeReadCsvBufferScalar)EmptyDataErrorParserError)find_stack_level)
is_integer)is_dict_like)
ParserBaseparser_defaults)Index
MultiIndexu   ﻿c                      s  e Zd Zddd fddZdddddZdWd
ddddZdddddZdXd
ddddZdddddZddddZ	d d!d"d d#d$d%Z
d&dd'd(Zd&d&d)d*d+Zd&d,d-d.d/Zd&dd0d1Zd2d"dd3d4d5Zd"d6d7d8d9Zd:d:d;d<d=Zd:d:d;d>d?Zd:d:d;d@dAZd:d2d2d:dBdCdDZd:d:d;dEdFZdddGdHZdIZdJdKdLdMdNZd:ddOdPdQZdYd
d:ddRdSZd:d:dTdUdVZ  ZS )ZPythonParserzReadCsvBuffer[str] | listNonefreturnc           
        s  t  | d _g  _d _d _|d  _t jrB j _n fdd _t	|d  _
|d  _|d  _t jtrt j _|d	  _|d
  _|d  _|d  _|d  _|d  _|d pd _d _d|v r|d  _|d  _|d  _|d  _|d  _t|tr2ttt | _nt|dsBJ  | d _  ! \} _" _#   $| j%\ _& _% _'}t j& _( j)sƈ * j&\} _( _&d _+ j%du r| _% j du rtt,t- j& _  . j& _/d} j0r 1 j  j&}| _2t- jdkr.t3dt45 j} jdu rTd| d}nt45 j}	d|	 d| d}t46| _7dS )zN
        Workhorse function for processing nested list into DataFrame
        Nr   skiprowsc                   s
   |  j v S N)r!   )xself [/var/www/html/django/DPS/env/lib/python3.9/site-packages/pandas/io/parsers/python_parser.py<lambda>M       z'PythonParser.__init__.<locals>.<lambda>
skipfooter	delimiter	quotechar
escapechardoublequoteskipinitialspacelineterminatorquotingskip_blank_linesnamesFhas_index_namesverbose	thousandsdecimalcommentreadlineT   z'Only length-1 decimal markers supportedz^[\-\+]?[0-9]*(z [0-9]*)?([0-9]?(E|e)\-?[0-9]+)?$z^[\-\+]?([0-9]+z	|[0-9])*()8super__init__databufposline_posr!   callableskipfunc_validate_skipfooter_argr*   r+   r,   
isinstancestrr-   r.   r/   r0   r1   r2   Znames_passedr4   r5   r6   r7   r8   listr   r
   hasattr_make_reader_col_indices_infer_columnsnum_original_columnsunnamed_cols_extract_multi_indexer_columnsindex_namescolumns	col_names
orig_names_has_complex_date_col_get_index_name_name_processedrangelen_validate_parse_dates_presence_parse_date_colsparse_dates_set_noconvert_dtype_columns_no_thousands_columns
ValueErrorreescapecompilenum)
r%   r   kwdsrO   _rN   Zno_thousands_columnsr7   regexr6   	__class__r$   r'   r<   =   s    
















zPythonParser.__init__IO[str] | ReadCsvBuffer[str]c                   sB  j d u stdkr$jr*tdG fdddtj}|}d urT|_ n  }|ggd }j	s~|s j	d7  _	  }|ggd }qnt
tt |}|d } j	d7  _	 jd7  _t |}|j |_ tjt||d}jt| tj |dd}	n fd	d
}
|
 }	|	_d S )Nr:   z<Custom line terminators not supported in python parser (yet)c                      s4   e Zd Z jZ jZ jZ jZ jZ jZdZ	dS )z,PythonParser._make_reader.<locals>.MyDialect
N)
__name__
__module____qualname__r+   r,   r-   r.   r/   r1   r0   r&   r$   r&   r'   	MyDialect   s   rk   r   )dialectT)rl   strictc                  3  s@      } t}||  V   D ]} ||  V  q&d S r"   )r9   r]   r_   splitstrip)linepat)r   sepr&   r'   _read   s
    
z(PythonParser._make_reader.<locals>._read)r+   rV   r0   r\   csvDialectr9   _check_commentsrB   r?   r   r   rE   r@   Sniffersniffreaderr   r>   extendrF   r=   )r%   r   rk   Zdiarp   linesZ	lines_strsniffedZline_rdrry   rs   r&   )r   r%   rr   r'   rH      s8    		zPythonParser._make_readerNz
int | NonezRtuple[Index | None, Sequence[Hashable] | MultiIndex, Mapping[Hashable, ArrayLike]])rowsr    c                 C  s  z|  |}W n( ty6   | jr(g }n
|    Y n0 d| _t| j}t|s| | j}| || j	| j
| j\}}}| || j}|||fS t|d }d }	| jr|t|kr|d }	|dd  }| |}
| |
\}}| |}| ||\}}| ||
||	\}}|||fS )NFr   r:   )
_get_linesStopIteration_first_chunkcloserF   rQ   rV   _maybe_dedup_names_get_empty_meta	index_colrN   dtype_maybe_make_multi_index_columnsrP   count_empty_valsr4   _rows_to_cols_exclude_implicit_index_convert_data_do_date_conversions_make_index)r%   r}   contentrO   r3   indexcol_dictZconv_columnsZcount_empty_content_valsindexnamerowalldatar=   Z	conv_dataresult_columnsr&   r&   r'   read   s@    




zPythonParser.readzlist[np.ndarray]z8tuple[Mapping[Hashable, np.ndarray], Sequence[Hashable]])r   r    c                   sR   |  | j}d| jr t| jt | |   fddt|D |fS )Nr   c                   s&   i | ]\}}|k r| |  qS r&   r&   ).0inamer   Zlen_alldataoffsetr&   r'   
<dictcomp>4  s   z8PythonParser._exclude_implicit_index.<locals>.<dictcomp>)r   rQ   _implicit_indexrV   r   _check_data_length	enumerate)r%   r   r3   r&   r   r'   r   &  s    
z$PythonParser._exclude_implicit_index)sizer    c                 C  s   |d u r| j }| j|dS )N)r}   )	chunksizer   )r%   r   r&   r&   r'   	get_chunk9  s    zPythonParser.get_chunkzMapping[Hashable, np.ndarray]zMapping[Hashable, ArrayLike])r=   r    c           	      C  s   |  | j}|  | j}i }i }t| jtr|| jD ]F}| j| }| j| }t|trh|| jvrh| j| }|||< |||< q2n| j}| j}| 	|||| j
||S r"   )_clean_mapping
convertersr   rD   	na_valuesdict
na_fvaluesintrQ   _convert_to_ndarraysr5   )	r%   r=   Z
clean_convclean_dtypesZclean_na_valuesZclean_na_fvaluescolna_valueZ	na_fvaluer&   r&   r'   r   C  s,    



zPythonParser._convert_dataz9tuple[list[list[Scalar | None]], int, set[Scalar | None]]r    c                   s,  j  d}d}t }d _jd ur j}t|tttjfrft	|dk}|rpt||d d g }n
d}|g}g }t
|D ]l\}}z" }	j|kr }	qW n ty }
 zdj  k r|kr<n nf|r||d kr<ttt|r|d d n|}dd| dt	| d	}td
| dj d|
|r|dkr|rZ  |d gt	|d   |||fW  Y d }
~
  S j std|
j d d  }	W Y d }
~
n
d }
~
0 0 g g t
|	D ]V\}}|dkr|rd| d| }n
d| }| | n
| q|s6jr6tt}fddtt	D  }|D ]}| }|}|| }|dkr|dkr|d ||< | d| }|v r|d7 }n|| }qjd urtjrj|d urj|d u rj|j|i ||< |d ||< qbn~|r||d krt	}j}|d urjt	|nd}t	}||kr|| |ks|dkrd}d g| jd g_| |fddD  t	|dkr|t	}q||r   d urz }W n ty(   d }Y n0 |d u r8dnt	|}t	 t	|d krlt	 |krltdt	|dkrt dj!d ur"| | nt	 }j#d urt	 t	j#kr fddt$j#D g}n g}n"||d |}n"z }	W nB tyN }
 z( s.td|
 d d  }	W Y d }
~
n
d }
~
0 0 |	_t	|	}|} sj%rfddt|D g}ntt|g}"||d |}nvj!d u st	 |kr" g |}t	 }nBt&j!st	 t	j!krtd" g |  g}|}|||fS )Nr   Tr:   F[,z
], len of z, zPassed header=z	but only z lines in filezNo columns to parse from file z	Unnamed: _level_c                   s   g | ]}| vr|qS r&   r&   r   r   )this_unnamed_colsr&   r'   
<listcomp>  s   z/PythonParser._infer_columns.<locals>.<listcomp>.c                   s   h | ]} | qS r&   r&   r   )this_columnsr&   r'   	<setcomp>  r)   z.PythonParser._infer_columns.<locals>.<setcomp>zHNumber of passed names did not match number of header fields in the filez*Cannot pass names with multi-index columnsc                   s   g | ]} | qS r&   r&   r   )r3   r&   r'   r     r)   c                   s   g | ]} j  | qS r&   )prefixr   r$   r&   r'   r     r)   )'r3   set_header_lineheaderrD   rF   tuplenpndarrayrV   r   _buffered_liner@   
_next_liner   maprE   joinr\   _clear_bufferappendr   mangle_dupe_colsr   r   rU   r   r   getupdater   r>   	TypeErrorusecols_handle_usecolsrI   sortedr   rA   )r%   rK   Zclear_bufferrL   r   Zhave_mi_columnsrO   levelhrrp   errZjoimsgr   ccol_namecountsZcol_loop_orderr   Zold_col	cur_countlcsicicZunnamed_count
first_lineZlen_first_data_rowncolsr&   )r3   r%   r   r   r'   rJ   f  s&   


$








"




$

"

 zPythonParser._infer_columnszlist[list[Scalar | None]]zlist[Scalar | None]r   )rO   usecols_keyrK   r    c              	     s   | j durt| j r$| | j | ntdd | j D rt|dkrLtdg  | j D ]P}t|trz |	| W q ty   | 
| j | Y q0 qV | qVn0fdd| j D }|rtjdtt d	 | j   fd
d|D }t | _|S )zb
        Sets self._col_indices

        usecols_key is used if there are string usecols.
        Nc                 s  s   | ]}t |tV  qd S r"   )rD   rE   )r   ur&   r&   r'   	<genexpr>B  r)   z/PythonParser._handle_usecols.<locals>.<genexpr>r:   z4If using multiple headers, usecols must be integers.c                   s   g | ]}| kr|qS r&   r&   )r   r   )rK   r&   r'   r   R  s   z0PythonParser._handle_usecols.<locals>.<listcomp>zkDefining usecols with out of bounds indices is deprecated and will raise a ParserError in a future version.)
stacklevelc                   s"   g | ]} fd dt |D qS )c                   s   g | ]\}}| v r|qS r&   r&   )r   r   ncol_indicesr&   r'   r   _  r)   z;PythonParser._handle_usecols.<locals>.<listcomp>.<listcomp>)r   )r   columnr   r&   r'   r   ^  s   )r   rA   _evaluate_usecolsanyrV   r\   rD   rE   r   r   _validate_usecols_nameswarningswarnFutureWarningr   r   rI   )r%   rO   r   rK   r   Zmissing_usecolsr&   )r   rK   r'   r   3  s>    






zPythonParser._handle_usecolszlist[Scalar]c                 C  s$   t | jdkr| jd S |  S dS )zH
        Return a line from buffer, filling buffer if required.
        r   N)rV   r>   r   r$   r&   r&   r'   r   e  s    
zPythonParser._buffered_line)	first_rowr    c           	      C  s   |s|S t |d ts|S |d s&|S |d d }|tkr>|S |d }t|dkr|d | jkrd}|d }|dd |d }||| }t||d kr|||d d 7 }n|dd }|g}||dd  S )a-  
        Checks whether the file begins with the BOM character.
        If it does, remove it. In addition, if there is quoting
        in the field subsequent to the BOM, remove it as well
        because it technically takes place at the beginning of
        the name, not the middle of it.
        r   r:      N)rD   rE   _BOMrV   r,   r   )	r%   r   Z	first_eltZfirst_row_bomstartquoteendnew_rowZnew_row_listr&   r&   r'   _check_for_bomn  s(    
zPythonParser._check_for_bombool)rp   r    c                 C  s   | pt dd |D S )z
        Check if a line is empty or not.

        Parameters
        ----------
        line : str, array-like
            The line of data to check.

        Returns
        -------
        boolean : Whether or not the line is empty.
        c                 s  s   | ]}| V  qd S r"   r&   r   r#   r&   r&   r'   r     r)   z.PythonParser._is_line_empty.<locals>.<genexpr>)all)r%   rp   r&   r&   r'   _is_line_empty  s    zPythonParser._is_line_emptyc                 C  s  t | jtr| | jr:| jt| jkr*q:|  jd7  _qzr| | j| j gd }|  jd7  _| js| | j| jd  s|rW qn"| jr| 	|g}|r|d }W qW q: t
y   tY q:0 q:n| | jr|  jd7  _| jd usJ t| j q| j| jd d}|  jd7  _|d ur| |gd }| jr\| 	|g}|rp|d }qrq| |sr|rqrq| jdkr| |}|  jd7  _| j| |S )Nr:   r   row_num)rD   r=   rF   rB   r?   rV   rv   r2   r   _remove_empty_lines
IndexErrorr   next_next_iter_liner   r@   r>   r   )r%   rp   retZ	orig_liner&   r&   r'   r     sR    
zPythonParser._next_linerE   )r   r   r    c                 C  sJ   | j | jjkrt|n.| j | jjkrFd| d}tj|| d  dS )a   
        Alert a user about a malformed row, depending on value of
        `self.on_bad_lines` enum.

        If `self.on_bad_lines` is ERROR, the alert will be `ParserError`.
        If `self.on_bad_lines` is WARN, the alert will be printed out.

        Parameters
        ----------
        msg: str
            The error message to display.
        row_num: int
            The row number where the parsing error occurred.
            Because this row number is displayed, we 1-index,
            even though we 0-index internally.
        zSkipping line z: rg   N)on_bad_linesBadLineHandleMethodERRORr   WARNsysstderrwrite)r%   r   r   baser&   r&   r'   _alert_malformed  s
    
zPythonParser._alert_malformedzlist[Scalar] | None)r   r    c              
   C  s   z,| j dusJ t| j }t|ts(J |W S  tjy } zl| j| jjksZ| j| jj	krt
|}d|v srd|v rvd}| jdkrd}|d| 7 }| || W Y d}~dS d}~0 0 dS )a[  
        Wrapper around iterating through `self.data` (CSV source).

        When a CSV error is raised, we check for specific
        error messages that allow us to customize the
        error message displayed to the user.

        Parameters
        ----------
        row_num: int
            The row number of the line being parsed.
        Nz	NULL bytezline contains NULzNULL byte detected. This byte cannot be processed in Python's native csv library at the moment, so please pass in engine='c' insteadr   zError could possibly be due to parsing errors in the skipped footer rows (the skipfooter keyword is only applied after Python's csv library has parsed all rows).. )r=   r   rD   rF   rt   Errorr   r   r   r   rE   r*   r   )r%   r   rp   er   reasonr&   r&   r'   r     s(    

zPythonParser._next_iter_linelist[list[Scalar]]r{   r    c                 C  s   | j d u r|S g }|D ]t}g }|D ]\}t|trD| j |vsD|| jv rP|| q"|d || j  }t|dkrz||  qq"|| q|S )Nr   )r8   rD   rE   r   r   findrV   )r%   r{   r   rp   rlr#   r&   r&   r'   rv   2  s&    

zPythonParser._check_commentsc                 C  sN   g }|D ]@}t |dks>t |dkrt|d tr>|d  r|| q|S )a  
        Iterate through the lines and remove any that are
        either empty or contain only one whitespace value

        Parameters
        ----------
        lines : list of list of Scalars
            The array of lines that we are to filter.

        Returns
        -------
        filtered_lines : list of list of Scalars
            The same array of lines with the "empty" ones removed.
        r:   r   )rV   rD   rE   ro   r   )r%   r{   r   rp   r&   r&   r'   r   G  s    


z PythonParser._remove_empty_linesc                 C  s    | j d u r|S | j|| j ddS )Nr   r{   searchreplace)r6   _search_replace_num_columnsr%   r{   r&   r&   r'   _check_thousandsa  s
    
zPythonParser._check_thousands)r{   r
  r  r    c           	      C  s   g }|D ]t}g }t |D ]X\}}t|trR||vsR| jrB|| jv sR| j| s^|| q|||| q|| q|S r"   )	r   rD   rE   r[   r`   r
  ro   r   r  )	r%   r{   r
  r  r   rp   r  r   r#   r&   r&   r'   r  i  s$    z(PythonParser._search_replace_num_columnsc                 C  s$   | j td kr|S | j|| j ddS )Nr7   r   r	  )r7   r   r  r  r&   r&   r'   _check_decimal|  s
    zPythonParser._check_decimalc                 C  s
   g | _ d S r"   )r>   r$   r&   r&   r'   r     s    zPythonParser._clear_bufferFzlist[Hashable]z@tuple[Sequence[Hashable] | None, list[Hashable], list[Hashable]])rO   r    c           
      C  st  t |}t |}| jdur"| j}n$z|  }W n tyD   d}Y n0 z|  }W n tyh   d}Y n0 d}|dur$| j}|durt|| j }|dur$| jdur$|dur$t|t|| j kr$t tt|| _| j	dd | _	t
|D ]}|d| qt |}t|| _|||fS |dkrTd| _| jdu rNt t|| _d}n| || j\}}	| _|||fS )a  
        Try several cases to get lines:

        0) There are headers on row 0 and row 1 and their
        total summed lengths equals the length of the next line.
        Treat row 0 as columns and row 1 as indices
        1) Look for implicit index: there are more columns
        on row 1 than row 0. If this is true, assume that row
        1 lists index columns and row 0 lists normal columns.
        2) Get index from the columns if it was listed.
        Nr   Fr:   T)rF   r   r   r   r   rV   rK   r   rU   r>   reversedinsertr   _clean_index_names)
r%   rO   rQ   rp   	next_lineZimplicit_first_colsr   r   
index_namerb   r&   r&   r'   rS     sP    






zPythonParser._get_index_name)r   r    c                   s  j }jr|tj7 }tdd |D }||krjdurjd u rjrZjnd}g }t|}t|}g }|D ]\}}	t|	}
|
|krtj	r	|	}|d ur|
| nTj	jjksڈj	jjkrj|| |  }|
||
f j	jjkr qqz|
|	 qz|D ]j\}}
d| d|d  d|
 }jrztjdkrzjtjkrzd	}|d
| 7 }||d  q"ttj||dj}jrjd usJ j jr fddt|D }n fddt|D }|S )Nc                 s  s   | ]}t |V  qd S r"   )rV   r   rowr&   r&   r'   r     r)   z-PythonParser._rows_to_cols.<locals>.<genexpr>Fr   z	Expected z fields in line r:   z, saw zXError could possibly be due to quotes being ignored when a multi-char delimiter is used.r  )	min_widthc                   s4   g | ],\}}|t jk s,|t j  v r|qS r&   )rV   r   r   r   ar   r%   r&   r'   r     s   z.PythonParser._rows_to_cols.<locals>.<listcomp>c                   s   g | ]\}}| v r|qS r&   r&   r  r   r&   r'   r   (  s   )rK   r   rV   r   maxr   r*   r   rA   r   r   r   r   r   r?   r+   r1   rt   
QUOTE_NONEr   rF   libto_object_arrayTrI   )r%   r   Zcol_lenmax_lenZfootersZ	bad_linesiter_contentZcontent_lenr   l
actual_lenZnew_lr   r   r  Zzipped_contentr&   r  r'   r     st    



	
zPythonParser._rows_to_colsc           	      C  s^  | j }d }|d urPt| j |krB| j d | | j |d   }| _ n|t| j 8 }|d u rt| jtr| jt| jkrzt|d u r| j| jd  }t| j}n | j| j| j|  }| j| }| |}|| || _n.g }z|d urvd}| j	d ur$| jd ur$tt
| j	t
t| j }t|| D ]&}| jd usDJ |t| j q0t|}| |}|| nBd}| j| j| d d}|d7 }|d urz|| qzt|}W n@ ty   t|}| |}|| t|dkr Y n0 |  j|7  _g | _ n|}| jr.|d | j  }| |}| jrJ| |}| |}| |S )Nr   r:   r   )r>   rV   rD   r=   rF   r?   r   _remove_skipped_rowsrz   r!   r   rU   r   r   r   r*   rv   r2   r   r  r  )	r%   r}   r{   new_rowsnew_posZrows_to_skiprb   Zlen_new_rowsr   r&   r&   r'   r~   -  sl    "












zPythonParser._get_lines)r%  r    c                   s     j r fddt|D S |S )Nc                   s$   g | ]\}}  | j s|qS r&   )rB   r?   )r   r   r  r$   r&   r'   r     s   z5PythonParser._remove_skipped_rows.<locals>.<listcomp>)r!   r   )r%   r%  r&   r$   r'   r$    s
    
z!PythonParser._remove_skipped_rows)N)N)N)rh   ri   rj   r<   rH   r   r   r   r   rJ   r   r   r   r   r   r   r   rv   r   r  r  r  r   r   rS   r   r~   r$  __classcell__r&   r&   rd   r'   r   <   s8   tD 2 
# N2	680MWRr   c                	   @  sb   e Zd ZdZdddddddd	d
ddZdddddddZdddddddZddddZdS )FixedWidthReaderz(
    A reader of fixed-width lines.
    Nd   rf   z(list[tuple[int, int]] | Literal['infer']z
str | Nonezset[int] | Noner   r   )r   colspecsr+   r8   r!   infer_nrowsr    c                 C  s   || _ d | _|rd| nd| _|| _|dkr>| j||d| _n|| _t| jttfsht	dt
|j | jD ]Z}t|ttfrt|dkrt|d ttjt
d frt|d ttjt
d fsnt	d	qnd S )
Nz
z
	 infer)r+  r!   z;column specifications must be a list or tuple, input was a r   r   r:   zEEach column specification must be 2 element tuple or list of integers)r   bufferr+   r8   detect_colspecsr*  rD   r   rF   r   typerh   rV   r   r   integer)r%   r   r*  r+   r8   r!   r+  colspecr&   r&   r'   r<     s6    	


zFixedWidthReader.__init__z	list[str])r+  r!   r    c                 C  sd   |du rt  }g }g }t| jD ]4\}}||vr:|| || t||kr  qVq t|| _|S )a  
        Read rows from self.f, skipping as specified.

        We distinguish buffer_rows (the first <= infer_nrows
        lines) from the rows returned to detect_colspecs
        because it's simpler to leave the other locations
        with skiprows logic alone than to modify them to
        deal with the fact we skipped some rows here as
        well.

        Parameters
        ----------
        infer_nrows : int
            Number of rows to read from self.f, not counting
            rows that are skipped.
        skiprows: set, optional
            Indices of rows to skip.

        Returns
        -------
        detect_rows : list of str
            A list containing the rows to read.

        N)r   r   r   r   rV   iterr-  )r%   r+  r!   Zbuffer_rowsZdetect_rowsr   r  r&   r&   r'   get_rows  s    


zFixedWidthReader.get_rowszlist[tuple[int, int]]c                   s   d dd  jD }td| d} ||}|s@tdttt|}t	j
|d td} jd ur| fd	d|D }|D ](}||D ]}	d||	 |	 < qqt	|d}
d
|
d
< t	||
A dkd
 }tt|d d d |dd d }|S )Nr   c                 S  s   g | ]}d | qS )\r&   r   r&   r&   r'   r     r)   z4FixedWidthReader.detect_colspecs.<locals>.<listcomp>z([^z]+)z(No rows from which to infer column widthr:   )r   c                   s   g | ]}|  jd  qS )r   )	partitionr8   r  r$   r&   r'   r     r)   r   r   )r   r+   r]   r_   r3  r   r  r   rV   r   zerosr   r8   finditerr   r   rollwhererF   zip)r%   r+  r!   
delimiterspatternr}   r   maskr  mshiftededgesZ
edge_pairsr&   r$   r'   r.    s"    
"z FixedWidthReader.detect_colspecsr   c                   s^   j d ur>ztj  W qH ty:   d _ tj Y qH0 n
tj  fddjD S )Nc                   s$   g | ]\}} ||  jqS r&   )ro   r+   )r   Zfrommtorp   r%   r&   r'   r     r)   z-FixedWidthReader.__next__.<locals>.<listcomp>)r-  r   r   r   r*  r$   r&   rB  r'   __next__  s    

zFixedWidthReader.__next__)Nr)  )N)r)  N)rh   ri   rj   __doc__r<   r3  r.  rC  r&   r&   r&   r'   r(    s   
  &' r(  c                   @  s@   e Zd ZdZdddddZddddd	Zd
d
dddZdS )FixedWidthFieldParserzl
    Specialization that Converts fixed-width fields into DataFrames.
    See PythonParser for details.
    zReadCsvBuffer[str]r   r   c                 K  s0   | d| _| d| _tj| |fi | d S )Nr*  r+  )popr*  r+  r   r<   )r%   r   ra   r&   r&   r'   r<     s    zFixedWidthFieldParser.__init__rf   c                 C  s"   t || j| j| j| j| j| _d S r"   )r(  r*  r+   r8   r!   r+  r=   )r%   r   r&   r&   r'   rH   	  s    z"FixedWidthFieldParser._make_readerr  r  c                 C  s   dd |D S )z
        Returns the list of lines without the empty ones. With fixed-width
        fields, empty lines become arrays of empty strings.

        See PythonParser._remove_empty_lines.
        c                 S  s"   g | ]}t d d |D r|qS )c                 s  s"   | ]}t |t p| V  qd S r"   )rD   rE   ro   )r   r  r&   r&   r'   r     r)   zGFixedWidthFieldParser._remove_empty_lines.<locals>.<listcomp>.<genexpr>)r   )r   rp   r&   r&   r'   r     s   z=FixedWidthFieldParser._remove_empty_lines.<locals>.<listcomp>r&   r  r&   r&   r'   r     s    z)FixedWidthFieldParser._remove_empty_linesN)rh   ri   rj   rD  r<   rH   r   r&   r&   r&   r'   rE    s   
rE  r   r   c                 C  s   t dd | D S )Nc                 s  s"   | ]}|d ks|du rdV  qdS )r   Nr:   r&   )r   vr&   r&   r'   r   "  r)   z#count_empty_vals.<locals>.<genexpr>)sum)valsr&   r&   r'   r   !  s    r   )r*   r    c                 C  s$   t | std| dk r td| S )a  
    Validate the 'skipfooter' parameter.

    Checks whether 'skipfooter' is a non-negative integer.
    Raises a ValueError if that is not the case.

    Parameters
    ----------
    skipfooter : non-negative integer
        The number of rows to skip at the end of the file.

    Returns
    -------
    validated_skipfooter : non-negative integer
        The original input if the validation succeeds.

    Raises
    ------
    ValueError : 'skipfooter' was not a non-negative integer.
    zskipfooter must be an integerr   zskipfooter cannot be negative)r   r\   )r*   r&   r&   r'   rC   %  s
    rC   )4
__future__r   collectionsr   r   rt   ior   r]   r   typingr   r   r   r	   r
   r   r   r   r   r   r   numpyr   pandas._libs.lib_libsr  pandas._typingr   r   r   pandas.errorsr   r   pandas.util._exceptionsr   pandas.core.dtypes.commonr   pandas.core.dtypes.inferencer   pandas.io.parsers.base_parserr   r   pandasr   r   r   r   r(  rE  r   rC   r&   r&   r&   r'   <module>   s>   0	        Sv$