14
14
from pandas .core .frame import DataFrame
15
15
import datetime
16
16
import pandas .core .common as com
17
+ from pandas .core .config import get_option
17
18
from pandas import compat
18
19
from pandas .io .date_converters import generic_parser
19
20
from pandas .io .common import get_filepath_or_buffer
@@ -1921,11 +1922,14 @@ class FixedWidthReader(object):
1921
1922
"""
1922
1923
A reader of fixed-width lines.
1923
1924
"""
1924
- def __init__ (self , f , colspecs , filler , thousands = None ):
1925
+ def __init__ (self , f , colspecs , filler , thousands = None , encoding = None ):
1925
1926
self .f = f
1926
1927
self .colspecs = colspecs
1927
1928
self .filler = filler # Empty characters between fields.
1928
1929
self .thousands = thousands
1930
+ if encoding is None :
1931
+ encoding = get_option ('display.encoding' )
1932
+ self .encoding = encoding
1929
1933
1930
1934
if not ( isinstance (colspecs , (tuple , list ))):
1931
1935
raise AssertionError ()
@@ -1941,7 +1945,7 @@ def __init__(self, f, colspecs, filler, thousands=None):
1941
1945
def next (self ):
1942
1946
line = next (self .f )
1943
1947
if isinstance (line , bytes ):
1944
- line = line .decode ('utf-8' )
1948
+ line = line .decode (self . encoding )
1945
1949
# Note: 'colspecs' is a sequence of half-open intervals.
1946
1950
return [line [fromm :to ].strip (self .filler or ' ' )
1947
1951
for (fromm , to ) in self .colspecs ]
@@ -1968,7 +1972,8 @@ def __init__(self, f, **kwds):
1968
1972
PythonParser .__init__ (self , f , ** kwds )
1969
1973
1970
1974
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 )
1972
1977
1973
1978
1974
1979
##### deprecations in 0.12 #####
0 commit comments