diff --git a/pandas/io/common.py b/pandas/io/common.py index 7151a34cd37de..c62de76286610 100644 --- a/pandas/io/common.py +++ b/pandas/io/common.py @@ -2,7 +2,6 @@ import bz2 import codecs -import csv import gzip from io import BufferedIOBase, BytesIO import mmap @@ -17,9 +16,7 @@ List, Mapping, Optional, - TextIO, Tuple, - Type, Union, ) from urllib.parse import ( # noqa @@ -574,16 +571,3 @@ def next(self) -> bytes: def close(self): self.reader.close() - - -# Keeping these class for now because it provides a necessary convenience -# for "dropping" the "encoding" argument from our I/O arguments when -# creating a Unicode I/O object. -def UnicodeReader(f, dialect=csv.excel, encoding="utf-8", **kwds): - return csv.reader(f, dialect=dialect, **kwds) - - -def UnicodeWriter( - f: TextIO, dialect: Type[csv.Dialect] = csv.excel, encoding: str = "utf-8", **kwds -): - return csv.writer(f, dialect=dialect, **kwds) diff --git a/pandas/io/formats/csvs.py b/pandas/io/formats/csvs.py index c0071028a8ef4..3a91d65ab4562 100644 --- a/pandas/io/formats/csvs.py +++ b/pandas/io/formats/csvs.py @@ -5,7 +5,7 @@ import csv as csvlib from io import StringIO import os -from typing import Any, Dict, List +from typing import List import warnings from zipfile import ZipFile @@ -22,7 +22,6 @@ from pandas.core.dtypes.missing import notna from pandas.io.common import ( - UnicodeWriter, get_compression_method, get_filepath_or_buffer, get_handle, @@ -188,7 +187,9 @@ def save(self): close = True try: - writer_kwargs: Dict[str, Any] = dict( + # Note: self.encoding is irrelevant here + self.writer = csvlib.writer( + f, lineterminator=self.line_terminator, delimiter=self.sep, quoting=self.quoting, @@ -196,10 +197,6 @@ def save(self): escapechar=self.escapechar, quotechar=self.quotechar, ) - if self.encoding == "ascii": - self.writer = csvlib.writer(f, **writer_kwargs) - else: - self.writer = UnicodeWriter(f, encoding=self.encoding, **writer_kwargs) self._save() diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index cc3d2bd12ca35..37cd36a2be3bc 100755 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -63,7 +63,6 @@ from pandas.io.common import ( BaseIterator, - UnicodeReader, UTF8Recoder, get_filepath_or_buffer, get_handle, @@ -2431,23 +2430,13 @@ class MyDialect(csv.Dialect): self.line_pos += 1 sniffed = csv.Sniffer().sniff(line) dia.delimiter = sniffed.delimiter - if self.encoding is not None: - self.buf.extend( - list( - UnicodeReader( - StringIO(line), dialect=dia, encoding=self.encoding - ) - ) - ) - else: - self.buf.extend(list(csv.reader(StringIO(line), dialect=dia))) - if self.encoding is not None: - reader = UnicodeReader( - f, dialect=dia, encoding=self.encoding, strict=True - ) - else: - reader = csv.reader(f, dialect=dia, strict=True) + # Note: self.encoding is irrelevant here + line_rdr = csv.reader(StringIO(line), dialect=dia) + self.buf.extend(list(line_rdr)) + + # Note: self.encoding is irrelevant here + reader = csv.reader(f, dialect=dia, strict=True) else: