3
3
from io import StringIO
4
4
import re
5
5
import sys
6
- from typing import Iterator , List , Optional , Set , cast
6
+ from typing import DefaultDict , Iterator , List , Optional , Set , Tuple , cast
7
7
8
8
import numpy as np
9
9
@@ -118,7 +118,7 @@ def __init__(self, f: Union[FilePathOrBuffer, List], **kwds):
118
118
self .columns = self .columns [0 ]
119
119
120
120
# get popped off for index
121
- self .orig_names = list (self .columns )
121
+ self .orig_names : List [ Union [ int , str , Tuple ]] = list (self .columns )
122
122
123
123
# needs to be cleaned/refactored
124
124
# multiple date column thing turning into a real spaghetti factory
@@ -236,10 +236,7 @@ def read(self, rows=None):
236
236
# done with first read, next time raise StopIteration
237
237
self ._first_chunk = False
238
238
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 )
243
240
if not len (content ): # pragma: no cover
244
241
# DataFrame with the right metadata, even though it's length 0
245
242
names = self ._maybe_dedup_names (self .orig_names )
@@ -292,15 +289,8 @@ def _clean_mapping(mapping):
292
289
"""converts col numbers to names"""
293
290
clean = {}
294
291
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 ]
304
294
clean [col ] = v
305
295
return clean
306
296
@@ -320,15 +310,8 @@ def _clean_mapping(mapping):
320
310
na_value = self .na_values [col ]
321
311
na_fvalue = self .na_fvalues [col ]
322
312
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 ]
332
315
333
316
clean_na_values [col ] = na_value
334
317
clean_na_fvalues [col ] = na_fvalue
@@ -349,10 +332,7 @@ def _infer_columns(self):
349
332
names = self .names
350
333
num_original_columns = 0
351
334
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 ()
356
336
357
337
if self .header is not None :
358
338
header = self .header
@@ -366,9 +346,7 @@ def _infer_columns(self):
366
346
have_mi_columns = False
367
347
header = [header ]
368
348
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 ]]]] = []
372
350
for level , hr in enumerate (header ):
373
351
try :
374
352
line = self ._buffered_line ()
@@ -397,7 +375,7 @@ def _infer_columns(self):
397
375
398
376
line = self .names [:]
399
377
400
- this_columns = []
378
+ this_columns : List [ Optional [ Union [ int , str ]]] = []
401
379
this_unnamed_cols = []
402
380
403
381
for i , c in enumerate (line ):
@@ -413,9 +391,7 @@ def _infer_columns(self):
413
391
this_columns .append (c )
414
392
415
393
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 )
419
395
420
396
for i , col in enumerate (this_columns ):
421
397
cur_count = counts [col ]
@@ -439,16 +415,10 @@ def _infer_columns(self):
439
415
440
416
if lc != unnamed_count and lc - ic > unnamed_count :
441
417
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
446
419
self .buf = [self .buf [- 1 ]]
447
420
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 )
452
422
unnamed_cols .update ({this_columns [i ] for i in this_unnamed_cols })
453
423
454
424
if len (columns ) == 1 :
@@ -490,19 +460,9 @@ def _infer_columns(self):
490
460
491
461
if not names :
492
462
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 )]]
501
464
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 ))]
506
466
columns = self ._handle_usecols (columns , columns [0 ])
507
467
else :
508
468
if self .usecols is None or len (names ) >= num_original_columns :
0 commit comments