Skip to content

Commit 2399688

Browse files
authored
CLN: inspect_excel_format (pandas-dev#39008)
1 parent 47f5fdf commit 2399688

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

pandas/io/excel/_base.py

+8-18
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import datetime
33
from distutils.version import LooseVersion
44
import inspect
5-
from io import BufferedIOBase, BytesIO, RawIOBase
5+
from io import BytesIO
66
import os
77
from textwrap import fill
8-
from typing import IO, Any, Dict, Mapping, Optional, Union, cast
8+
from typing import Any, Dict, Mapping, Optional, Union, cast
99
import warnings
1010
import zipfile
1111

@@ -906,24 +906,18 @@ def close(self):
906906

907907
@doc(storage_options=_shared_docs["storage_options"])
908908
def inspect_excel_format(
909-
path: Optional[str] = None,
910-
content: Union[None, BufferedIOBase, RawIOBase, bytes] = None,
909+
content_or_path: FilePathOrBuffer,
911910
storage_options: StorageOptions = None,
912911
) -> str:
913912
"""
914913
Inspect the path or content of an excel file and get its format.
915914
916-
At least one of path or content must be not None. If both are not None,
917-
content will take precedence.
918-
919915
Adopted from xlrd: https://github.com/python-excel/xlrd.
920916
921917
Parameters
922918
----------
923-
path : str, optional
924-
Path to file to inspect. May be a URL.
925-
content : file-like object, optional
926-
Content of file to inspect.
919+
content_or_path : str or file-like object
920+
Path to file or content of file to inspect. May be a URL.
927921
{storage_options}
928922
929923
Returns
@@ -938,12 +932,8 @@ def inspect_excel_format(
938932
BadZipFile
939933
If resulting stream does not have an XLS signature and is not a valid zipfile.
940934
"""
941-
content_or_path: Union[None, str, BufferedIOBase, RawIOBase, IO[bytes]]
942-
if isinstance(content, bytes):
943-
content_or_path = BytesIO(content)
944-
else:
945-
content_or_path = content or path
946-
assert content_or_path is not None
935+
if isinstance(content_or_path, bytes):
936+
content_or_path = BytesIO(content_or_path)
947937

948938
with get_handle(
949939
content_or_path, "rb", storage_options=storage_options, is_text=False
@@ -1069,7 +1059,7 @@ def __init__(
10691059
ext = "xls"
10701060
else:
10711061
ext = inspect_excel_format(
1072-
content=path_or_buffer, storage_options=storage_options
1062+
content_or_path=path_or_buffer, storage_options=storage_options
10731063
)
10741064

10751065
if engine is None:

0 commit comments

Comments
 (0)