File tree 3 files changed +10
-40
lines changed
3 files changed +10
-40
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import bz2
4
4
import codecs
5
- import csv
6
5
import gzip
7
6
from io import BufferedIOBase , BytesIO
8
7
import mmap
17
16
List ,
18
17
Mapping ,
19
18
Optional ,
20
- TextIO ,
21
19
Tuple ,
22
- Type ,
23
20
Union ,
24
21
)
25
22
from urllib .parse import ( # noqa
@@ -574,16 +571,3 @@ def next(self) -> bytes:
574
571
575
572
def close (self ):
576
573
self .reader .close ()
577
-
578
-
579
- # Keeping these class for now because it provides a necessary convenience
580
- # for "dropping" the "encoding" argument from our I/O arguments when
581
- # creating a Unicode I/O object.
582
- def UnicodeReader (f , dialect = csv .excel , encoding = "utf-8" , ** kwds ):
583
- return csv .reader (f , dialect = dialect , ** kwds )
584
-
585
-
586
- def UnicodeWriter (
587
- f : TextIO , dialect : Type [csv .Dialect ] = csv .excel , encoding : str = "utf-8" , ** kwds
588
- ):
589
- return csv .writer (f , dialect = dialect , ** kwds )
Original file line number Diff line number Diff line change 5
5
import csv as csvlib
6
6
from io import StringIO
7
7
import os
8
- from typing import Any , Dict , List
8
+ from typing import List
9
9
import warnings
10
10
from zipfile import ZipFile
11
11
22
22
from pandas .core .dtypes .missing import notna
23
23
24
24
from pandas .io .common import (
25
- UnicodeWriter ,
26
25
get_compression_method ,
27
26
get_filepath_or_buffer ,
28
27
get_handle ,
@@ -188,18 +187,16 @@ def save(self):
188
187
close = True
189
188
190
189
try :
191
- writer_kwargs : Dict [str , Any ] = dict (
190
+ # Note: self.encoding is irrelevant here
191
+ self .writer = csvlib .writer (
192
+ f ,
192
193
lineterminator = self .line_terminator ,
193
194
delimiter = self .sep ,
194
195
quoting = self .quoting ,
195
196
doublequote = self .doublequote ,
196
197
escapechar = self .escapechar ,
197
198
quotechar = self .quotechar ,
198
199
)
199
- if self .encoding == "ascii" :
200
- self .writer = csvlib .writer (f , ** writer_kwargs )
201
- else :
202
- self .writer = UnicodeWriter (f , encoding = self .encoding , ** writer_kwargs )
203
200
204
201
self ._save ()
205
202
Original file line number Diff line number Diff line change 63
63
64
64
from pandas .io .common import (
65
65
BaseIterator ,
66
- UnicodeReader ,
67
66
UTF8Recoder ,
68
67
get_filepath_or_buffer ,
69
68
get_handle ,
@@ -2431,23 +2430,13 @@ class MyDialect(csv.Dialect):
2431
2430
self .line_pos += 1
2432
2431
sniffed = csv .Sniffer ().sniff (line )
2433
2432
dia .delimiter = sniffed .delimiter
2434
- if self .encoding is not None :
2435
- self .buf .extend (
2436
- list (
2437
- UnicodeReader (
2438
- StringIO (line ), dialect = dia , encoding = self .encoding
2439
- )
2440
- )
2441
- )
2442
- else :
2443
- self .buf .extend (list (csv .reader (StringIO (line ), dialect = dia )))
2444
2433
2445
- if self .encoding is not None :
2446
- reader = UnicodeReader (
2447
- f , dialect = dia , encoding = self .encoding , strict = True
2448
- )
2449
- else :
2450
- reader = csv .reader (f , dialect = dia , strict = True )
2434
+ # Note: self.encoding is irrelevant here
2435
+ line_rdr = csv . reader ( StringIO ( line ), dialect = dia )
2436
+ self .buf . extend ( list ( line_rdr ))
2437
+
2438
+ # Note: self.encoding is irrelevant here
2439
+ reader = csv .reader (f , dialect = dia , strict = True )
2451
2440
2452
2441
else :
2453
2442
You can’t perform that action at this time.
0 commit comments