1+ from __future__ import annotations
2+
13from collections import defaultdict
24import csv
35import datetime
68 Any ,
79 Callable ,
810 DefaultDict ,
9- Dict ,
1011 Iterable ,
11- List ,
12- Optional ,
1312 Sequence ,
14- Set ,
15- Tuple ,
16- Union ,
1713 cast ,
1814)
1915import warnings
@@ -122,12 +118,12 @@ class ParserBase:
122118 def __init__ (self , kwds ):
123119
124120 self .names = kwds .get ("names" )
125- self .orig_names : Optional [ List ] = None
121+ self .orig_names : list | None = None
126122 self .prefix = kwds .pop ("prefix" , None )
127123
128124 self .index_col = kwds .get ("index_col" , None )
129- self .unnamed_cols : Set = set ()
130- self .index_names : Optional [ List ] = None
125+ self .unnamed_cols : set = set ()
126+ self .index_names : list | None = None
131127 self .col_names = None
132128
133129 self .parse_dates = _validate_parse_dates_arg (kwds .pop ("parse_dates" , False ))
@@ -205,9 +201,9 @@ def __init__(self, kwds):
205201
206202 self .usecols , self .usecols_dtype = self ._validate_usecols_arg (kwds ["usecols" ])
207203
208- self .handles : Optional [ IOHandles ] = None
204+ self .handles : IOHandles | None = None
209205
210- def _open_handles (self , src : FilePathOrBuffer , kwds : Dict [str , Any ]) -> None :
206+ def _open_handles (self , src : FilePathOrBuffer , kwds : dict [str , Any ]) -> None :
211207 """
212208 Let the readers open IOHanldes after they are done with their potential raises.
213209 """
@@ -221,7 +217,7 @@ def _open_handles(self, src: FilePathOrBuffer, kwds: Dict[str, Any]) -> None:
221217 errors = kwds .get ("encoding_errors" , "strict" ),
222218 )
223219
224- def _validate_parse_dates_presence (self , columns : List [str ]) -> None :
220+ def _validate_parse_dates_presence (self , columns : list [str ]) -> None :
225221 """
226222 Check if parse_dates are in columns.
227223
@@ -371,7 +367,7 @@ def _maybe_dedup_names(self, names):
371367 # would be nice!
372368 if self .mangle_dupe_cols :
373369 names = list (names ) # so we can index
374- counts : DefaultDict [Union [ int , str , Tuple ] , int ] = defaultdict (int )
370+ counts : DefaultDict [int | str | tuple , int ] = defaultdict (int )
375371 is_potential_mi = _is_potential_multi_index (names , self .index_col )
376372
377373 for i , col in enumerate (names ):
@@ -596,8 +592,8 @@ def _convert_to_ndarrays(
596592
597593 @final
598594 def _set_noconvert_dtype_columns (
599- self , col_indices : List [int ], names : List [ Union [ int , str , Tuple ] ]
600- ) -> Set [int ]:
595+ self , col_indices : list [int ], names : list [ int | str | tuple ]
596+ ) -> set [int ]:
601597 """
602598 Set the columns that should not undergo dtype conversions.
603599
@@ -615,7 +611,7 @@ def _set_noconvert_dtype_columns(
615611 -------
616612 A set of integers containing the positions of the columns not to convert.
617613 """
618- usecols : Optional [ Union [ List [ int ], List [str ]]]
614+ usecols : list [ int ] | list [str ] | None
619615 noconvert_columns = set ()
620616 if self .usecols_dtype == "integer" :
621617 # A set of integers will be converted to a list in
@@ -900,7 +896,7 @@ def _clean_index_names(self, columns, index_col, unnamed_cols):
900896 return [None ] * len (index_col ), columns , index_col
901897
902898 cp_cols = list (columns )
903- index_names : List [ Optional [ Union [ int , str ]] ] = []
899+ index_names : list [ str | int | None ] = []
904900
905901 # don't mutate
906902 index_col = list (index_col )
@@ -926,7 +922,7 @@ def _clean_index_names(self, columns, index_col, unnamed_cols):
926922 return index_names , columns , index_col
927923
928924 def _get_empty_meta (
929- self , columns , index_col , index_names , dtype : Optional [ DtypeArg ] = None
925+ self , columns , index_col , index_names , dtype : DtypeArg | None = None
930926 ):
931927 columns = list (columns )
932928
@@ -1150,7 +1146,7 @@ def _get_na_values(col, na_values, na_fvalues, keep_default_na):
11501146
11511147
11521148def _is_potential_multi_index (
1153- columns , index_col : Optional [ Union [ bool , Sequence [int ]]] = None
1149+ columns , index_col : bool | Sequence [int ] | None = None
11541150) -> bool :
11551151 """
11561152 Check whether or not the `columns` parameter
0 commit comments