File tree Expand file tree Collapse file tree 3 files changed +10
-40
lines changed Expand file tree Collapse file tree 3 files changed +10
-40
lines changed Original file line number Diff line number Diff line change 22
33import bz2
44import codecs
5- import csv
65import gzip
76from io import BufferedIOBase , BytesIO
87import mmap
1716 List ,
1817 Mapping ,
1918 Optional ,
20- TextIO ,
2119 Tuple ,
22- Type ,
2320 Union ,
2421)
2522from urllib .parse import ( # noqa
@@ -574,16 +571,3 @@ def next(self) -> bytes:
574571
575572 def close (self ):
576573 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 55import csv as csvlib
66from io import StringIO
77import os
8- from typing import Any , Dict , List
8+ from typing import List
99import warnings
1010from zipfile import ZipFile
1111
2222from pandas .core .dtypes .missing import notna
2323
2424from pandas .io .common import (
25- UnicodeWriter ,
2625 get_compression_method ,
2726 get_filepath_or_buffer ,
2827 get_handle ,
@@ -188,18 +187,16 @@ def save(self):
188187 close = True
189188
190189 try :
191- writer_kwargs : Dict [str , Any ] = dict (
190+ # Note: self.encoding is irrelevant here
191+ self .writer = csvlib .writer (
192+ f ,
192193 lineterminator = self .line_terminator ,
193194 delimiter = self .sep ,
194195 quoting = self .quoting ,
195196 doublequote = self .doublequote ,
196197 escapechar = self .escapechar ,
197198 quotechar = self .quotechar ,
198199 )
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 )
203200
204201 self ._save ()
205202
Original file line number Diff line number Diff line change 6363
6464from pandas .io .common import (
6565 BaseIterator ,
66- UnicodeReader ,
6766 UTF8Recoder ,
6867 get_filepath_or_buffer ,
6968 get_handle ,
@@ -2431,23 +2430,13 @@ class MyDialect(csv.Dialect):
24312430 self .line_pos += 1
24322431 sniffed = csv .Sniffer ().sniff (line )
24332432 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 )))
24442433
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 )
24512440
24522441 else :
24532442
You can’t perform that action at this time.
0 commit comments