Skip to content

REGR: read_excel does not work for most file handles #38819

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 2 commits into from
Dec 30, 2020
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/v1.2.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Fixed regressions
- Bug in repr of float-like strings of an ``object`` dtype having trailing 0's truncated after the decimal (:issue:`38708`)
- Fixed regression in :meth:`DataFrame.groupby()` with :class:`Categorical` grouping column not showing unused categories for ``grouped.indices`` (:issue:`38642`)
- Fixed regression in :meth:`DataFrame.any` and :meth:`DataFrame.all` not returning a result for tz-aware ``datetime64`` columns (:issue:`38723`)
- :func:`read_excel` does not work for non-rawbyte file handles (issue:`38788`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect maybe a copy and paste error, should have been :issue:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in #38850

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!

- Bug in :meth:`read_csv` with ``float_precision="high"`` caused segfault or wrong parsing of long exponent strings (:issue:`38753`)
-

Expand Down
9 changes: 2 additions & 7 deletions pandas/io/excel/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1051,16 +1051,11 @@ def __init__(

xlrd_version = LooseVersion(xlrd.__version__)

if isinstance(path_or_buffer, (BufferedIOBase, RawIOBase, bytes)):
ext = inspect_excel_format(
content=path_or_buffer, storage_options=storage_options
)
elif xlrd_version is not None and isinstance(path_or_buffer, xlrd.Book):
if xlrd_version is not None and isinstance(path_or_buffer, xlrd.Book):
ext = "xls"
else:
# path_or_buffer is path-like, use stringified path
ext = inspect_excel_format(
path=str(self._io), storage_options=storage_options
content=path_or_buffer, storage_options=storage_options
)

if engine is None:
Expand Down
16 changes: 16 additions & 0 deletions pandas/tests/io/excel/test_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,22 @@ def test_read_from_s3_url(self, read_ext, s3_resource, s3so):
local_table = pd.read_excel("test1" + read_ext)
tm.assert_frame_equal(url_table, local_table)

def test_read_from_s3_object(self, read_ext, s3_resource, s3so):
# GH 38788
# Bucket "pandas-test" created in tests/io/conftest.py
with open("test1" + read_ext, "rb") as f:
s3_resource.Bucket("pandas-test").put_object(Key="test1" + read_ext, Body=f)

import s3fs

s3 = s3fs.S3FileSystem(**s3so)

with s3.open("s3://pandas-test/test1" + read_ext) as f:
url_table = pd.read_excel(f)

local_table = pd.read_excel("test1" + read_ext)
tm.assert_frame_equal(url_table, local_table)

@pytest.mark.slow
def test_read_from_file_url(self, read_ext, datapath):

Expand Down