289
289
290
290
.. versionadded:: 2.0
291
291
292
+ engine_kwargs : dict, optional
293
+ Arbitrary keyword arguments passed to excel engine.
294
+
292
295
Returns
293
296
-------
294
297
DataFrame or dict of DataFrames
302
305
read_csv : Read a comma-separated values (csv) file into DataFrame.
303
306
read_fwf : Read a table of fixed-width formatted lines into DataFrame.
304
307
308
+ Notes
309
+ -----
310
+ For specific information on the methods used for each Excel engine, refer to the pandas
311
+ :ref:`user guide <io.excel_reader>`
312
+
305
313
Examples
306
314
--------
307
315
The file can be read using the file name as string or an open file object:
@@ -472,13 +480,21 @@ def read_excel(
472
480
skipfooter : int = 0 ,
473
481
storage_options : StorageOptions = None ,
474
482
dtype_backend : DtypeBackend | lib .NoDefault = lib .no_default ,
483
+ engine_kwargs : dict | None = None ,
475
484
) -> DataFrame | dict [IntStrT , DataFrame ]:
476
485
check_dtype_backend (dtype_backend )
477
-
478
486
should_close = False
487
+ if engine_kwargs is None :
488
+ engine_kwargs = {}
489
+
479
490
if not isinstance (io , ExcelFile ):
480
491
should_close = True
481
- io = ExcelFile (io , storage_options = storage_options , engine = engine )
492
+ io = ExcelFile (
493
+ io ,
494
+ storage_options = storage_options ,
495
+ engine = engine ,
496
+ engine_kwargs = engine_kwargs ,
497
+ )
482
498
elif engine and engine != io .engine :
483
499
raise ValueError (
484
500
"Engine should not be specified when passing "
@@ -520,8 +536,14 @@ def read_excel(
520
536
521
537
class BaseExcelReader (metaclass = abc .ABCMeta ):
522
538
def __init__ (
523
- self , filepath_or_buffer , storage_options : StorageOptions = None
539
+ self ,
540
+ filepath_or_buffer ,
541
+ storage_options : StorageOptions = None ,
542
+ engine_kwargs : dict | None = None ,
524
543
) -> None :
544
+ if engine_kwargs is None :
545
+ engine_kwargs = {}
546
+
525
547
# First argument can also be bytes, so create a buffer
526
548
if isinstance (filepath_or_buffer , bytes ):
527
549
filepath_or_buffer = BytesIO (filepath_or_buffer )
@@ -540,7 +562,7 @@ def __init__(
540
562
# N.B. xlrd.Book has a read attribute too
541
563
self .handles .handle .seek (0 )
542
564
try :
543
- self .book = self .load_workbook (self .handles .handle )
565
+ self .book = self .load_workbook (self .handles .handle , engine_kwargs )
544
566
except Exception :
545
567
self .close ()
546
568
raise
@@ -555,7 +577,7 @@ def _workbook_class(self):
555
577
pass
556
578
557
579
@abc .abstractmethod
558
- def load_workbook (self , filepath_or_buffer ):
580
+ def load_workbook (self , filepath_or_buffer , engine_kwargs ):
559
581
pass
560
582
561
583
def close (self ) -> None :
@@ -1450,6 +1472,8 @@ class ExcelFile:
1450
1472
1451
1473
Please do not report issues when using ``xlrd`` to read ``.xlsx`` files.
1452
1474
This is not supported, switch to using ``openpyxl`` instead.
1475
+ engine_kwargs : dict, optional
1476
+ Arbitrary keyword arguments passed to excel engine.
1453
1477
"""
1454
1478
1455
1479
from pandas .io .excel ._odfreader import ODFReader
@@ -1469,7 +1493,11 @@ def __init__(
1469
1493
path_or_buffer ,
1470
1494
engine : str | None = None ,
1471
1495
storage_options : StorageOptions = None ,
1496
+ engine_kwargs : dict | None = None ,
1472
1497
) -> None :
1498
+ if engine_kwargs is None :
1499
+ engine_kwargs = {}
1500
+
1473
1501
if engine is not None and engine not in self ._engines :
1474
1502
raise ValueError (f"Unknown engine: { engine } " )
1475
1503
@@ -1513,7 +1541,11 @@ def __init__(
1513
1541
self .engine = engine
1514
1542
self .storage_options = storage_options
1515
1543
1516
- self ._reader = self ._engines [engine ](self ._io , storage_options = storage_options )
1544
+ self ._reader = self ._engines [engine ](
1545
+ self ._io ,
1546
+ storage_options = storage_options ,
1547
+ engine_kwargs = engine_kwargs ,
1548
+ )
1517
1549
1518
1550
def __fspath__ (self ):
1519
1551
return self ._io
0 commit comments