1
+ from __future__ import annotations
2
+
1
3
from collections import defaultdict
2
4
import csv
3
5
import datetime
6
8
Any ,
7
9
Callable ,
8
10
DefaultDict ,
9
- Dict ,
10
11
Iterable ,
11
- List ,
12
- Optional ,
13
12
Sequence ,
14
- Set ,
15
- Tuple ,
16
- Union ,
17
13
cast ,
18
14
)
19
15
import warnings
@@ -122,12 +118,12 @@ class ParserBase:
122
118
def __init__ (self , kwds ):
123
119
124
120
self .names = kwds .get ("names" )
125
- self .orig_names : Optional [ List ] = None
121
+ self .orig_names : list | None = None
126
122
self .prefix = kwds .pop ("prefix" , None )
127
123
128
124
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
131
127
self .col_names = None
132
128
133
129
self .parse_dates = _validate_parse_dates_arg (kwds .pop ("parse_dates" , False ))
@@ -205,9 +201,9 @@ def __init__(self, kwds):
205
201
206
202
self .usecols , self .usecols_dtype = self ._validate_usecols_arg (kwds ["usecols" ])
207
203
208
- self .handles : Optional [ IOHandles ] = None
204
+ self .handles : IOHandles | None = None
209
205
210
- def _open_handles (self , src : FilePathOrBuffer , kwds : Dict [str , Any ]) -> None :
206
+ def _open_handles (self , src : FilePathOrBuffer , kwds : dict [str , Any ]) -> None :
211
207
"""
212
208
Let the readers open IOHanldes after they are done with their potential raises.
213
209
"""
@@ -221,7 +217,7 @@ def _open_handles(self, src: FilePathOrBuffer, kwds: Dict[str, Any]) -> None:
221
217
errors = kwds .get ("encoding_errors" , "strict" ),
222
218
)
223
219
224
- def _validate_parse_dates_presence (self , columns : List [str ]) -> None :
220
+ def _validate_parse_dates_presence (self , columns : list [str ]) -> None :
225
221
"""
226
222
Check if parse_dates are in columns.
227
223
@@ -371,7 +367,7 @@ def _maybe_dedup_names(self, names):
371
367
# would be nice!
372
368
if self .mangle_dupe_cols :
373
369
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 )
375
371
is_potential_mi = _is_potential_multi_index (names , self .index_col )
376
372
377
373
for i , col in enumerate (names ):
@@ -596,8 +592,8 @@ def _convert_to_ndarrays(
596
592
597
593
@final
598
594
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 ]:
601
597
"""
602
598
Set the columns that should not undergo dtype conversions.
603
599
@@ -615,7 +611,7 @@ def _set_noconvert_dtype_columns(
615
611
-------
616
612
A set of integers containing the positions of the columns not to convert.
617
613
"""
618
- usecols : Optional [ Union [ List [ int ], List [str ]]]
614
+ usecols : list [ int ] | list [str ] | None
619
615
noconvert_columns = set ()
620
616
if self .usecols_dtype == "integer" :
621
617
# 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):
900
896
return [None ] * len (index_col ), columns , index_col
901
897
902
898
cp_cols = list (columns )
903
- index_names : List [ Optional [ Union [ int , str ]] ] = []
899
+ index_names : list [ str | int | None ] = []
904
900
905
901
# don't mutate
906
902
index_col = list (index_col )
@@ -926,7 +922,7 @@ def _clean_index_names(self, columns, index_col, unnamed_cols):
926
922
return index_names , columns , index_col
927
923
928
924
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
930
926
):
931
927
columns = list (columns )
932
928
@@ -1150,7 +1146,7 @@ def _get_na_values(col, na_values, na_fvalues, keep_default_na):
1150
1146
1151
1147
1152
1148
def _is_potential_multi_index (
1153
- columns , index_col : Optional [ Union [ bool , Sequence [int ]]] = None
1149
+ columns , index_col : bool | Sequence [int ] | None = None
1154
1150
) -> bool :
1155
1151
"""
1156
1152
Check whether or not the `columns` parameter
0 commit comments