Skip to content

CLN: inspect_excel_format #39008

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
Jan 8, 2021
Merged
Changes from 1 commit
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
21 changes: 6 additions & 15 deletions pandas/io/excel/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,24 +906,18 @@ def close(self):

@doc(storage_options=_shared_docs["storage_options"])
def inspect_excel_format(
path: Optional[str] = None,
content: Union[None, BufferedIOBase, RawIOBase, bytes] = None,
content_or_path: Union[None, str, BufferedIOBase, RawIOBase, IO[bytes]] = None,
Copy link
Member

Choose a reason for hiding this comment

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

I don't think the default value or type None is necessary here, is that right?

Copy link
Contributor

Choose a reason for hiding this comment

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

could just be Buffer? (and I would call the arg buffer)

storage_options: StorageOptions = None,
) -> str:
"""
Inspect the path or content of an excel file and get its format.

At least one of path or content must be not None. If both are not None,
content will take precedence.

Adopted from xlrd: https://github.com/python-excel/xlrd.

Parameters
----------
path : str, optional
Path to file to inspect. May be a URL.
content : file-like object, optional
Content of file to inspect.
content_or_path : str or file-like object
Path to file or content of file to inspect. May be a URL.
{storage_options}

Returns
Expand All @@ -938,12 +932,9 @@ def inspect_excel_format(
BadZipFile
If resulting stream does not have an XLS signature and is not a valid zipfile.
"""
content_or_path: Union[None, str, BufferedIOBase, RawIOBase, IO[bytes]]
if isinstance(content, bytes):
content_or_path = BytesIO(content)
else:
content_or_path = content or path
assert content_or_path is not None
Copy link
Member

Choose a reason for hiding this comment

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

With the above, would be okay to remove this line.

if isinstance(content_or_path, bytes):
content_or_path = BytesIO(content_or_path)

with get_handle(
content_or_path, "rb", storage_options=storage_options, is_text=False
Expand Down Expand Up @@ -1069,7 +1060,7 @@ def __init__(
ext = "xls"
else:
ext = inspect_excel_format(
content=path_or_buffer, storage_options=storage_options
content_or_path=path_or_buffer, storage_options=storage_options
)

if engine is None:
Expand Down