Skip to content

Commit 754aca4

Browse files
authored
DOC: How to use storage_option param here to integrate with GCP bucket? (#45928)
* added storage_options description * shared the doc-strings between all the methods * shared the doc-strings between all the methods * shared the doc-strings between all the methods * replaced {storage_options} in _base file * replaced {storage_options} in _base file * fixed unescaped braces
1 parent cdca67a commit 754aca4

File tree

9 files changed

+51
-45
lines changed

9 files changed

+51
-45
lines changed

pandas/core/shared_docs.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,12 @@
400400
] = """storage_options : dict, optional
401401
Extra options that make sense for a particular storage connection, e.g.
402402
host, port, username, password, etc. For HTTP(S) URLs the key-value pairs
403-
are forwarded to ``urllib`` as header options. For other URLs (e.g.
404-
starting with "s3://", and "gcs://") the key-value pairs are forwarded to
405-
``fsspec``. Please see ``fsspec`` and ``urllib`` for more details."""
403+
are forwarded to ``urllib.request.Request`` as header options. For other
404+
URLs (e.g. starting with "s3://", and "gcs://") the key-value pairs are
405+
forwarded to ``fsspec.open``. Please see ``fsspec`` and ``urllib`` for more
406+
details, and for more examples on storage options refer `here
407+
<https://pandas.pydata.org/docs/user_guide/io.html?
408+
highlight=storage_options#reading-writing-remote-files>`_."""
406409

407410
_shared_docs[
408411
"compression_options"

pandas/io/common.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,10 @@ def is_fsspec_url(url: FilePath | BaseBuffer) -> bool:
251251
)
252252

253253

254-
@doc(compression_options=_shared_docs["compression_options"] % "filepath_or_buffer")
254+
@doc(
255+
storage_options=_shared_docs["storage_options"],
256+
compression_options=_shared_docs["compression_options"] % "filepath_or_buffer",
257+
)
255258
def _get_filepath_or_buffer(
256259
filepath_or_buffer: FilePath | BaseBuffer,
257260
encoding: str = "utf-8",
@@ -274,13 +277,7 @@ def _get_filepath_or_buffer(
274277
encoding : the encoding to use to decode bytes, default is 'utf-8'
275278
mode : str, optional
276279
277-
storage_options : dict, optional
278-
Extra options that make sense for a particular storage connection, e.g.
279-
host, port, username, password, etc., if using a URL that will
280-
be parsed by ``fsspec``, e.g., starting "s3://", "gcs://". An error
281-
will be raised if providing this argument with a local path or
282-
a file-like buffer. See the fsspec and backend storage implementation
283-
docs for the set of allowed keys and values
280+
{storage_options}
284281
285282
.. versionadded:: 1.2.0
286283

pandas/io/excel/_base.py

+11-18
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
Append ``.squeeze("columns")`` to the call to ``read_excel`` to squeeze
144144
the data.
145145
dtype : Type name or dict of column -> type, default None
146-
Data type for data or columns. E.g. {'a': np.float64, 'b': np.int32}
146+
Data type for data or columns. E.g. {{'a': np.float64, 'b': np.int32}}
147147
Use `object` to preserve data as stored in Excel and not interpret dtype.
148148
If converters are specified, they will be applied INSTEAD
149149
of dtype conversion.
@@ -227,7 +227,7 @@
227227
each as a separate date column.
228228
* list of lists. e.g. If [[1, 3]] -> combine columns 1 and 3 and parse as
229229
a single date column.
230-
* dict, e.g. {'foo' : [1, 3]} -> parse columns 1, 3 as date and call
230+
* dict, e.g. {{'foo' : [1, 3]}} -> parse columns 1, 3 as date and call
231231
result 'foo'
232232
233233
If a column or index contains an unparsable date, the entire column or
@@ -277,13 +277,7 @@
277277
Duplicate columns will be specified as 'X', 'X.1', ...'X.N', rather than
278278
'X'...'X'. Passing in False will cause data to be overwritten if there
279279
are duplicate names in the columns.
280-
storage_options : dict, optional
281-
Extra options that make sense for a particular storage connection, e.g.
282-
host, port, username, password, etc., if using a URL that will
283-
be parsed by ``fsspec``, e.g., starting "s3://", "gcs://". An error
284-
will be raised if providing this argument with a local path or
285-
a file-like buffer. See the fsspec and backend storage implementation
286-
docs for the set of allowed keys and values.
280+
{storage_options}
287281
288282
.. versionadded:: 1.2.0
289283
@@ -329,7 +323,7 @@
329323
Column types are inferred but can be explicitly specified
330324
331325
>>> pd.read_excel('tmp.xlsx', index_col=0,
332-
... dtype={'Name': str, 'Value': float}) # doctest: +SKIP
326+
... dtype={{'Name': str, 'Value': float}}) # doctest: +SKIP
333327
Name Value
334328
0 string1 1.0
335329
1 string2 2.0
@@ -425,6 +419,7 @@ def read_excel(
425419
...
426420

427421

422+
@doc(storage_options=_shared_docs["storage_options"])
428423
@deprecate_nonkeyword_arguments(allowed_args=["io", "sheet_name"], version="2.0")
429424
@Appender(_read_excel_doc)
430425
def read_excel(
@@ -766,6 +761,7 @@ def parse(
766761
return output[asheetname]
767762

768763

764+
@doc(storage_options=_shared_docs["storage_options"])
769765
class ExcelWriter(metaclass=abc.ABCMeta):
770766
"""
771767
Class for writing DataFrame objects into excel sheets.
@@ -799,16 +795,13 @@ class ExcelWriter(metaclass=abc.ABCMeta):
799795
datetime_format : str, default None
800796
Format string for datetime objects written into Excel files.
801797
(e.g. 'YYYY-MM-DD HH:MM:SS').
802-
mode : {'w', 'a'}, default 'w'
798+
mode : {{'w', 'a'}}, default 'w'
803799
File mode to use (write or append). Append does not work with fsspec URLs.
804-
storage_options : dict, optional
805-
Extra options that make sense for a particular storage connection, e.g.
806-
host, port, username, password, etc., if using a URL that will
807-
be parsed by ``fsspec``, e.g., starting "s3://", "gcs://".
800+
{storage_options}
808801
809802
.. versionadded:: 1.2.0
810803
811-
if_sheet_exists : {'error', 'new', 'replace', 'overlay'}, default 'error'
804+
if_sheet_exists : {{'error', 'new', 'replace', 'overlay'}}, default 'error'
812805
How to behave when trying to write to a sheet that already
813806
exists (append mode only).
814807
@@ -929,7 +922,7 @@ class ExcelWriter(metaclass=abc.ABCMeta):
929922
>>> with pd.ExcelWriter(
930923
... "path_to_file.xlsx",
931924
... engine="xlsxwriter",
932-
... engine_kwargs={"options": {"nan_inf_to_errors": True}}
925+
... engine_kwargs={{"options": {{"nan_inf_to_errors": True}}}}
933926
... ) as writer:
934927
... df.to_excel(writer) # doctest: +SKIP
935928
@@ -940,7 +933,7 @@ class ExcelWriter(metaclass=abc.ABCMeta):
940933
... "path_to_file.xlsx",
941934
... engine="openpyxl",
942935
... mode="a",
943-
... engine_kwargs={"keep_vba": True}
936+
... engine_kwargs={{"keep_vba": True}}
944937
... ) as writer:
945938
... df.to_excel(writer, sheet_name="Sheet2") # doctest: +SKIP
946939
"""

pandas/io/excel/_odfreader.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@
99
StorageOptions,
1010
)
1111
from pandas.compat._optional import import_optional_dependency
12+
from pandas.util._decorators import doc
1213

1314
import pandas as pd
15+
from pandas.core.shared_docs import _shared_docs
1416

1517
from pandas.io.excel._base import BaseExcelReader
1618

1719

20+
@doc(storage_options=_shared_docs["storage_options"])
1821
class ODFReader(BaseExcelReader):
1922
"""
2023
Read tables out of OpenDocument formatted files.
@@ -23,8 +26,7 @@ class ODFReader(BaseExcelReader):
2326
----------
2427
filepath_or_buffer : str, path to be parsed or
2528
an open readable stream.
26-
storage_options : dict, optional
27-
passed to fsspec for appropriate URLs (see ``_get_filepath_or_buffer``)
29+
{storage_options}
2830
"""
2931

3032
def __init__(

pandas/io/excel/_openpyxl.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
WriteExcelBuffer,
1919
)
2020
from pandas.compat._optional import import_optional_dependency
21+
from pandas.util._decorators import doc
22+
23+
from pandas.core.shared_docs import _shared_docs
2124

2225
from pandas.io.excel._base import (
2326
BaseExcelReader,
@@ -526,6 +529,7 @@ def _write_cells(
526529

527530

528531
class OpenpyxlReader(BaseExcelReader):
532+
@doc(storage_options=_shared_docs["storage_options"])
529533
def __init__(
530534
self,
531535
filepath_or_buffer: FilePath | ReadBuffer[bytes],
@@ -538,8 +542,7 @@ def __init__(
538542
----------
539543
filepath_or_buffer : str, path object or Workbook
540544
Object to be parsed.
541-
storage_options : dict, optional
542-
passed to fsspec for appropriate URLs (see ``_get_filepath_or_buffer``)
545+
{storage_options}
543546
"""
544547
import_optional_dependency("openpyxl")
545548
super().__init__(filepath_or_buffer, storage_options=storage_options)

pandas/io/excel/_pyxlsb.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88
StorageOptions,
99
)
1010
from pandas.compat._optional import import_optional_dependency
11+
from pandas.util._decorators import doc
12+
13+
from pandas.core.shared_docs import _shared_docs
1114

1215
from pandas.io.excel._base import BaseExcelReader
1316

1417

1518
class PyxlsbReader(BaseExcelReader):
19+
@doc(storage_options=_shared_docs["storage_options"])
1620
def __init__(
1721
self,
1822
filepath_or_buffer: FilePath | ReadBuffer[bytes],
@@ -25,8 +29,7 @@ def __init__(
2529
----------
2630
filepath_or_buffer : str, path object, or Workbook
2731
Object to be parsed.
28-
storage_options : dict, optional
29-
passed to fsspec for appropriate URLs (see ``_get_filepath_or_buffer``)
32+
{storage_options}
3033
"""
3134
import_optional_dependency("pyxlsb")
3235
# This will call load_workbook on the filepath or buffer

pandas/io/excel/_xlrd.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44

55
from pandas._typing import StorageOptions
66
from pandas.compat._optional import import_optional_dependency
7+
from pandas.util._decorators import doc
8+
9+
from pandas.core.shared_docs import _shared_docs
710

811
from pandas.io.excel._base import BaseExcelReader
912

1013

1114
class XlrdReader(BaseExcelReader):
15+
@doc(storage_options=_shared_docs["storage_options"])
1216
def __init__(self, filepath_or_buffer, storage_options: StorageOptions = None):
1317
"""
1418
Reader using xlrd engine.
@@ -17,8 +21,7 @@ def __init__(self, filepath_or_buffer, storage_options: StorageOptions = None):
1721
----------
1822
filepath_or_buffer : str, path object or Workbook
1923
Object to be parsed.
20-
storage_options : dict, optional
21-
passed to fsspec for appropriate URLs (see ``_get_filepath_or_buffer``)
24+
{storage_options}
2225
"""
2326
err_msg = "Install xlrd >= 1.0.0 for Excel support"
2427
import_optional_dependency("xlrd", extra=err_msg)

pandas/io/formats/xml.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@
3030
)
3131

3232

33-
@doc(compression_options=_shared_docs["compression_options"] % "path_or_buffer")
33+
@doc(
34+
storage_options=_shared_docs["storage_options"],
35+
compression_options=_shared_docs["compression_options"] % "path_or_buffer",
36+
)
3437
class BaseXMLFormatter:
3538
"""
3639
Subclass for formatting data in XML.
@@ -82,9 +85,7 @@ class BaseXMLFormatter:
8285
8386
.. versionchanged:: 1.4.0 Zstandard support.
8487
85-
storage_options : dict, optional
86-
Extra options that make sense for a particular storage connection,
87-
e.g. host, port, username, password, etc.,
88+
{storage_options}
8889
8990
See also
9091
--------

pandas/io/xml.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@
4242
from pandas.io.parsers import TextParser
4343

4444

45-
@doc(decompression_options=_shared_docs["decompression_options"] % "path_or_buffer")
45+
@doc(
46+
storage_options=_shared_docs["storage_options"],
47+
decompression_options=_shared_docs["decompression_options"] % "path_or_buffer",
48+
)
4649
class _XMLFrameParser:
4750
"""
4851
Internal subclass to parse XML into DataFrames.
@@ -98,9 +101,7 @@ class _XMLFrameParser:
98101
99102
.. versionchanged:: 1.4.0 Zstandard support.
100103
101-
storage_options : dict, optional
102-
Extra options that make sense for a particular storage connection,
103-
e.g. host, port, username, password, etc.,
104+
{storage_options}
104105
105106
See also
106107
--------

0 commit comments

Comments
 (0)