Skip to content

Commit f4aef5e

Browse files
author
Lucas Kushner
committed
Clarify whitespace behavior in read_fwf documentation (#16772)
1 parent 80e40f8 commit f4aef5e

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

pandas/io/parsers.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@
6363
file. For file URLs, a host is expected. For instance, a local file could
6464
be file ://localhost/path/to/table.csv
6565
%s
66-
delimiter : str, default ``None``
67-
Alternative argument name for sep.
6866
delim_whitespace : boolean, default False
6967
Specifies whether or not whitespace (e.g. ``' '`` or ``'\t'``) will be
7068
used as the sep. Equivalent to setting ``sep='\s+'``. If this option
@@ -316,7 +314,9 @@
316314
be used automatically. In addition, separators longer than 1 character and
317315
different from ``'\s+'`` will be interpreted as regular expressions and
318316
will also force the use of the Python parsing engine. Note that regex
319-
delimiters are prone to ignoring quoted data. Regex example: ``'\r\t'``"""
317+
delimiters are prone to ignoring quoted data. Regex example: ``'\r\t'``
318+
delimiter : str, default ``None``
319+
Alternative argument name for sep."""
320320

321321
_read_csv_doc = """
322322
Read CSV (comma-separated) file into DataFrame
@@ -341,15 +341,16 @@
341341
widths : list of ints. optional
342342
A list of field widths which can be used instead of 'colspecs' if
343343
the intervals are contiguous.
344+
delimiter: str, default ``\t ``
345+
Characters to consider as filler characters in the fixed-width file.
346+
Can be used to specify the filler character of the fields
347+
if it is not spaces (e.g., '~').
344348
"""
345349

346350
_read_fwf_doc = """
347351
Read a table of fixed-width formatted lines into DataFrame
348352
349353
%s
350-
351-
Also, 'delimiter' is used to specify the filler character of the
352-
fields if it is not spaces (e.g., '~').
353354
""" % (_parser_params % (_fwf_widths, ''))
354355

355356

pandas/tests/io/parser/test_read_fwf.py

+12
Original file line numberDiff line numberDiff line change
@@ -405,3 +405,15 @@ def test_skiprows_inference_empty(self):
405405

406406
with pytest.raises(EmptyDataError):
407407
read_fwf(StringIO(test), skiprows=3)
408+
409+
def test_whitespace_preservation(self):
410+
data_expected = """ a ,bbb
411+
cc,dd """
412+
expected = read_csv(StringIO(data_expected), header=None)
413+
414+
test_data = """ a bbb
415+
ccdd """
416+
df = read_fwf(StringIO(test_data), widths=[3, 3],
417+
header=None, delimiter="\n")
418+
419+
tm.assert_frame_equal(df, expected)

0 commit comments

Comments
 (0)