Skip to content

Commit

Permalink
CLN: remove py2-legacy UnicodeReader, UnicodeWriter (#30371)
Browse files Browse the repository at this point in the history
* CLN: remove py2-legacy UnicodeReader, UnicodeWriter

* remove unnecessar y writer_kwargs
  • Loading branch information
jbrockmendel authored Dec 20, 2019
1 parent 0df8858 commit 0cd388f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 40 deletions.
16 changes: 0 additions & 16 deletions pandas/io/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import bz2
import codecs
import csv
import gzip
from io import BufferedIOBase, BytesIO
import mmap
Expand All @@ -17,9 +16,7 @@
List,
Mapping,
Optional,
TextIO,
Tuple,
Type,
Union,
)
from urllib.parse import ( # noqa
Expand Down Expand Up @@ -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)
11 changes: 4 additions & 7 deletions pandas/io/formats/csvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
Expand Down Expand Up @@ -188,18 +187,16 @@ 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,
doublequote=self.doublequote,
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()

Expand Down
23 changes: 6 additions & 17 deletions pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@

from pandas.io.common import (
BaseIterator,
UnicodeReader,
UTF8Recoder,
get_filepath_or_buffer,
get_handle,
Expand Down Expand Up @@ -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:

Expand Down

0 comments on commit 0cd388f

Please sign in to comment.