Skip to content

Commit 67984e9

Browse files
authored
DOC: Fixing EX01 - Added examples (#54357)
* Example for writer * updated code_checks.sh
1 parent e287acc commit 67984e9

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

ci/code_checks.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
6363

6464
MSG='Partially validate docstrings (EX01)' ; echo $MSG
6565
$BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX01 --ignore_functions \
66-
pandas.io.stata.StataWriter.write_file \
6766
pandas.api.extensions.ExtensionArray \
6867
RET=$(($RET + $?)) ; echo $MSG "DONE"
6968

pandas/io/stata.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2737,6 +2737,30 @@ def _encode_strings(self) -> None:
27372737
def write_file(self) -> None:
27382738
"""
27392739
Export DataFrame object to Stata dta format.
2740+
2741+
Examples
2742+
--------
2743+
>>> df = pd.DataFrame({"fully_labelled": [1, 2, 3, 3, 1],
2744+
... "partially_labelled": [1.0, 2.0, np.nan, 9.0, np.nan],
2745+
... "Y": [7, 7, 9, 8, 10],
2746+
... "Z": pd.Categorical(["j", "k", "l", "k", "j"]),
2747+
... })
2748+
>>> path = "/My_path/filename.dta"
2749+
>>> labels = {"fully_labelled": {1: "one", 2: "two", 3: "three"},
2750+
... "partially_labelled": {1.0: "one", 2.0: "two"},
2751+
... }
2752+
>>> writer = pd.io.stata.StataWriter(path,
2753+
... df,
2754+
... value_labels=labels) # doctest: +SKIP
2755+
>>> writer.write_file() # doctest: +SKIP
2756+
>>> df = pd.read_stata(path) # doctest: +SKIP
2757+
>>> df # doctest: +SKIP
2758+
index fully_labelled partially_labeled Y Z
2759+
0 0 one one 7 j
2760+
1 1 two two 7 k
2761+
2 2 three NaN 9 l
2762+
3 3 three 9.0 8 k
2763+
4 4 one NaN 10 j
27402764
"""
27412765
with get_handle(
27422766
self._fname,

0 commit comments

Comments
 (0)