
    MhH                       S SK Jr  S SKJrJr  S SKJrJrJrJ	r	  S SK
r
S SKJr  S SKrS SKJrJrJrJrJr  S SKrS SKrS SKJr  S SKJrJrJr  S S	KJr  S S
KJ r   S SK!J"r"J#r#J$r$  S SK%J&r&  S SK'J(r(J)r)  S SK*J+r+J,r,  \(       a  S SK-J.r.J/r/J0r0  S SK1J2r2J3r3  Sr4 " S S\+5      r5 " S S\R                  5      r6 " S S\55      r7SS jr8SS jr9g)    )annotations)abcdefaultdict)HashableIteratorMappingSequenceN)StringIO)IOTYPE_CHECKINGDefaultDictLiteralcast)lib)EmptyDataErrorParserErrorParserWarning)cache_readonly)find_stack_level)is_bool_dtype
is_integeris_numeric_dtype)is_dict_like)dedup_namesis_potential_multi_index)
ParserBaseparser_defaults)	ArrayLikeReadCsvBufferScalar)Index
MultiIndexu   ﻿c                    ^  \ rS rSr% S\S'   S!U 4S jjr\S"S j5       rS#S jr S$   S%S jjr	    S&S jr
 S$   S'S	 jjr    S(S
 jr\S)S j5       r  S*S jr\S 5       r        S+S jrS,S jrS-S jrS.S jrS,S jrS/S jrS0S jrS1S jrS1S jrS1S jr        S2S jrS1S jrS3S jr  S4S jrS5S jrS$S6S jjrS7S jr S8S jr!S r"U =r#$ )9PythonParserG   set[int]_no_thousands_columnsc                  >^  [         TT ]  U5        ST l        / T l        ST l        ST l        US   T l        [        T R                  5      (       a  T R                  T l        OU 4S jT l        [        US   5      T l
        US   T l        US   T l        [        T R                  [        5      (       a  [        T R                  5      T l        US   T l        US	   T l        US
   T l        US   T l        US   T l        US   T l        ST l        SU;   a
  US   T l        US   T l        US   T l        US   T l        US   T l        [        U[4        5      (       a  [7        [8        [           U5      T l        O)[;        US5      (       d   eT R=                  U5      T l        ST l        T RA                  5       u  nT l!        T l"        T RG                  UT RH                  5      u  T l%        T l$        T l&        n[5        T RJ                  5      T l'        T RP                  (       d9  T RS                  5       u  nT l'        T l%        ST l*        T RH                  c  UT l$        T R>                  c,  [5        [W        [Y        T RJ                  5      5      5      T l        T R[                  T RJ                  5      T l.        T R_                  5       T l0        [Y        T R0                  5      S:w  a  [c        S5      eg)z>
Workhorse function for processing nested list into DataFrame
Nr   skiprowsc                "   > U TR                   ;   $ N)r)   )xselfs    Q/var/www/html/env/lib/python3.13/site-packages/pandas/io/parsers/python_parser.py<lambda>'PythonParser.__init__.<locals>.<lambda>Z   s    a4==&8    
skipfooter	delimiter	quotechar
escapechardoublequoteskipinitialspacelineterminatorquotingskip_blank_linesFhas_index_namesverbose	thousandsdecimalcommentreadlineT   z'Only length-1 decimal markers supported)2super__init__databufposline_posr)   callableskipfunc_validate_skipfooter_argr2   r3   r4   
isinstancestrr5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   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_set_no_thousand_columnsr'   
ValueError)r-   fkwdsrV   _rU   	__class__s   `     r.   rC   PythonParser.__init__J   s    	*.	Z(DMM"" MMDM8DM243EFk*k*dnnc** 0DN|,. $%7 8"#34I $%7 8$$#'(9#:D Ik*II aXc]A.DI1j))))))!,DI /3 !		
% //
	
LN +/t||*<
 ));?;O;O;Q8[$/4<#'D '#. $ $U3t||+<%= >D $ C CDLL Q%)%B%B%D"t||!FGG "r1   c                    [         R                  " U R                  5      nU R                  c  SU S3nO)[         R                  " U R                  5      nSU SU S3n[         R                  " U5      $ )Nz^[\-\+]?[0-9]*(z [0-9]*)?([0-9]?(E|e)\-?[0-9]+)?$z^[\-\+]?([0-9]+z	|[0-9])*()reescaper>   r=   compile)r-   r>   regexr=   s       r.   numPythonParser.num   sm    ))DLL)>>!&wi/OPE		$..1I"9+Ywi @, -  zz%  r1   c                  ^ ^^ T R                   mTb  [        T5      S:X  Ga  T R                  (       a  [        S5      e " U 4S jS[        R
                  5      nUnTb	  TUl         GOpTR                  5       nT R                  U//5      S   nT R                  T R                  5      (       d  U(       df  T =R                  S-  sl	        TR                  5       nT R                  U//5      S   nT R                  T R                  5      (       a  M]  U(       d  Mf  [        [        [           U5      nUS   nT =R                  S-  sl	        T =R                  S-  sl        [        R                  " 5       R                  U5      nUR                   Ul         [        R                   " [#        U5      US9nT R$                  R'                  [        U5      5        [        R                   " TUSS9n	U	$ UU4S	 jn
U
" 5       n	U	$ )
NrA   z<Custom line terminators not supported in python parser (yet)c                     > \ rS rSr Y R                  r Y R
                  r Y R                  r Y R                  r Y R                  r Y R                  r	Sr
Srg),PythonParser._make_reader.<locals>.MyDialect   
 N)__name__
__module____qualname____firstlineno__r3   r4   r5   r6   r7   r9   r8   __static_attributes__r-   s   r.   	MyDialectrp      sC     NN	 NN	!__
"..#'#8#8 ,,!%r1   rz   r   )dialectT)r{   strictc               3     >#    TR                  5       n [        R                  " T5      nUR                  U R	                  5       5      v   T H$  n UR                  U R	                  5       5      v   M&     g 7fr+   )r@   rh   rj   splitstrip)linepatrb   seps     r.   _read(PythonParser._make_reader.<locals>._read   sR     zz|jjoii

--D))DJJL11 s   A3A6)r3   r]   r8   ra   csvDialectr@   _check_commentsrI   rF   r   rM   rL   rG   Sniffersniffreaderr
   rE   extend)r-   rb   rz   diar   lines	lines_strsniffedline_rdrr   r   r   s   ``         @r.   rO   PythonParser._make_reader   s   nn;#c(a-"" R &CKK & C # zz|,,tfX6q9mmDHH--UHHMH::<D 004&:1=E mmDHH--UU !cE2	 !|A"++---d3 ' 1 1 ::htncBX/ ZZ3t<F 2 WFr1   c                     U R                  U5      nSU l        [	        U R
                  5      n[        U5      (       dr  [        U R
                  [        U R
                  U R                  5      5      nU R                  UU R                  5      u  pSnU R                  X0R                  5      nXWU4$ [        US   5      nS n	U R                  (       a  U[        U5      :X  a
  US   n	USS  nU R!                  U5      n
U R#                  U
5      u  pU R%                  U5      nU R'                  X<5      u  p<U R)                  XX95      u  p]X]U4$ ! [         a(    U R                  (       a  / n GNXU R                  5         e f = f)NFr   rA   )
_get_linesStopIteration_first_chunkcloserM   rX   r]   r   r   	index_col_get_empty_metadtype_maybe_make_multi_index_columnsrW   count_empty_valsr;   _rows_to_cols_exclude_implicit_index_convert_data_do_date_conversions_make_index)r-   rowscontentrV   namesindexcol_dictconv_columnscount_empty_content_valsindexnamerowalldatarD   	conv_dataresult_columnss                 r.   readPythonParser.read   sv   
	ood+G "&*4??&;7||  (OONNE (,';';

($EH  ??XL00 $4GAJ#? $<G$L"1:LabkG$$W-44W=&&t,	!66wJ $ 0 0!
 i//[  	  

	s   E E=+E=c                Z   [        U R                  [        U R                  U R                  5      5      nSnU R                  (       a  [        U R                  5      n[        U5      nU R                  X!5        [        U5       VVs0 s H  u  pVXT:  d  M  XaXS-      _M     snnU4$ s  snnf Nr   )r   rX   r   r   _implicit_indexr]   _check_data_length	enumerate)r-   r   r   offsetlen_alldatainames          r.   r   $PythonParser._exclude_implicit_index,  s    
 OO$
 (F'l/ 6?u5E
5E'!%D!*%%5E
 	 
s   B'B'c                >    Uc  U R                   nU R                  US9$ )N)r   )	chunksizer   )r-   sizes     r.   	get_chunkPythonParser.get_chunkF  s#    
 <>>Dyydy##r1   c                   U R                  U R                  5      nU R                  U R                  5      n0 n0 n[        U R                  [
        5      (       am  U R                   H\  nU R                  U   nU R                  U   n[        U[        5      (       a  X`R                  ;  a  U R                  U   nXtU'   XU'   M^     OU R                  nU R                  nU R                  UUUU R                  UU5      $ r+   )_clean_mapping
convertersr   rK   	na_valuesdict
na_fvaluesintrX   _convert_to_ndarraysr<   )	r-   rD   
clean_convclean_dtypesclean_na_valuesclean_na_fvaluescolna_value	na_fvalues	            r.   r   PythonParser._convert_dataP  s    
 ((9
**4::6 dnnd++~~>>#. OOC0	c3''C,F//#.C'/$(1% & #nnO#((LL
 	
r1   c                    U R                   c  gU R                   n[        U[        [        [        R
                  45      (       a  [        U5      S:  $ g)NFrA   )headerrK   rM   tuplenpndarrayr]   )r-   r   s     r.   _have_mi_columnsPythonParser._have_mi_columnss  sA    ;;ftUBJJ788v;?"r1   c           
     8   U R                   nSnSn[        5       nU R                  GbH  U R                  nU R                  n[	        U[
        [        [        R                  45      (       a  U(       a  [        U5      US   S-   /-   nOU/n/ n[        U5       GH  u  p U R                  5       n
U R                  U	::  a"  U R                  5       n
U R                  U	::  a  M"  / n/ n[        U
5       HV  u  nnUS:X  a9  U(       a	  SU SU 3nOSU 3nUR)                  U5        UR)                  U5        ME  UR)                  U5        MX     U(       Gd+  [-        [.        5      n[1        [#        U5      5       Vs/ s H  nUU;  d  M  UPM     snU-   nU H  nUU   nUnUU   nUS:  a  US:  a(  US-   UU'   U SU 3nUU;   a  US-  nOUU   nUS:  a  M(  U R2                  b  [5        U R2                  5      (       an  U R2                  R7                  U5      bR  U R2                  R7                  U5      c6  U R2                  R9                  UU R2                  R7                  U5      05        UUU'   US-   UU'   M     OsU(       al  XS   :X  ad  [#        U5      nU R:                  nUb  [#        U5      OSn[#        U5      nUU:w  a	  UU-
  U:  d  US:X  a  SnS /U-  nU R<                  S   /U l        UR)                  U5        UR9                  U Vs1 s H  nUU   iM
     sn5        [#        U5      S:X  d  GM  [#        U5      nGM     U(       a  U R'                  5         Ub   U R                  5       nUc  SO
[#        U5      n[#        U5      [#        US   5      :  a  [#        U5      U:  a  [%        S5      e[#        U5      S:  a  [?        S5      eU R@                  b  U RC                  XqU5        O[#        U5      nU RD                  bM  [#        U5      [#        U RD                  5      :w  a+  [G        U RD                  5       Vs/ s H  nUU   PM
     sn/nOU/nOU RC                  XwS   U5      nO[#        U RH                  5      nUnU(       d+  [        [1        U5      5      /nU RC                  XwS   U5      nOU R@                  b  [#        U5      U:  a   U RC                  U/UU5      n[#        U5      nO_[K        U R@                  5      (       d-  [#        U5      [#        U R@                  5      :w  a  [%        S5      eU/nU RC                  XwS   U5        XrU4$ ! [         Ga  nSU R                  s=:  a  U	::  au  O  OrU(       a  XS   :w  ac  [        [        [        U(       a  US S OU5      5      nSSR!                  U5       S[#        U5       S3n[%        S	U S
U R                   S35      UeU(       aI  U	S:  aC  U(       a  U R'                  5         UR)                  S /[#        US   5      -  5        XrU4s S nAs  $ U R                   (       d  [+        S5      UeU R                   S S  n
 S nAGNS nAff = fs  snf s  snf ! [         a    S n GN f = fs  snf )Nr   TrA   [,z
], len of z, zPassed header=z	but only z lines in fileNo columns to parse from file z	Unnamed: _level_.FzHNumber of passed names did not match number of header fields in the filez*Cannot pass names with multi-index columns)&r   setr   r   rK   rM   r   r   r   r   _buffered_linerG   
_next_liner   maprL   joinr]   ra   _clear_bufferappendr   r   r   r\   r   r   getupdater   rE   	TypeErrorusecols_handle_usecolsrP   sorted_header_linerH   )r-   r   rR   clear_bufferrS   r   have_mi_columnsrV   levelhrr   errjoimsgthis_columnsthis_unnamed_colsr   ccol_namecountscol_loop_orderr   old_col	cur_countlcsicicunnamed_count
first_linelen_first_data_rowncolss                                  r.   rQ   PythonParser._infer_columns~  sQ    

 +.5;;"[[F"33O&4

";<<"!&\VBZ!^,<<F 13G&v.	)..0D--2-#0 --2-< 57$&!%dODAqBw*)21#WUG'DH)21#H)003$++H5$++A. , '*5c*:F
 "'s<'8!9&!9A$55 !9& *	&*N ,*1o"%$*3K	$q="+a-2;a-w)0	9+&>#&,#6$-NI06sI #,a- !%

 6$0$<$<$(JJNN7$;$G$(JJNN3$7$? $

 1 13

w8O2P Q*-Q&/!ms- ,. % BZ' ."nn),SXa(+,=(> -/BGm4KPRVWPW+0L,06B;L(,~DH|,##>O$P>O\!_>O$PQw<1$+.|+<(Q /T ""$  &!%!2J +5*<Q#j/"u:GAJ/CJAS4S$>  w<!##$PQQ<<+ ((9MN+.u:($$0SZ3%%D 6 399J9J2KL2KQa2KLMG$gG..QZ)= ))*E#( e-...w
EJ%Uu)<..wuE'*5z$dll++E
c$,,>O0O 0  !'$$Waj%@l::y % )4==.B.+rBZ/? #3s?F3BKPV#WX !#((3-
3s8*BG(,SE'nF  ## '26' ..0vGBK0@'@A&lJJ::,-LMSVV::a=D3)\&` %Q % &!%J&,  MsP   A U7
Y:Y:Y?
#Z ZY7$CY28Y7 ,Y22Y7ZZc                    U R                   b  g  U R                  5       nU$ ! [         a7  nU R                  (       d  [	        S5      UeU R                  S S  n S nAU$ S nAff = f)Nr   )r   r   r   r   r   )r-   r   r   s      r.   r   PythonParser._header_line7  sd     ;;"	!&&(D   	!::$%DE3N::a=D	!s   " 
A#,AA#c                d   U R                   Gba  [        U R                   5      (       a  U R                  U R                   U5      nO[        S U R                    5       5      (       ay  [	        U5      S:  a  [        S5      e/ nU R                    HL  n[        U[        5      (       a#   UR                  UR                  U5      5        M;  UR                  U5        MN     OEU R                    Vs/ s H  oUU:  d  M
  UPM     nnU(       a  [        SU S35      eU R                   nU VVV	s/ s H*  n[        U5       VV	s/ s H  u  pX;   d  M  U	PM     sn	nPM,     nnnn	[        U5      U l        U$ ! [
         a!    U R                  U R                   U5         GM  f = fs  snf s  sn	nf s  sn	nnf )zJ
Sets self._col_indices

usecols_key is used if there are string usecols.
c              3  B   #    U  H  n[        U[        5      v   M     g 7fr+   )rK   rL   ).0us     r.   	<genexpr>/PythonParser._handle_usecols.<locals>.<genexpr>U  s     >AZ3''s   rA   z4If using multiple headers, usecols must be integers.z<Defining usecols with out-of-bounds indices is not allowed. z are out-of-bounds.)r   rH   _evaluate_usecolsanyr]   ra   rK   rL   r   r   _validate_usecols_namesr   r   r   rP   )
r-   rV   usecols_keyrR   col_indicesr   missing_usecolscolumnr   ns
             r.   r   PythonParser._handle_usecolsF  s    <<#%%"44T\\;O>>>>w<!#$N  !<<C!#s++T'..{/@/@/EF $**3/ ( $(<<##/C:N3NC<   # #%V*++>@  #ll &%F  )0E0tqA4D0E%   !'{ 3D)  * T 88{SST
# Fs<   ( E2.	F ;F +F+?F%F%F+2&FF%F+c                r    [        U R                  5      S:  a  U R                  S   $ U R                  5       $ )z8
Return a line from buffer, filling buffer if required.
r   )r]   rE   r   ry   s    r.   r   PythonParser._buffered_linev  s/     txx=188A;??$$r1   c                r   U(       d  U$ [        US   [        5      (       d  U$ US   (       d  U$ US   S   nU[        :w  a  U$ US   n[        U5      S:  aR  US   U R                  :X  a?  SnUS   nUSS R                  U5      S-   nX4U n[        U5      US-   :  a
  XsUS-   S -  nOUSS nU/nXSS -   $ )z
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   rA      N)rK   rL   _BOMr]   r4   r   )	r-   	first_row	first_eltfirst_row_bomstartquoteendnew_rownew_row_lists	            r.   _check_for_bomPythonParser._check_for_bom  s     
 )A,,, | aLO	!! }!mA&6$..&HE!!$E#))%014C $#.G =!C!G+q33 $AB'G&-Ym++r1   c                B    U(       + =(       d    [        S U 5       5      $ )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              3  .   #    U  H  o(       + v   M     g 7fr+   rs   )r  r,   s     r.   r  .PythonParser._is_line_empty.<locals>.<genexpr>  s     3duuds   )all)r-   r   s     r.   _is_line_emptyPythonParser._is_line_empty  s     x333d333r1   c                   [        U R                  [        5      (       Ga;  U R                  U R                  5      (       a[  U R                  [        U R                  5      :  a  O7U =R                  S-  sl        U R                  U R                  5      (       a  M[    U R                  U R                  U R                     /5      S   nU =R                  S-  sl        U R                  (       d9  U R                  U R                  U R                  S-
     5      (       d  U(       a  GOIU R                  (       a   U R                  U/5      nU(       a  US   nGOM  U R                  U R                  5      (       a[  U =R                  S-  sl        U R                  c   e[        U R                  5        U R                  U R                  5      (       a  M[   U R                  U R                  S-   S9nU =R                  S-  sl        Ubd  U R                  U/5      S   nU R                  (       a   U R                  U/5      nU(       a  US   nO!OU R                  U5      (       d  U(       a  OM  U R                  S:X  a  U R                  U5      nU =R                  S-  sl        U R                   R#                  U5        U$ ! [         a    [        ef = f)NrA   r   row_num)rK   rD   rM   rI   rF   r]   r   r:   r%  _remove_empty_lines
IndexErrorr   next_next_iter_liner  rG   rE   r   )r-   r   ret	orig_lines       r.   r   PythonParser._next_line  s:   dii&&--))88s499~-A --))
 (//4881D0EFqIDHHMH00++DIIdhhl,CDD,,"66v>#&q6D! " --))Ayy,,,TYY	 --))  00A0F	A(//<Q?D,,"66v>#&q6D!  ,,Y774 & 88q=&&t,DC " (''(s   B	K )/K Kc                    U R                   U R                  R                  :X  a  [        U5      eU R                   U R                  R                  :X  a*  [
        R                  " SU SU S3[        [        5       S9  gg)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: rr   )
stacklevelN)	on_bad_linesBadLineHandleMethodERRORr   WARNwarningswarnr   r   )r-   r   r)  s      r.   _alert_malformedPythonParser._alert_malformed  so    "  8 8 > >>c"" 8 8 = ==MM 	C53+- >r1   c                    U R                   c   e[        U R                   5      n[        U[        5      (       d   eU$ ! [        R
                   a  nU R                  U R                  R                  U R                  R                  4;   aD  [        U5      nSU;   d  SU;   a  SnU R                  S:  a
  SnUSU-   -  nU R                  XA5         SnAgSnAff = f)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).. )rD   r,  rK   rM   r   Errorr3  r4  r5  r6  rL   r2   r9  )r-   r)  r   er   reasons         r.   r-  PythonParser._next_iter_line  s    !	99(((		?DdD))))Kyy 	  ((..((--%  !f#%)<)C?  ??Q&%  4&=(C%%c35	s   <? CA>CCc                |   U R                   c  U$ / nU H  n/ nU H  n[        U[        5      (       a  U R                   U;  d  XPR                  ;   a  UR	                  U5        MJ  US UR                  U R                   5       n[        U5      S:  a  UR	                  U5          O   UR	                  U5        M     U$ r   )r?   rK   rL   r   r   findr]   )r-   r   r.  r   rlr,   s         r.   r   PythonParser._check_commentsE  s    <<LDB"1c**||1,NN*IIaL0AFF4<<01A1vz		!  JJrN  
r1   c                    U Vs/ s HW  n[        U5      S:  dC  [        U5      S:X  d  M#  [        US   [        5      (       a  US   R                  5       (       d  MU  UPMY     nnU$ s  snf )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.
rA   r   )r]   rK   rL   r   )r-   r   r   r.  s       r.   r*   PythonParser._remove_empty_linesZ  sj    $ 
D	At9>	 
 $DGS11T!W]]_  	 
 

s   "A'.A'A'c                T    U R                   c  U$ U R                  XR                   SS9$ )Nr   r   searchreplace)r=   _search_replace_num_columnsr-   r   s     r.   _check_thousandsPythonParser._check_thousandsu  s2    >>!L// 0 
 	
r1   c                ~   / nU H  n/ n[        U5       H  u  px[        U[        5      (       aB  X(;  d=  XpR                  ;   d.  U R                  R                  UR                  5       5      (       d  UR                  U5        Mo  UR                  UR                  X#5      5        M     UR                  U5        M     U$ r+   )	r   rK   rL   r'   rl   rI  r   r   rJ  )	r-   r   rI  rJ  r.  r   rC  r   r,   s	            r.   rK  (PythonParser._search_replace_num_columns}  s     DB!$"1c**66688??177955IIaLIIaii89 ( JJrN  
r1   c                h    U R                   [        S   :X  a  U$ U R                  XR                   SS9$ )Nr>   r   rH  )r>   r   rK  rL  s     r.   _check_decimalPythonParser._check_decimal  s9    <<?955L//c 0 
 	
r1   c                    / U l         g r+   )rE   ry   s    r.   r   PythonParser._clear_buffer  s	    r1   c                   U R                   n[        U5      n[        U5      nU R                  b  U R                  nO U R                  5       n U R                  5       nSnUb  U R
                  nUSLa  [        U5      U R                  -
  nUb  U R                  b  USLa  [        U5      [        U5      U R                  -   :X  ay  [        [        [        U5      5      5      U l        U R                  SS U l
        [        U5       H  nUR                  SU5        M     [        U5      n[        U5      U l        X2U4$ US:  a0  SU l        U R
                  c  [        [        U5      5      U l        SnO#U R                  XR
                  5      u  pU l        XU4$ ! [         a    Sn GN^f = f! [         a    Sn GN`f = f)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   FrA   T)rX   rM   r   r   r   r   r]   rR   r   r\   rE   reversedinsertr   _clean_index_names)
r-   rV   rX   r   	next_lineimplicit_first_colsr   r   
index_namerd   s
             r.   rZ   PythonParser._get_index_name  s    '+oo']
w- ($$D(
	)I
   I%&)$i$2K2K&K# %KK+U*y>SY1J1J%JJ%)%D	*:%;DN#xx|DH%d^q!, , "&gJ03GD-W44"#'D ~~%!%e,?&@!AJ /3.E.E/+ZDN w..i !   	I	s#   F F0 F-,F-0G ?G c                    U R                   nU R                  (       a  U[        U R                  5      -  n[	        S U 5       5      nX2:  Ga  U R                  SLGa  U R
                  Gc  U R                  (       a  U R                  OSn/ n[        U5      n[        U5      n/ nU H  u  p[        U	5      n
X:  a  [        U R                  5      (       a)  U R                  U	5      nUb  UR                  U5        MV  MX  U R                  U R                  R                  U R                  R                  4;   aN  U R                  Xx-
  U-   -
  nUR                  X45        U R                  U R                  R                  :X  a    OM  M  UR                  U	5        M     U Hy  u  pSU SUS-    SU
 3nU R                  (       aA  [        U R                  5      S:  a(  U R                   ["        R$                  :w  a
  SnUS	U-   -  nU R'                  XS-   5        M{     [)        [*        R,                  " XS
9R.                  5      nU R
                  (       a  U R0                  c   eU R0                  nU R                  (       aY  [        U5       VVs/ s H?  u  nnU[        U R                  5      :  d  U[        U R                  5      -
  U;   d  M=  UPMA     nnnU$ [        U5       VVs/ s H  u  nnUU;   d  M  UPM     nnnU$ s  snnf s  snnf )Nc              3  8   #    U  H  n[        U5      v   M     g 7fr+   )r]   )r  rows     r.   r  -PythonParser._rows_to_cols.<locals>.<genexpr>  s     2'3c#hh's   Fr   z	Expected z fields in line rA   z, saw zXError could possibly be due to quotes being ignored when a multi-char delimiter is used.r<  )	min_width)rR   r   r]   r   maxr   r2   r   rH   r3  r   r4  r5  r6  rF   r3   r9   r   
QUOTE_NONEr9  rM   r   to_object_arrayTrP   )r-   r   col_lenmax_lenfooters	bad_linesiter_contentcontent_lenr   _content
actual_lennew_lr)  r   r?  zipped_contentr  as                     r.   r   PythonParser._rows_to_cols  s   ++s4>>**G2'22 e+$)-dooaGI$W-Lg,KG+ ]
' 1 122 $ 1 1( ; ,#NN51 -**00660055/  #'((ko.G"H!((')>?,,0H0H0N0NN! O NN8,%  ,( (1#y(81V!l$ 
 NNDNN+a/6G  4&=(C%%cQ;7# (1( c11'MOOP<<$$000++K## !*. 9" 91C//s4>>22kA	  9  "  #,N";"";$!QqK?OA";  " ""s   <LL(L
9L
c                2   U R                   nS nUbU  [        U R                   5      U:  a$  U R                   S U U R                   US  so0l         OU[        U R                   5      -  nUGc  [        U R                  [        5      (       a  U R
                  [        U R                  5      :  a  [        eUc/  U R                  U R
                  S  n[        U R                  5      nO5U R                  U R
                  U R
                  U-    nU R
                  U-   nU R                  U5      nUR                  U5        X@l        GO/ n Ub  SnSnU R
                  b  U R
                  OSnXa:  a^  U R                  c   e[        U R                  5      nU R                  Xu-   5      (       d  US-  nUS-  nUR                  U5        Xa:  a  M^  [        U5      n	U R                  U5      nUR                  U5        O=Sn U R                  U R
                  U-   S-   S9n
US-  nU
b  UR                  U
5        M:  U =R
                  U	-  sl        / U l         OUnU R                  (       a  US U R                  *  nU R                  U5      nU R                  (       a  U R!                  U5      nU R#                  U5      nU R%                  U5      $ ! [         a@    [        U5      n	U R                  U5      nUR                  U5        [        U5      S:X  a  e  Nf = f)Nr   rA   r(  )rE   r]   rK   rD   rM   rF   r   _remove_skipped_rowsr   r,  rI   r   r-  r2   r   r:   r*  rM  rR  )r-   r   r   new_rowsnew_pos	row_indexrow_ctr   r  len_new_rowsnext_rows              r.   r   PythonParser._get_lines?  s    488}$%)XXet_dhhtuo"( DHH%$))T**88c$))n,''<#yy4H!$))nG#yyDHHtODH"hhoG44X>X&" "'$%	!"-1XX-Aq$m $(99#88#8&*499oG#'==1C#D#D &!%NI$OOG4 %m (+8}#'#<#<X#FX. "'+';';DHHtOVWDW';'XH AID'3 ( 9 # L(DHE??,T__,-E$$U+  ,,U3E%%e,""5))' % #&x=L#88BHLL*5zQ '	s    BK -K :=K ALLc                    U R                   (       aD  [        U5       VVs/ s H+  u  p#U R                  X R                  -   5      (       a  M)  UPM-     snn$ U$ s  snnf r+   )r)   r   rI   rF   )r-   ru  r   r`  s       r.   rt  !PythonParser._remove_skipped_rows  sJ    =="+H"5"5T]]1xx<=X"5  s   (AAc                   [        5       nU R                  (       aF  U R                  (       a5  U R                  c   eU R	                  U R                  U R                  5      nU R                  (       Ga  U R
                  (       Ga  U R                  c   e[        U R                  U R                  5       H  u  p#[        U R
                  [        5      (       d+  [        U R
                  5      (       d  UR                  U5        [        U R
                  [        5      (       d  Mp  X0R
                  ;   d  M  [        U R
                  U   5      (       a  [        U R
                  U   5      (       d  M  UR                  U5        M     U$ r+   )r   rV   parse_datesrP   _set_noconvert_dtype_columnsr   ziprK   r   r   addr   )r-   no_thousands_columnsr   r   s       r.   r`   %PythonParser._set_no_thousand_columns  s   ),<<D,,$$000#'#D#D!!4<<$  <<<DJJJ$$000d//>!$**d33<LJJ= = ),,Q/tzz400zz),TZZ_==(C99 ),,Q/ ? $#r1   )!rP   r   r   r[   r'   r_   rE   rW   rV   r?   rD   r>   r3   r6   r5   r;   r   rU   rG   r8   rR   rX   rF   r4   r9   r:   r2   rI   r7   r)   r=   rS   r<   )rb   zReadCsvBuffer[str] | listreturnNone)r  z
re.Pattern)rb   IO[str] | ReadCsvBuffer[str]r+   )r   
int | Noner  Rtuple[Index | None, Sequence[Hashable] | MultiIndex, Mapping[Hashable, ArrayLike]])r   list[np.ndarray]r  z8tuple[Mapping[Hashable, np.ndarray], Sequence[Hashable]])r   r  r  r  )rD   zMapping[Hashable, np.ndarray]r  zMapping[Hashable, ArrayLike])r  bool)r  z9tuple[list[list[Scalar | None]], int, set[Scalar | None]])rV   list[list[Scalar | None]]r  zlist[Scalar | None]rR   r   r  r  )r  list[Scalar])r  r  r  r  )r   r  r  r  )r   rL   r)  r   r  r  )r)  r   r  zlist[Scalar] | Noner   list[list[Scalar]]r  r  )r   r  rI  rL   rJ  rL   r  r  )r  r  )r  z@tuple[Sequence[Hashable] | None, list[Hashable], list[Hashable]])r   r  r  r  )r   r  r  r  )ru  r  r  r  )r  r&   )$rt   ru   rv   rw   __annotations__rC   r   rl   rO   r   r   r   r   r   rQ   r   r   r   r  r%  r   r9  r-  r   r*  rM  rK  rR  r   rZ   r   r   rt  r`   rx   __classcell__)re   s   @r.   r$   r$   G   s   ##]H~ 
! 
!>B "&4040
40l! 
B6 "&$$
$!
+!
 
&!
F  w;	Bw;r  .*. ). "	.
 
#.`%3,j46p4.`*6
'14?B	&
L/	IL/\TlO*b$ $r1   r$   c                  v    \ rS rSrSr  S	             S
S jjrSSS jjr S     SS jjrSS jrSr	g)FixedWidthReaderi  z 
A reader of fixed-width lines.
Nc           	     v   Xl         S U l        U(       a  SU-   OSU l        X@l        US:X  a  U R	                  XeS9U l        OX l        [        U R
                  [        [        45      (       d!  [        S[        U5      R                   35      eU R
                   H  n[        U[        [        45      (       au  [        U5      S:X  af  [        US   [        [        R                  [        S 5      45      (       a4  [        US   [        [        R                  [        S 5      45      (       a  M  [        S	5      e   g )
Nz
z
	 infer)infer_nrowsr)   z;column specifications must be a list or tuple, input was a r  r   rA   zEEach column specification must be 2 element tuple or list of integers)rb   bufferr3   r?   detect_colspecscolspecsrK   r   rM   r   typert   r]   r   r   integer)r-   rb   r  r3   r?   r)   r  colspecs           r.   rC   FixedWidthReader.__init__  s	    '+/8)+iw 00' 1 DM %M$--%77#H~6679 
 }}G7UDM22LA%wqzCT$Z+HIIwqzCT$Z+HII:  %r1   c                    Uc
  [        5       n/ n/ n[        U R                  5       H=  u  pVXR;  a  UR                  U5        UR                  U5        [	        U5      U:  d  M=    O   [        U5      U l        U$ )a1  
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.

)r   r   rb   r   r]   iterr  )r-   r  r)   buffer_rowsdetect_rowsr   r`  s          r.   get_rowsFixedWidthReader.get_rows  sv    2 uH'FA ""3's#;;. ( ;'r1   c           	        SR                  U R                   Vs/ s H  nSU 3PM
     sn5      n[        R                  " SU S35      nU R	                  X5      nU(       d  [        S5      e[        [        [        U5      5      n[        R                  " US-   [        S9nU R                  b-  U V	s/ s H   oR                  U R                  5      S   PM"     nn	U H;  n	UR                  U	5       H#  n
SXR                  5       U
R!                  5       & M%     M=     [        R"                  " US5      nSUS'   [        R$                  " X-  S:H  5      S   n['        [)        US S S	2   USS S	2   5      5      nU$ s  snf s  sn	f )
Nr   \z([^z]+)z(No rows from which to infer column widthrA   )r   r   r  )r   r3   rh   rj   r  r   rc  r   r]   r   zerosr   r?   	partitionfinditerr  r  rollwhererM   r  )r-   r  r)   r,   
delimiterspatternr   rh  maskr`  mshiftededges
edge_pairss                 r.   r   FixedWidthReader.detect_colspecs  sP    WW?11#h?@
**s:,c23}}[3 !KLLc#tn%xx!3/<<#>BCdsMM$,,/2dDCC%%c*,-WWY) +  ''$"
$.Q./2#eCaCj%1+67
! @ Ds   E:3'E?c                P   U R                   b   [        U R                   5      nO[        U R                  5      nU R                   VVs/ s H"  u  p#XU R                  U R                  5      PM$     snn$ ! [         a    S U l         [        U R                  5      n Ndf = fs  snnf r+   )r  r,  r   rb   r  r   r3   )r-   r   from_tos       r.   __next__FixedWidthReader.__next__  s     ;;"$DKK(
 <DHLV%2$$T^^4VV ! $"DFF|$ Ws   A6 	)B"6&BB)r  r  r?   r3   rb   )Nd   )rb   r  r  z(list[tuple[int, int]] | Literal['infer']r3   
str | Noner?   r  r)   set[int] | Noner  r   r  r  r+   )r  r   r)   r  r  	list[str])r  N)r  r   r)   r  r  zlist[tuple[int, int]])r  r  )
rt   ru   rv   rw   __doc__rC   r  r  r  rx   rs   r1   r.   r  r    s     %)$'$ ;$ 	$
 $ "$ $ 
$L$N CG0?	,Wr1   r  c                  6    \ rS rSrSrSS jrS	S jrS
S jrSrg)FixedWidthFieldParseri'  z`
Specialization that Converts fixed-width fields into DataFrames.
See PythonParser for details.
c                    UR                  S5      U l        UR                  S5      U l        [        R                  " X40 UD6  g )Nr  r  )popr  r  r$   rC   )r-   rb   rc   s      r.   rC   FixedWidthFieldParser.__init__-  s6    ,88M2d..r1   c                    [        UU R                  U R                  U R                  U R                  U R
                  5      $ r+   )r  r  r3   r?   r)   r  )r-   rb   s     r.   rO   "FixedWidthFieldParser._make_reader3  s7    MMNNLLMM
 	
r1   c                d    U Vs/ s H  n[        S U 5       5      (       d  M  UPM      sn$ s  snf )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              3  z   #    U  H1  n[        U[        5      (       + =(       d    UR                  5       v   M3     g 7fr+   )rK   rL   r   )r  r>  s     r.   r  <FixedWidthFieldParser._remove_empty_lines.<locals>.<genexpr>G  s(     E1z!S))6QWWY6s   9;)r
  )r-   r   r   s      r.   r*  )FixedWidthFieldParser._remove_empty_lines=  s7     
EEE 
 	
 
s   --)r  r  N)rb   zReadCsvBuffer[str]r  r  )rb   r  r  r  r  )	rt   ru   rv   rw   r  rC   rO   r*  rx   rs   r1   r.   r  r  '  s    
/

r1   r  c                &    [        S U  5       5      $ )Nc              3  :   #    U  H  oS :X  d  Ub  M  Sv   M     g7f)r   NrA   rs   )r  vs     r.   r  #count_empty_vals.<locals>.<genexpr>L  s     7$Qr'Qqq$s   	)sum)valss    r.   r   r   K  s    7$777r1   c                ^    [        U 5      (       d  [        S5      eU S:  a  [        S5      eU $ )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   ra   )r2   s    r.   rJ   rJ   O  s6    * j!!899A~899 r1   )r  r   )r2   r   r  r   ):
__future__r   collectionsr   r   collections.abcr   r   r   r	   r   ior
   rh   typingr   r   r   r   r   r7  numpyr   pandas._libsr   pandas.errorsr   r   r   pandas.util._decoratorsr   pandas.util._exceptionsr   pandas.core.dtypes.commonr   r   r   pandas.core.dtypes.inferencer   pandas.io.commonr   r   pandas.io.parsers.base_parserr   r   pandas._typingr   r   r    pandasr!   r"   r  r$   r  r  r   rJ   rs   r1   r.   <module>r     s    "    	     
 3 4 
 6
   g$: g$T#sWs|| sWl!
L !
H8r1   