2
2
import datetime
3
3
from distutils .version import LooseVersion
4
4
import inspect
5
- from io import BufferedIOBase , BytesIO , RawIOBase
5
+ from io import BytesIO
6
6
import os
7
7
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
9
9
import warnings
10
10
import zipfile
11
11
@@ -906,24 +906,18 @@ def close(self):
906
906
907
907
@doc (storage_options = _shared_docs ["storage_options" ])
908
908
def inspect_excel_format (
909
- path : Optional [str ] = None ,
910
- content : Union [None , BufferedIOBase , RawIOBase , bytes ] = None ,
909
+ content_or_path : FilePathOrBuffer ,
911
910
storage_options : StorageOptions = None ,
912
911
) -> str :
913
912
"""
914
913
Inspect the path or content of an excel file and get its format.
915
914
916
- At least one of path or content must be not None. If both are not None,
917
- content will take precedence.
918
-
919
915
Adopted from xlrd: https://github.com/python-excel/xlrd.
920
916
921
917
Parameters
922
918
----------
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.
927
921
{storage_options}
928
922
929
923
Returns
@@ -938,12 +932,8 @@ def inspect_excel_format(
938
932
BadZipFile
939
933
If resulting stream does not have an XLS signature and is not a valid zipfile.
940
934
"""
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 )
947
937
948
938
with get_handle (
949
939
content_or_path , "rb" , storage_options = storage_options , is_text = False
@@ -1069,7 +1059,7 @@ def __init__(
1069
1059
ext = "xls"
1070
1060
else :
1071
1061
ext = inspect_excel_format (
1072
- content = path_or_buffer , storage_options = storage_options
1062
+ content_or_path = path_or_buffer , storage_options = storage_options
1073
1063
)
1074
1064
1075
1065
if engine is None :
0 commit comments