Skip to content

Commit 8341cec

Browse files
ryankarlosjreback
authored andcommitted
DOC: #22896, Fixed docstring of to_stata in pandas/core/frame.py (#23152)
1 parent 4f16dff commit 8341cec

File tree

2 files changed

+17
-26
lines changed

2 files changed

+17
-26
lines changed

ci/code_checks.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then
148148

149149
MSG='Doctests frame.py' ; echo $MSG
150150
pytest -q --doctest-modules pandas/core/frame.py \
151-
-k"-axes -combine -itertuples -join -nunique -pivot_table -quantile -query -reindex -reindex_axis -replace -round -set_index -stack -to_stata"
151+
-k"-axes -combine -itertuples -join -nunique -pivot_table -quantile -query -reindex -reindex_axis -replace -round -set_index -stack"
152152
RET=$(($RET + $?)) ; echo $MSG "DONE"
153153

154154
MSG='Doctests series.py' ; echo $MSG

pandas/core/frame.py

+16-25
Original file line numberDiff line numberDiff line change
@@ -1856,13 +1856,16 @@ def to_stata(self, fname, convert_dates=None, write_index=True,
18561856
data_label=None, variable_labels=None, version=114,
18571857
convert_strl=None):
18581858
"""
1859-
Export Stata binary dta files.
1859+
Export DataFrame object to Stata dta format.
1860+
1861+
Writes the DataFrame to a Stata dataset file.
1862+
"dta" files contain a Stata dataset.
18601863
18611864
Parameters
18621865
----------
1863-
fname : path (string), buffer or path object
1864-
string, path object (pathlib.Path or py._path.local.LocalPath) or
1865-
object implementing a binary write() functions. If using a buffer
1866+
fname : str, buffer or path object
1867+
String, path object (pathlib.Path or py._path.local.LocalPath) or
1868+
object implementing a binary write() function. If using a buffer
18661869
then the buffer will not be automatically closed after the file
18671870
data has been written.
18681871
convert_dates : dict
@@ -1881,15 +1884,15 @@ def to_stata(self, fname, convert_dates=None, write_index=True,
18811884
time_stamp : datetime
18821885
A datetime to use as file creation date. Default is the current
18831886
time.
1884-
data_label : str
1887+
data_label : str, optional
18851888
A label for the data set. Must be 80 characters or smaller.
18861889
variable_labels : dict
18871890
Dictionary containing columns as keys and variable labels as
18881891
values. Each label must be 80 characters or smaller.
18891892
18901893
.. versionadded:: 0.19.0
18911894
1892-
version : {114, 117}
1895+
version : {114, 117}, default 114
18931896
Version to use in the output dta file. Version 114 can be used
18941897
read by Stata 10 and later. Version 117 can be read by Stata 13
18951898
or later. Version 114 limits string variables to 244 characters or
@@ -1921,28 +1924,16 @@ def to_stata(self, fname, convert_dates=None, write_index=True,
19211924
19221925
See Also
19231926
--------
1924-
pandas.read_stata : Import Stata data files.
1925-
pandas.io.stata.StataWriter : Low-level writer for Stata data files.
1926-
pandas.io.stata.StataWriter117 : Low-level writer for version 117
1927-
files.
1927+
read_stata : Import Stata data files.
1928+
io.stata.StataWriter : Low-level writer for Stata data files.
1929+
io.stata.StataWriter117 : Low-level writer for version 117 files.
19281930
19291931
Examples
19301932
--------
1931-
>>> data.to_stata('./data_file.dta')
1932-
1933-
Or with dates
1934-
1935-
>>> data.to_stata('./date_data_file.dta', {2 : 'tw'})
1936-
1937-
Alternatively you can create an instance of the StataWriter class
1938-
1939-
>>> writer = StataWriter('./data_file.dta', data)
1940-
>>> writer.write_file()
1941-
1942-
With dates:
1943-
1944-
>>> writer = StataWriter('./date_data_file.dta', data, {2 : 'tw'})
1945-
>>> writer.write_file()
1933+
>>> df = pd.DataFrame({'animal': ['falcon', 'parrot', 'falcon',
1934+
... 'parrot'],
1935+
... 'speed': [350, 18, 361, 15]})
1936+
>>> df.to_stata('animals.dta') # doctest: +SKIP
19461937
"""
19471938
kwargs = {}
19481939
if version not in (114, 117):

0 commit comments

Comments
 (0)