3
3
from io import BufferedIOBase , BytesIO , RawIOBase
4
4
import os
5
5
from textwrap import fill
6
- from typing import Any , Mapping , Union
6
+ from typing import Any , Dict , Mapping , Union , cast
7
7
8
8
from pandas ._config import config
9
9
10
10
from pandas ._libs .parsers import STR_NA_VALUES
11
- from pandas ._typing import StorageOptions
11
+ from pandas ._typing import Buffer , FilePathOrBuffer , StorageOptions
12
12
from pandas .errors import EmptyDataError
13
13
from pandas .util ._decorators import Appender , deprecate_nonkeyword_arguments
14
14
@@ -567,6 +567,12 @@ class ExcelWriter(metaclass=abc.ABCMeta):
567
567
File mode to use (write or append). Append does not work with fsspec URLs.
568
568
569
569
.. versionadded:: 0.24.0
570
+ storage_options : dict, optional
571
+ Extra options that make sense for a particular storage connection, e.g.
572
+ host, port, username, password, etc., if using a URL that will
573
+ be parsed by ``fsspec``, e.g., starting "s3://", "gcs://".
574
+
575
+ .. versionadded:: 1.2.0
570
576
571
577
Attributes
572
578
----------
@@ -710,11 +716,12 @@ def save(self):
710
716
711
717
def __init__ (
712
718
self ,
713
- path ,
719
+ path : Union [ FilePathOrBuffer , "ExcelWriter" ] ,
714
720
engine = None ,
715
721
date_format = None ,
716
722
datetime_format = None ,
717
- mode = "w" ,
723
+ mode : str = "w" ,
724
+ storage_options : StorageOptions = None ,
718
725
** engine_kwargs ,
719
726
):
720
727
# validate that this engine can handle the extension
@@ -729,10 +736,13 @@ def __init__(
729
736
# the excel backend first read the existing file and then write any data to it
730
737
mode = mode .replace ("a" , "r+" )
731
738
732
- self .handles = IOHandles (path , compression = {"copression" : None })
739
+ # cast ExcelWriter to avoid adding 'if self.handles is not None'
740
+ self .handles = IOHandles (cast (Buffer , path ), compression = {"copression" : None })
733
741
if not isinstance (path , ExcelWriter ):
734
- self .handles = get_handle (path , mode , is_text = False )
735
- self .sheets = {}
742
+ self .handles = get_handle (
743
+ path , mode , storage_options = storage_options , is_text = False
744
+ )
745
+ self .sheets : Dict [str , Any ] = {}
736
746
self .cur_sheet = None
737
747
738
748
if date_format is None :
0 commit comments