Skip to content

Commit c3dae26

Browse files
committed
Use passed encoding to decode bytes
1 parent 8633d23 commit c3dae26

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

pandas/io/parsers.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from pandas.core.frame import DataFrame
1515
import datetime
1616
import pandas.core.common as com
17+
from pandas.core.config import get_option
1718
from pandas import compat
1819
from pandas.io.date_converters import generic_parser
1920
from pandas.io.common import get_filepath_or_buffer
@@ -1921,11 +1922,14 @@ class FixedWidthReader(object):
19211922
"""
19221923
A reader of fixed-width lines.
19231924
"""
1924-
def __init__(self, f, colspecs, filler, thousands=None):
1925+
def __init__(self, f, colspecs, filler, thousands=None, encoding=None):
19251926
self.f = f
19261927
self.colspecs = colspecs
19271928
self.filler = filler # Empty characters between fields.
19281929
self.thousands = thousands
1930+
if encoding is None:
1931+
encoding = get_option('display.encoding')
1932+
self.encoding = encoding
19291933

19301934
if not ( isinstance(colspecs, (tuple, list))):
19311935
raise AssertionError()
@@ -1941,7 +1945,7 @@ def __init__(self, f, colspecs, filler, thousands=None):
19411945
def next(self):
19421946
line = next(self.f)
19431947
if isinstance(line, bytes):
1944-
line = line.decode('utf-8')
1948+
line = line.decode(self.encoding)
19451949
# Note: 'colspecs' is a sequence of half-open intervals.
19461950
return [line[fromm:to].strip(self.filler or ' ')
19471951
for (fromm, to) in self.colspecs]
@@ -1968,7 +1972,8 @@ def __init__(self, f, **kwds):
19681972
PythonParser.__init__(self, f, **kwds)
19691973

19701974
def _make_reader(self, f):
1971-
self.data = FixedWidthReader(f, self.colspecs, self.delimiter)
1975+
self.data = FixedWidthReader(f, self.colspecs, self.delimiter,
1976+
encoding=self.encoding)
19721977

19731978

19741979
##### deprecations in 0.12 #####

0 commit comments

Comments
 (0)