Skip to content

Commit a21615b

Browse files
committed
DOC: Clean up doc strings
Fix typo Enhance compliance of related docstrings usign validator
1 parent 1baeb46 commit a21615b

File tree

3 files changed

+43
-25
lines changed

3 files changed

+43
-25
lines changed

pandas/core/frame.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -1772,25 +1772,25 @@ def to_stata(self, fname, convert_dates=None, write_index=True,
17721772
data_label=None, variable_labels=None, version=114,
17731773
convert_strl=None):
17741774
"""
1775-
A class for writing Stata binary dta files from array-like objects
1775+
Export Stata binary dta files.
17761776
17771777
Parameters
17781778
----------
17791779
fname : str or buffer
1780-
String path of file-like object
1780+
String path of file-like object.
17811781
convert_dates : dict
17821782
Dictionary mapping columns containing datetime types to stata
17831783
internal format to use when writing the dates. Options are 'tc',
17841784
'td', 'tm', 'tw', 'th', 'tq', 'ty'. Column can be either an integer
17851785
or a name. Datetime columns that do not have a conversion type
17861786
specified will be converted to 'tc'. Raises NotImplementedError if
1787-
a datetime column has timezone information
1787+
a datetime column has timezone information.
17881788
write_index : bool
17891789
Write the index to Stata dataset.
17901790
encoding : str
1791-
Default is latin-1. Unicode is not supported
1791+
Default is latin-1. Unicode is not supported.
17921792
byteorder : str
1793-
Can be ">", "<", "little", or "big". default is `sys.byteorder`
1793+
Can be ">", "<", "little", or "big". default is `sys.byteorder`.
17941794
time_stamp : datetime
17951795
A datetime to use as file creation date. Default is the current
17961796
time.
@@ -1803,7 +1803,7 @@ def to_stata(self, fname, convert_dates=None, write_index=True,
18031803
.. versionadded:: 0.19.0
18041804
18051805
version : {114, 117}
1806-
dta version to use in the output file. Version 114 can be used
1806+
Version to use in the output dta file. Version 114 can be used
18071807
read by Stata 10 and later. Version 117 can be read by Stata 13
18081808
or later. Version 114 limits string variables to 244 characters or
18091809
fewer while 117 allows strings with lengths up to 2,000,000
@@ -1813,7 +1813,7 @@ def to_stata(self, fname, convert_dates=None, write_index=True,
18131813
18141814
convert_strl : list, optional
18151815
List of column names to convert to string columns to Stata StrL
1816-
format. Only available if version is 117. Storign strings in the
1816+
format. Only available if version is 117. Storing strings in the
18171817
StrL format can produce smaller dta files if strings have more than
18181818
8 characters and values are repeated.
18191819
@@ -1832,6 +1832,12 @@ def to_stata(self, fname, convert_dates=None, write_index=True,
18321832
18331833
.. versionadded:: 0.19.0
18341834
1835+
See Also
1836+
--------
1837+
pandas.read_stata : Import Stata data files
1838+
pandas.io.stata.StataWriter : low-level writer for Stata data files
1839+
pandas.io.stata.StataWriter117 : low-level writer for version 117 files
1840+
18351841
Examples
18361842
--------
18371843
>>> data.to_stata('./data_file.dta')

pandas/io/stata.py

+25-17
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@
4545

4646
_statafile_processing_params1 = """\
4747
convert_dates : boolean, defaults to True
48-
Convert date variables to DataFrame time values
48+
Convert date variables to DataFrame time values.
4949
convert_categoricals : boolean, defaults to True
50-
Read value labels and convert columns to Categorical/Factor variables"""
50+
Read value labels and convert columns to Categorical/Factor variables."""
5151

5252
_encoding_params = """\
5353
encoding : string, None or encoding
5454
Encoding used to parse the files. None defaults to latin-1."""
5555

5656
_statafile_processing_params2 = """\
5757
index_col : string, optional, default: None
58-
Column to set as index
58+
Column to set as index.
5959
convert_missing : boolean, defaults to False
6060
Flag indicating whether to convert missing values to their Stata
6161
representations. If False, missing values are replaced with nan.
@@ -64,28 +64,29 @@
6464
StataMissingValue objects.
6565
preserve_dtypes : boolean, defaults to True
6666
Preserve Stata datatypes. If False, numeric data are upcast to pandas
67-
default types for foreign data (float64 or int64)
67+
default types for foreign data (float64 or int64).
6868
columns : list or None
6969
Columns to retain. Columns will be returned in the given order. None
70-
returns all columns
70+
returns all columns.
7171
order_categoricals : boolean, defaults to True
7272
Flag indicating whether converted categorical data are ordered."""
7373

7474
_chunksize_params = """\
7575
chunksize : int, default None
7676
Return StataReader object for iterations, returns chunks with
77-
given number of lines"""
77+
given number of lines."""
7878

7979
_iterator_params = """\
8080
iterator : boolean, default False
81-
Return StataReader object"""
81+
Return StataReader object."""
8282

83-
_read_stata_doc = """Read Stata file into DataFrame
83+
_read_stata_doc = """
84+
Read Stata file into DataFrame.
8485
8586
Parameters
8687
----------
8788
filepath_or_buffer : string or file-like object
88-
Path to .dta file or object implementing a binary read() functions
89+
Path to .dta file or object implementing a binary read() functions.
8990
%s
9091
%s
9192
%s
@@ -96,17 +97,23 @@
9697
-------
9798
DataFrame or StataReader
9899
100+
See Also
101+
--------
102+
pandas.io.stata.StataReader : low-level reader for Stata data files
103+
pandas.DataFrame.to_stata: export Stata data files
104+
99105
Examples
100106
--------
101107
Read a Stata dta file:
102108
103-
>>> df = pandas.read_stata('filename.dta')
109+
>>> import pandas as pd
110+
>>> df = pd.read_stata('filename.dta')
104111
105112
Read a Stata dta file in 10,000 line chunks:
106113
107-
>>> itr = pandas.read_stata('filename.dta', chunksize=10000)
114+
>>> itr = pd.read_stata('filename.dta', chunksize=10000)
108115
>>> for chunk in itr:
109-
>>> do_something(chunk)
116+
... do_something(chunk)
110117
""" % (_statafile_processing_params1, _encoding_params,
111118
_statafile_processing_params2, _chunksize_params,
112119
_iterator_params)
@@ -2472,7 +2479,7 @@ def __init__(self, df, columns, version=117, byteorder=None):
24722479

24732480
self.df = df
24742481
self.columns = columns
2475-
self._gso_table = OrderedDict((('', 0),))
2482+
self._gso_table = OrderedDict((('', (0, 0)),))
24762483
if byteorder is None:
24772484
byteorder = sys.byteorder
24782485
self._byteorder = _set_endianness(byteorder)
@@ -2674,15 +2681,16 @@ class StataWriter117(StataWriter):
26742681
Examples
26752682
--------
26762683
>>> import pandas as pd
2677-
>>> data = pd.DataFrame([[1.0, 1, 'a']], columns=['a', 'b'])
2684+
>>> from pandas.io.stata import StataWriter117
2685+
>>> data = pd.DataFrame([[1.0, 1, 'a']], columns=['a', 'b', 'c'])
26782686
>>> writer = StataWriter117('./data_file.dta', data)
26792687
>>> writer.write_file()
26802688
2681-
Or with dates
2682-
>>> from datetime import datetime
2689+
Or with long strings stored in strl format
2690+
26832691
>>> data = pd.DataFrame([['A relatively long string'], [''], ['']],
26842692
... columns=['strls'])
2685-
>>> writer = StataWriter117('./date_data_file.dta', data,
2693+
>>> writer = StataWriter117('./data_file_with_long_strings.dta', data,
26862694
... convert_strl=['strls'])
26872695
>>> writer.write_file()
26882696
"""

pandas/tests/io/test_stata.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1378,7 +1378,11 @@ def test_date_parsing_ignores_format_details(self, column):
13781378
def test_writer_117(self):
13791379
original = DataFrame(data=[['string', 'object', 1, 1, 1, 1.1, 1.1,
13801380
np.datetime64('2003-12-25'),
1381-
'a', 'a' * 2045, 'a' * 5000, 'a']],
1381+
'a', 'a' * 2045, 'a' * 5000, 'a'],
1382+
['string-1', 'object-1', 1, 1, 1, 1.1, 1.1,
1383+
np.datetime64('2003-12-26'),
1384+
'b', 'b' * 2045, '', '']
1385+
],
13821386
columns=['string', 'object', 'int8', 'int16',
13831387
'int32', 'float32', 'float64',
13841388
'datetime',

0 commit comments

Comments
 (0)