File tree 1 file changed +18
-12
lines changed
1 file changed +18
-12
lines changed Original file line number Diff line number Diff line change 43
43
44
44
from pandas .core .dtypes .common import (
45
45
is_bool ,
46
+ is_file_like ,
46
47
is_float ,
47
48
is_integer ,
48
49
is_list_like ,
@@ -1523,20 +1524,25 @@ def __init__(
1523
1524
# Always a string
1524
1525
self ._io = stringify_path (path_or_buffer )
1525
1526
1526
- # Determine xlrd version if installed
1527
- if import_optional_dependency ("xlrd" , errors = "ignore" ) is None :
1528
- xlrd_version = None
1529
- else :
1530
- import xlrd
1531
-
1532
- xlrd_version = Version (get_version (xlrd ))
1533
-
1534
1527
if engine is None :
1535
1528
# Only determine ext if it is needed
1536
- ext : str | None
1537
- if xlrd_version is not None and isinstance (path_or_buffer , xlrd .Book ):
1538
- ext = "xls"
1539
- else :
1529
+ ext : str | None = None
1530
+
1531
+ if not isinstance (
1532
+ path_or_buffer , (str , os .PathLike , ExcelFile )
1533
+ ) and not is_file_like (path_or_buffer ):
1534
+ # GH#56692 - avoid importing xlrd if possible
1535
+ if import_optional_dependency ("xlrd" , errors = "ignore" ) is None :
1536
+ xlrd_version = None
1537
+ else :
1538
+ import xlrd
1539
+
1540
+ xlrd_version = Version (get_version (xlrd ))
1541
+
1542
+ if xlrd_version is not None and isinstance (path_or_buffer , xlrd .Book ):
1543
+ ext = "xls"
1544
+
1545
+ if ext is None :
1540
1546
ext = inspect_excel_format (
1541
1547
content_or_path = path_or_buffer , storage_options = storage_options
1542
1548
)
You can’t perform that action at this time.
0 commit comments