Skip to content

Commit c3fce1a

Browse files
authored
Replace doc in stata (#62668)
1 parent 79eb377 commit c3fce1a

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

pandas/io/stata.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
ValueLabelTypeMismatch,
4545
)
4646
from pandas.util._decorators import (
47-
doc,
4847
set_module,
4948
)
5049
from pandas.util._exceptions import find_stack_level
@@ -2377,10 +2376,6 @@ def _dtype_to_default_stata_fmt(
23772376
raise NotImplementedError(f"Data type {dtype} not supported.")
23782377

23792378

2380-
@doc(
2381-
storage_options=_shared_docs["storage_options"],
2382-
compression_options=_shared_docs["compression_options"] % "fname",
2383-
)
23842379
class StataWriter(StataParser):
23852380
"""
23862381
A class for writing Stata binary dta files
@@ -2412,11 +2407,36 @@ class StataWriter(StataParser):
24122407
variable_labels : dict
24132408
Dictionary containing columns as keys and variable labels as values.
24142409
Each label must be 80 characters or smaller.
2415-
{compression_options}
2410+
compression : str or dict, default 'infer'
2411+
For on-the-fly compression of the output data. If 'infer' and 'fname' is
2412+
path-like, then detect compression from the following extensions: '.gz',
2413+
'.bz2', '.zip', '.xz', '.zst', '.tar', '.tar.gz', '.tar.xz' or '.tar.bz2'
2414+
(otherwise no compression).
2415+
Set to ``None`` for no compression.
2416+
Can also be a dict with key ``'method'`` set
2417+
to one of {``'zip'``, ``'gzip'``, ``'bz2'``, ``'zstd'``, ``'xz'``, ``'tar'``}
2418+
and other key-value pairs are forwarded to
2419+
``zipfile.ZipFile``, ``gzip.GzipFile``,
2420+
``bz2.BZ2File``, ``zstandard.ZstdCompressor``, ``lzma.LZMAFile`` or
2421+
``tarfile.TarFile``, respectively.
2422+
As an example, the following could be passed for faster compression and to
2423+
create a reproducible gzip archive:
2424+
``compression={'method': 'gzip', 'compresslevel': 1, 'mtime': 1}``.
2425+
2426+
.. versionadded:: 1.5.0
2427+
Added support for `.tar` files.
24162428
24172429
.. versionchanged:: 1.4.0 Zstandard support.
24182430
2419-
{storage_options}
2431+
storage_options : dict, optional
2432+
Extra options that make sense for a particular storage connection, e.g.
2433+
host, port, username, password, etc. For HTTP(S) URLs the key-value pairs
2434+
are forwarded to ``urllib.request.Request`` as header options. For other
2435+
URLs (e.g. starting with "s3://", and "gcs://") the key-value pairs are
2436+
forwarded to ``fsspec.open``. Please see ``fsspec`` and ``urllib`` for more
2437+
details, and for more examples on storage options refer `here
2438+
<https://pandas.pydata.org/docs/user_guide/io.html?
2439+
highlight=storage_options#reading-writing-remote-files>`_.
24202440
24212441
value_labels : dict of dicts
24222442
Dictionary containing columns as keys and dictionaries of column value
@@ -2449,14 +2469,14 @@ class StataWriter(StataParser):
24492469
>>> writer.write_file()
24502470
24512471
Directly write a zip file
2452-
>>> compression = {{"method": "zip", "archive_name": "data_file.dta"}}
2472+
>>> compression = {"method": "zip", "archive_name": "data_file.dta"}
24532473
>>> writer = StataWriter("./data_file.zip", data, compression=compression)
24542474
>>> writer.write_file()
24552475
24562476
Save a DataFrame with dates
24572477
>>> from datetime import datetime
24582478
>>> data = pd.DataFrame([[datetime(2000, 1, 1)]], columns=["date"])
2459-
>>> writer = StataWriter("./date_data_file.dta", data, {{"date": "tw"}})
2479+
>>> writer = StataWriter("./date_data_file.dta", data, {"date": "tw"})
24602480
>>> writer.write_file()
24612481
"""
24622482

0 commit comments

Comments
 (0)