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 1 commit
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 @@ -597,16 +594,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)
7 changes: 2 additions & 5 deletions pandas/io/formats/csvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from pandas.core.dtypes.missing import notna

from pandas.io.common import (
UnicodeWriter,
_get_compression_method,
_get_handle,
_infer_compression,
Expand Down Expand Up @@ -196,10 +195,8 @@ 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)
# Note: self.encoding is irrelevant here
self.writer = csvlib.writer(f, **writer_kwargs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need to create writer_kwargs dict up-front now?


self._save()

Expand Down
25 changes: 7 additions & 18 deletions pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
is_categorical_dtype,
is_dtype_equal,
is_extension_array_dtype,
is_file_like,
is_float,
is_integer,
is_integer_dtype,
Expand Down Expand Up @@ -62,13 +63,11 @@
from pandas.io.common import (
_NA_VALUES,
BaseIterator,
UnicodeReader,
UTF8Recoder,
_get_handle,
_infer_compression,
_validate_header_arg,
get_filepath_or_buffer,
is_file_like,
)
from pandas.io.date_converters import generic_parser

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