Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLN: remove py2-legacy UnicodeReader, UnicodeWriter #30371

Merged
merged 4 commits into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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