Skip to content

UnsupportedOperation 'seek' when loading excel files from url #20434

Closed
@mcrot

Description

@mcrot

Code Sample, a copy-pastable example if possible

url = 'https://raw.github.com/pandas-dev/pandas/master/pandas/tests/io/data/test1.xls'
pandas.read_excel(url)

Problem description

In my version 0.23.0.dev0+657.g01882ba I get an UnsupportedOperation:

UnsupportedOperation                      Traceback (most recent call last)
<ipython-input-5-71715bfd4345> in <module>()
----> 1 pandas.read_excel(url)

~/prj/pandas-mcrot/pandas/util/_decorators.py in wrapper(*args, **kwargs)
    170                 else:
    171                     kwargs[new_arg_name] = new_arg_value
--> 172             return func(*args, **kwargs)
    173         return wrapper
    174     return _deprecate_kwarg

~/prj/pandas-mcrot/pandas/util/_decorators.py in wrapper(*args, **kwargs)
    170                 else:
    171                     kwargs[new_arg_name] = new_arg_value
--> 172             return func(*args, **kwargs)
    173         return wrapper
    174     return _deprecate_kwarg

~/prj/pandas-mcrot/pandas/io/excel.py in read_excel(io, sheet_name, header, names, index_col, usecols, squeeze, dtype, engine, converters, true_values, false_values, skiprows, nrows, na_values, parse_dates, date_parser, thousands, comment, skipfooter, convert_float, **kwds)
    313 
    314     if not isinstance(io, ExcelFile):
--> 315         io = ExcelFile(io, engine=engine)
    316 
    317     return io._parse_excel(

~/prj/pandas-mcrot/pandas/io/excel.py in __init__(self, io, **kwds)
    390             if hasattr(io, 'seek'):
    391                 # GH 19779
--> 392                 io.seek(0)
    393 
    394             data = io.read()

UnsupportedOperation: seek

The PR #19926 was made in order to fix #19779. It introduced a call of seek() method
only for objects having a that method. In case of giving a URL to pandas.read_excel(),
seek() is called on a HTTPResponse instance and it seems like that it does not support seeking, although the method seek() is available.

This issue is already covered by a test. When running

pytest pandas/tests/io/test_excel.py

the test method TestXlrdReader.test_read_from_http_url fails for the same reason.

Expected Output

In version 0.22 this code returns the data as expected:

Out[4]: 
                   A         B         C         D
2000-01-03  0.980269  3.685731 -0.364217 -1.159738
2000-01-04  1.047916 -0.041232 -0.161812  0.212549
2000-01-05  0.498581  0.731168 -0.537677  1.346270
2000-01-06  1.120202  1.567621  0.003641  0.675253
2000-01-07 -0.487094  0.571455 -1.611639  0.103469
2000-01-10  0.836649  0.246462  0.588543  1.062782
2000-01-11 -0.157161  1.340307  1.195778 -1.097007

Output of pd.show_versions()

INSTALLED VERSIONS

commit: 01882ba
python: 3.6.4.final.0
python-bits: 64
OS: Linux
OS-release: 4.4.0-116-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: de_DE.UTF-8
LOCALE: de_DE.UTF-8

pandas: 0.23.0.dev0+657.g01882ba
pytest: 3.4.2
pip: 9.0.1
setuptools: 38.5.1
Cython: 0.27.3
numpy: 1.14.2
scipy: 1.0.0
pyarrow: 0.8.0
xarray: 0.10.2
IPython: 6.2.1
sphinx: 1.7.1
patsy: 0.5.0
dateutil: 2.7.0
pytz: 2018.3
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.4
feather: 0.4.0
matplotlib: 2.2.2
openpyxl: 2.5.0
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.0.2
lxml: 4.1.1
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.2.5
pymysql: 0.8.0
psycopg2: None
jinja2: 2.10
s3fs: 0.1.3
fastparquet: 0.1.4
pandas_gbq: None
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    IO Excelread_excel, to_excelRegressionFunctionality that used to work in a prior pandas version

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions