Skip to content

Commit 1055eae

Browse files
committed
Merge pull request pandas-dev#4774 from jtratner/fix_fwf_error_msg
BUG: read_fwf: incorrect error message with no colspecs or widths
2 parents 08c191c + 3c95f7e commit 1055eae

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

doc/source/release.rst

+1
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ See :ref:`Internal Refactoring<whatsnew_0130.refactoring>`
335335
- Bug in setting with ``loc/ix`` a single indexer with a multi-index axis and a numpy array, related to (:issue:`3777`)
336336
- Bug in concatenation with duplicate columns across dtypes not merging with axis=0 (:issue:`4771`)
337337
- Bug in ``iloc`` with a slice index failing (:issue:`4771`)
338+
- Incorrect error message with no colspecs or width in ``read_fwf``. (:issue:`4774`)
338339

339340
pandas 0.12
340341
===========

pandas/io/parsers.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,9 @@ def parser_f(filepath_or_buffer,
414414
@Appender(_read_fwf_doc)
415415
def read_fwf(filepath_or_buffer, colspecs=None, widths=None, **kwds):
416416
# Check input arguments.
417-
if bool(colspecs is None) == bool(widths is None):
417+
if colspecs is None and widths is None:
418+
raise ValueError("Must specify either colspecs or widths")
419+
elif colspecs is not None and widths is not None:
418420
raise ValueError("You must specify only one of 'widths' and "
419421
"'colspecs'")
420422

pandas/io/tests/test_parsers.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1995,8 +1995,11 @@ def test_fwf(self):
19951995
StringIO(data3), colspecs=colspecs, delimiter='~', header=None)
19961996
tm.assert_frame_equal(df, expected)
19971997

1998-
self.assertRaises(ValueError, read_fwf, StringIO(data3),
1999-
colspecs=colspecs, widths=[6, 10, 10, 7])
1998+
with tm.assertRaisesRegexp(ValueError, "must specify only one of"):
1999+
read_fwf(StringIO(data3), colspecs=colspecs, widths=[6, 10, 10, 7])
2000+
2001+
with tm.assertRaisesRegexp(ValueError, "Must specify either"):
2002+
read_fwf(StringIO(data3))
20002003

20012004
def test_fwf_regression(self):
20022005
# GH 3594

0 commit comments

Comments
 (0)