Skip to content

ENH: Add support for s3 in read_excel #11447 #11714

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

Merged
merged 1 commit into from
Dec 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.18.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Other enhancements
^^^^^^^^^^^^^^^^^^

- Handle truncated floats in SAS xport files (:issue:`11713`)
- ``read_excel`` now supports s3 urls of the format ``s3://bucketname/filename`` (:issue:`11447`)

.. _whatsnew_0180.enhancements.rounding:

Expand Down
7 changes: 5 additions & 2 deletions pandas/io/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from pandas.core.frame import DataFrame
from pandas.io.parsers import TextParser
from pandas.io.common import _is_url, _urlopen, _validate_header_arg
from pandas.io.common import _is_url, _urlopen, _validate_header_arg, get_filepath_or_buffer, _is_s3_url
from pandas.tseries.period import Period
from pandas import json
from pandas.compat import (map, zip, reduce, range, lrange, u, add_metaclass,
Expand Down Expand Up @@ -199,7 +199,10 @@ def __init__(self, io, **kwds):
raise ValueError("Unknown engine: %s" % engine)

if isinstance(io, compat.string_types):
if _is_url(io):
if _is_s3_url(io):
buffer, _, _ = get_filepath_or_buffer(io)
self.book = xlrd.open_workbook(file_contents=buffer.read())
elif _is_url(io):
data = _urlopen(io).read()
self.book = xlrd.open_workbook(file_contents=data)
else:
Expand Down
16 changes: 16 additions & 0 deletions pandas/io/tests/test_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ def _skip_if_no_excelsuite():
_skip_if_no_openpyxl()


def _skip_if_no_boto():
try:
import boto # NOQA
except ImportError:
raise nose.SkipTest('boto not installed, skipping')


_seriesd = tm.getSeriesData()
_tsd = tm.getTimeSeriesData()
_frame = DataFrame(_seriesd)[:10]
Expand Down Expand Up @@ -429,6 +436,15 @@ def test_read_from_http_url(self):
local_table = self.get_exceldf('test1')
tm.assert_frame_equal(url_table, local_table)

@tm.network(check_before_test=True)
def test_read_from_s3_url(self):
_skip_if_no_boto()

url = ('s3://pandas-test/test1' + self.ext)
url_table = read_excel(url)
local_table = self.get_exceldf('test1')
tm.assert_frame_equal(url_table, local_table)

@slow
def test_read_from_file_url(self):

Expand Down