|
44 | 44 | ValueLabelTypeMismatch, |
45 | 45 | ) |
46 | 46 | from pandas.util._decorators import ( |
47 | | - doc, |
48 | 47 | set_module, |
49 | 48 | ) |
50 | 49 | from pandas.util._exceptions import find_stack_level |
@@ -2377,10 +2376,6 @@ def _dtype_to_default_stata_fmt( |
2377 | 2376 | raise NotImplementedError(f"Data type {dtype} not supported.") |
2378 | 2377 |
|
2379 | 2378 |
|
2380 | | -@doc( |
2381 | | - storage_options=_shared_docs["storage_options"], |
2382 | | - compression_options=_shared_docs["compression_options"] % "fname", |
2383 | | -) |
2384 | 2379 | class StataWriter(StataParser): |
2385 | 2380 | """ |
2386 | 2381 | A class for writing Stata binary dta files |
@@ -2412,11 +2407,36 @@ class StataWriter(StataParser): |
2412 | 2407 | variable_labels : dict |
2413 | 2408 | Dictionary containing columns as keys and variable labels as values. |
2414 | 2409 | 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. |
2416 | 2428 |
|
2417 | 2429 | .. versionchanged:: 1.4.0 Zstandard support. |
2418 | 2430 |
|
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>`_. |
2420 | 2440 |
|
2421 | 2441 | value_labels : dict of dicts |
2422 | 2442 | Dictionary containing columns as keys and dictionaries of column value |
@@ -2449,14 +2469,14 @@ class StataWriter(StataParser): |
2449 | 2469 | >>> writer.write_file() |
2450 | 2470 |
|
2451 | 2471 | Directly write a zip file |
2452 | | - >>> compression = {{"method": "zip", "archive_name": "data_file.dta"}} |
| 2472 | + >>> compression = {"method": "zip", "archive_name": "data_file.dta"} |
2453 | 2473 | >>> writer = StataWriter("./data_file.zip", data, compression=compression) |
2454 | 2474 | >>> writer.write_file() |
2455 | 2475 |
|
2456 | 2476 | Save a DataFrame with dates |
2457 | 2477 | >>> from datetime import datetime |
2458 | 2478 | >>> 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"}) |
2460 | 2480 | >>> writer.write_file() |
2461 | 2481 | """ |
2462 | 2482 |
|
|
0 commit comments