Skip to content

Commit 5a95500

Browse files
committed
Change docstrings for read_fwf
1 parent 97db816 commit 5a95500

File tree

1 file changed

+59
-25
lines changed

1 file changed

+59
-25
lines changed

pandas/io/parsers.py

Lines changed: 59 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -343,24 +343,6 @@
343343
Alias for sep.
344344
"""
345345

346-
_fwf_widths = r"""
347-
colspecs : list of pairs (int, int) or 'infer'. optional
348-
A list of pairs (tuples) giving the extents of the fixed-width
349-
fields of each line as half-open intervals (i.e., [from, to[ ).
350-
String value 'infer' can be used to instruct the parser to try
351-
detecting the column specifications from the first 100 rows of
352-
the data which are not being skipped via skiprows (default='infer').
353-
widths : list of ints. optional
354-
A list of field widths which can be used instead of 'colspecs' if
355-
the intervals are contiguous.
356-
delimiter : str, default ``'\t' + ' '``
357-
Characters to consider as filler characters in the fixed-width file.
358-
Can be used to specify the filler character of the fields
359-
if it is not spaces (e.g., '~').
360-
**kwds : optional
361-
All the following keyword arguments can be passed.
362-
"""
363-
364346

365347
def _validate_integer(name, val, min_val=0):
366348
"""
@@ -726,13 +708,64 @@ def parser_f(filepath_or_buffer,
726708
)(read_table)
727709

728710

729-
@Appender(_parser_params.format(
730-
func_name='read_fwf',
731-
summary=('Read a table of fixed-width formatted lines '
732-
'into DataFrame.'),
733-
sep_doc=_fwf_widths,
734-
engine_doc=''))
735-
def read_fwf(filepath_or_buffer, colspecs='infer', widths=None, **kwds):
711+
def read_fwf(filepath_or_buffer, delimiter='\t' + ' ',
712+
colspecs='infer', widths=None, **kwds):
713+
714+
r"""
715+
Read a table of fixed-width formatted lines into DataFrame.
716+
717+
Also supports optionally iterating or breaking of the file
718+
into chunks.
719+
720+
Additional help can be found in the `online docs for IO Tools
721+
<http://pandas.pydata.org/pandas-docs/stable/io.html>`_.
722+
723+
Parameters
724+
----------
725+
filepath_or_buffer : str, path object, or file-like object
726+
Any valid string path is acceptable. The string could be a URL. Valid
727+
URL schemes include http, ftp, s3, and file. For file URLs, a host is
728+
expected. A local file could be: file://localhost/path/to/table.csv.
729+
730+
If you want to pass in a path object, pandas accepts either
731+
``pathlib.Path`` or ``py._path.local.LocalPath``.
732+
733+
By file-like object, we refer to objects with a ``read()`` method,
734+
such as a file handler (e.g. via builtin ``open`` function)
735+
or ``StringIO``.
736+
delimiter : str, default ``'\t'+' '``
737+
Characters to consider as filler characters in the fixed-width file.
738+
Can be used to specify the filler character of the fields
739+
if it is not spaces (e.g., '~').
740+
colspecs : list of pairs (int, int) or 'infer'. optional
741+
A list of pairs (tuples) giving the extents of the fixed-width
742+
fields of each line as half-open intervals (i.e., [from, to[ ).
743+
String value 'infer' can be used to instruct the parser to try
744+
detecting the column specifications from the first 100 rows of
745+
the data which are not being skipped via skiprows (default='infer').
746+
widths : list of ints. optional
747+
A list of field widths which can be used instead of 'colspecs' if
748+
the intervals are contiguous.
749+
**kwds : optional
750+
Optional keyword arguments can be passed to ``TextFileReader``.
751+
752+
Returns
753+
-------
754+
DataFrame or TextParser
755+
A comma-separated values (csv) file is returned as two-dimensional
756+
data structure with labeled axes.
757+
758+
See Also
759+
--------
760+
to_csv : Write DataFrame to a comma-separated values (csv) file.
761+
read_csv : Read a comma-separated values (csv) file into DataFrame.
762+
read_fwf : Read a table of fixed-width formatted lines into DataFrame.
763+
764+
Examples
765+
--------
766+
>>> pd.read_fwf('data.csv') # doctest: +SKIP
767+
"""
768+
736769
# Check input arguments.
737770
if colspecs is None and widths is None:
738771
raise ValueError("Must specify either colspecs or widths")
@@ -747,6 +780,7 @@ def read_fwf(filepath_or_buffer, colspecs='infer', widths=None, **kwds):
747780
colspecs.append((col, col + w))
748781
col += w
749782

783+
kwds['delimiter'] = delimiter
750784
kwds['colspecs'] = colspecs
751785
kwds['engine'] = 'python-fwf'
752786
return _read(filepath_or_buffer, kwds)

0 commit comments

Comments
 (0)