Skip to content

Commit 3f5fbcd

Browse files
committed
Switch to .format from %s
1 parent d0600f9 commit 3f5fbcd

File tree

1 file changed

+51
-44
lines changed

1 file changed

+51
-44
lines changed

pandas/io/parsers.py

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@
5353
# so we need to remove it if we see it.
5454
_BOM = u('\ufeff')
5555

56-
_parser_params = r"""Also supports optionally iterating or breaking of the file
56+
_parser_params = r"""{summary}
57+
58+
Also supports optionally iterating or breaking of the file
5759
into chunks.
5860
5961
Additional help can be found in the `online docs for IO Tools
@@ -71,7 +73,7 @@
7173
7274
By file-like object, we refer to objects with a ``read()`` method, such as
7375
a file handler (e.g. via builtin ``open`` function) or ``StringIO``.
74-
%s
76+
{sep_doc}
7577
header : int or list of ints, default 'infer'
7678
Row number(s) to use as the column names, and the start of the
7779
data. Default behavior is to infer the column names: if no names
@@ -122,12 +124,12 @@
122124
'X'...'X'. Passing in False will cause data to be overwritten if there
123125
are duplicate names in the columns.
124126
dtype : Type name or dict of column -> type, default None
125-
Data type for data or columns. E.g. {'a': np.float64, 'b': np.int32}
127+
Data type for data or columns. E.g. {{'a': np.float64, 'b': np.int32}}
126128
Use `str` or `object` together with suitable `na_values` settings
127129
to preserve and not interpret dtype.
128130
If converters are specified, they will be applied INSTEAD
129131
of dtype conversion.
130-
%s
132+
{engine_doc}
131133
converters : dict, default None
132134
Dict of functions for converting values in certain columns. Keys can either
133135
be integers or column labels.
@@ -185,8 +187,8 @@
185187
each as a separate date column.
186188
* list of lists. e.g. If [[1, 3]] -> combine columns 1 and 3 and parse as
187189
a single date column.
188-
* dict, e.g. {'foo' : [1, 3]} -> parse columns 1, 3 as date and call result
189-
'foo'
190+
* dict, e.g. {{'foo' : [1, 3]}} -> parse columns 1, 3 as date and call
191+
result 'foo'
190192
191193
If a column or index contains an unparseable date, the entire column or
192194
index will be returned unaltered as an object data type. For non-standard
@@ -221,7 +223,7 @@
221223
See the `IO Tools docs
222224
<http://pandas.pydata.org/pandas-docs/stable/io.html#io-chunking>`_
223225
for more information on ``iterator`` and ``chunksize``.
224-
compression : {'infer', 'gzip', 'bz2', 'zip', 'xz', None}, default 'infer'
226+
compression : {{'infer', 'gzip', 'bz2', 'zip', 'xz', None}}, default 'infer'
225227
For on-the-fly decompression of on-disk data. If 'infer' and
226228
`filepath_or_buffer` is path-like, then detect compression from the
227229
following extensions: '.gz', '.bz2', '.zip', or '.xz' (otherwise no
@@ -309,15 +311,32 @@
309311
Returns
310312
-------
311313
DataFrame or TextParser
314+
A comma-separated values (csv) file is returned as two-dimensional
315+
data structure with labeled axes.
312316
313317
See Also
314318
--------
315319
to_csv : Write DataFrame to a comma-separated values (csv) file.
316-
%s
320+
read_csv : Read a comma-separated values (csv) file into DataFrame.
321+
read_fwf : Read a table of fixed-width formatted lines into DataFrame.
317322
318323
Examples
319324
--------
320-
%s # doctest: +SKI"""
325+
>>> pd.{func_name}('data.csv') # doctest: +SKIP
326+
"""
327+
328+
# Summary line for read_csv,read_table and read_fwf
329+
_summary_read_csv = """
330+
Read a comma-separated values (csv) file into DataFrame."""
331+
332+
_summary_read_table = """
333+
Read general delimited file into DataFrame.
334+
335+
.. deprecated:: 0.24.0
336+
Use :func:`pandas.read_csv` instead, passing ``sep='\t'`` if necessary."""
337+
338+
_summary_read_fwf = """
339+
Read a table of fixed-width formatted lines into DataFrame."""
321340

322341
# engine is not used in read_fwf() so is factored out of the shared docstring
323342
_engine_doc = """engine : {'c', 'python'}, optional
@@ -335,34 +354,24 @@
335354
delimiter : str, default ``None``
336355
Alias for sep.
337356
"""
338-
339-
_see_also_csv_doc = ('read_csv : Read a comma-separated values '
340-
'(csv) file into DataFrame.')
341-
342-
_see_also_fwf_doc = ('read_fwf : Read a table of '
343-
'fixed-width formatted lines into DataFrame.')
344-
345-
_example_doc = "pd.{_api}('/tmp/data.csv')"
346-
347-
_read_csv_doc = """
348-
Read a comma-separated values (csv) file into DataFrame.
349-
350-
%s
351-
""" % (_parser_params % (_sep_doc.format(default="','"),
352-
_engine_doc, _see_also_fwf_doc,
353-
_example_doc.format(_api='read_csv')))
354-
355-
_read_table_doc = """
356-
Read general delimited file into DataFrame.
357-
358-
.. deprecated:: 0.24.0
359-
Use :func:`pandas.read_csv` instead, passing ``sep='\t'`` if necessary.
360-
361-
%s
362-
""" % (_parser_params % (_sep_doc.format(default="\\t (tab-stop)"),
363-
_engine_doc,
364-
'{}\n{}'.format(_see_also_csv_doc, _see_also_fwf_doc),
365-
_example_doc.format(_api='read_table')))
357+
# _read_csv_doc = """
358+
# Read a comma-separated values (csv) file into DataFrame.
359+
360+
# %s
361+
# """ % (_parser_params % (_sep_doc.format(default="','"),
362+
# _engine_doc,
363+
# _example_doc.format(_api='read_csv')))
364+
_read_csv_doc = (_parser_params
365+
.format(summary=_summary_read_csv,
366+
sep_doc=_sep_doc.format(default="','"),
367+
engine_doc=_engine_doc,
368+
func_name='read_csv'))
369+
370+
_read_table_doc = (_parser_params
371+
.format(summary=_summary_read_table,
372+
sep_doc=_sep_doc.format(default="\\t (tab-stop)"),
373+
engine_doc=_engine_doc,
374+
func_name='read_table'))
366375

367376
_fwf_widths = """\
368377
colspecs : list of pairs (int, int) or 'infer'. optional
@@ -380,13 +389,11 @@
380389
if it is not spaces (e.g., '~').
381390
"""
382391

383-
_read_fwf_doc = """
384-
Read a table of fixed-width formatted lines into DataFrame.
385-
386-
%s
387-
""" % (_parser_params % (_fwf_widths, '',
388-
_see_also_csv_doc,
389-
_example_doc.format(_api='read_fwf')))
392+
_read_fwf_doc = (_parser_params
393+
.format(summary=_summary_read_fwf,
394+
sep_doc='',
395+
engine_doc='',
396+
func_name='read_fwf'))
390397

391398

392399
def _validate_integer(name, val, min_val=0):

0 commit comments

Comments
 (0)