Skip to content

Commit 475fcd2

Browse files
committed
BUG: ignore encoding option when writing csv in python 3, GH #738
1 parent 3c6a1da commit 475fcd2

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

pandas/core/common.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -850,25 +850,27 @@ def __iter__(self):
850850
def next(self):
851851
return self.reader.next().encode("utf-8")
852852

853-
class UnicodeReader:
854-
"""
855-
A CSV reader which will iterate over lines in the CSV file "f",
856-
which is encoded in the given encoding.
857-
858-
On Python 3, this is replaced (below) by csv.reader, which handles unicode.
859-
"""
860-
861-
def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds):
862-
f = UTF8Recoder(f, encoding)
863-
self.reader = csv.reader(f, dialect=dialect, **kwds)
853+
if py3compat.PY3: # pragma: no cover
854+
def UnicodeReader(f, dialect=csv.excel, encoding="utf-8", **kwds):
855+
# ignore encoding
856+
return csv.reader(f, dialect=csv.excel, **kwds)
857+
else:
858+
class UnicodeReader:
859+
"""
860+
A CSV reader which will iterate over lines in the CSV file "f",
861+
which is encoded in the given encoding.
864862
865-
def next(self):
866-
row = self.reader.next()
867-
return [unicode(s, "utf-8") for s in row]
863+
On Python 3, this is replaced (below) by csv.reader, which handles
864+
unicode.
865+
"""
868866

869-
def __iter__(self): # pragma: no cover
870-
return self
867+
def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds):
868+
f = UTF8Recoder(f, encoding)
869+
self.reader = csv.reader(f, dialect=dialect, **kwds)
871870

872-
if py3compat.PY3: # pragma: no cover
873-
UnicodeReader = csv.reader
871+
def next(self):
872+
row = self.reader.next()
873+
return [unicode(s, "utf-8") for s in row]
874874

875+
def __iter__(self): # pragma: no cover
876+
return self

0 commit comments

Comments
 (0)