33from io import StringIO
44import re
55import sys
6- from typing import Iterator , List , Optional , Set , cast
6+ from typing import DefaultDict , Iterator , List , Optional , Set , Tuple , cast
77
88import numpy as np
99
@@ -118,7 +118,7 @@ def __init__(self, f: Union[FilePathOrBuffer, List], **kwds):
118118 self .columns = self .columns [0 ]
119119
120120 # get popped off for index
121- self .orig_names = list (self .columns )
121+ self .orig_names : List [ Union [ int , str , Tuple ]] = list (self .columns )
122122
123123 # needs to be cleaned/refactored
124124 # multiple date column thing turning into a real spaghetti factory
@@ -236,10 +236,7 @@ def read(self, rows=None):
236236 # done with first read, next time raise StopIteration
237237 self ._first_chunk = False
238238
239- # pandas\io\parsers.py:2480: error: Argument 1 to "list" has
240- # incompatible type "Optional[Any]"; expected "Iterable[Any]"
241- # [arg-type]
242- columns = list (self .orig_names ) # type: ignore[arg-type]
239+ columns = list (self .orig_names )
243240 if not len (content ): # pragma: no cover
244241 # DataFrame with the right metadata, even though it's length 0
245242 names = self ._maybe_dedup_names (self .orig_names )
@@ -292,15 +289,8 @@ def _clean_mapping(mapping):
292289 """converts col numbers to names"""
293290 clean = {}
294291 for col , v in mapping .items ():
295- # pandas\io\parsers.py:2537: error: Unsupported right operand
296- # type for in ("Optional[Any]") [operator]
297- if (
298- isinstance (col , int )
299- and col not in self .orig_names # type: ignore[operator]
300- ):
301- # pandas\io\parsers.py:2538: error: Value of type
302- # "Optional[Any]" is not indexable [index]
303- col = self .orig_names [col ] # type: ignore[index]
292+ if isinstance (col , int ) and col not in self .orig_names :
293+ col = self .orig_names [col ]
304294 clean [col ] = v
305295 return clean
306296
@@ -320,15 +310,8 @@ def _clean_mapping(mapping):
320310 na_value = self .na_values [col ]
321311 na_fvalue = self .na_fvalues [col ]
322312
323- # pandas\io\parsers.py:2558: error: Unsupported right operand
324- # type for in ("Optional[Any]") [operator]
325- if (
326- isinstance (col , int )
327- and col not in self .orig_names # type: ignore[operator]
328- ):
329- # pandas\io\parsers.py:2559: error: Value of type
330- # "Optional[Any]" is not indexable [index]
331- col = self .orig_names [col ] # type: ignore[index]
313+ if isinstance (col , int ) and col not in self .orig_names :
314+ col = self .orig_names [col ]
332315
333316 clean_na_values [col ] = na_value
334317 clean_na_fvalues [col ] = na_fvalue
@@ -349,10 +332,7 @@ def _infer_columns(self):
349332 names = self .names
350333 num_original_columns = 0
351334 clear_buffer = True
352- # pandas\io\parsers.py:2580: error: Need type annotation for
353- # 'unnamed_cols' (hint: "unnamed_cols: Set[<type>] = ...")
354- # [var-annotated]
355- unnamed_cols = set () # type: ignore[var-annotated]
335+ unnamed_cols : Set [Optional [Union [int , str ]]] = set ()
356336
357337 if self .header is not None :
358338 header = self .header
@@ -366,9 +346,7 @@ def _infer_columns(self):
366346 have_mi_columns = False
367347 header = [header ]
368348
369- # pandas\io\parsers.py:2594: error: Need type annotation for
370- # 'columns' (hint: "columns: List[<type>] = ...") [var-annotated]
371- columns = [] # type: ignore[var-annotated]
349+ columns : List [List [Optional [Union [int , str ]]]] = []
372350 for level , hr in enumerate (header ):
373351 try :
374352 line = self ._buffered_line ()
@@ -397,7 +375,7 @@ def _infer_columns(self):
397375
398376 line = self .names [:]
399377
400- this_columns = []
378+ this_columns : List [ Optional [ Union [ int , str ]]] = []
401379 this_unnamed_cols = []
402380
403381 for i , c in enumerate (line ):
@@ -413,9 +391,7 @@ def _infer_columns(self):
413391 this_columns .append (c )
414392
415393 if not have_mi_columns and self .mangle_dupe_cols :
416- # pandas\io\parsers.py:2639: error: Need type annotation
417- # for 'counts' [var-annotated]
418- counts = defaultdict (int ) # type: ignore[var-annotated]
394+ counts : DefaultDict = defaultdict (int )
419395
420396 for i , col in enumerate (this_columns ):
421397 cur_count = counts [col ]
@@ -439,16 +415,10 @@ def _infer_columns(self):
439415
440416 if lc != unnamed_count and lc - ic > unnamed_count :
441417 clear_buffer = False
442- # pandas\io\parsers.py:2663: error: List item 0 has
443- # incompatible type "None"; expected "str"
444- # [list-item]
445- this_columns = [None ] * lc # type: ignore[list-item]
418+ this_columns = [None ] * lc
446419 self .buf = [self .buf [- 1 ]]
447420
448- # pandas\io\parsers.py:2666: error: Argument 1 to "append" of
449- # "list" has incompatible type "List[str]"; expected
450- # "List[None]" [arg-type]
451- columns .append (this_columns ) # type: ignore[arg-type]
421+ columns .append (this_columns )
452422 unnamed_cols .update ({this_columns [i ] for i in this_unnamed_cols })
453423
454424 if len (columns ) == 1 :
@@ -490,19 +460,9 @@ def _infer_columns(self):
490460
491461 if not names :
492462 if self .prefix :
493- # pandas\io\parsers.py:2711: error: List comprehension has
494- # incompatible type List[str]; expected List[None] [misc]
495- columns = [
496- [
497- f"{ self .prefix } { i } " # type: ignore[misc]
498- for i in range (ncols )
499- ]
500- ]
463+ columns = [[f"{ self .prefix } { i } " for i in range (ncols )]]
501464 else :
502- # pandas\io\parsers.py:2713: error: Argument 1 to "list"
503- # has incompatible type "range"; expected "Iterable[None]"
504- # [arg-type]
505- columns = [list (range (ncols ))] # type: ignore[arg-type]
465+ columns = [list (range (ncols ))]
506466 columns = self ._handle_usecols (columns , columns [0 ])
507467 else :
508468 if self .usecols is None or len (names ) >= num_original_columns :
0 commit comments