diff --git a/doc/source/release.rst b/doc/source/release.rst index 96527d0161687..66ac9d813f056 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -335,6 +335,7 @@ See :ref:`Internal Refactoring` - Bug in setting with ``loc/ix`` a single indexer with a multi-index axis and a numpy array, related to (:issue:`3777`) - Bug in concatenation with duplicate columns across dtypes not merging with axis=0 (:issue:`4771`) - Bug in ``iloc`` with a slice index failing (:issue:`4771`) + - Incorrect error message with no colspecs or width in ``read_fwf``. (:issue:`4774`) pandas 0.12 =========== diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index 8cf7eaa1b19e3..f05b0a676cde4 100644 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -414,7 +414,9 @@ def parser_f(filepath_or_buffer, @Appender(_read_fwf_doc) def read_fwf(filepath_or_buffer, colspecs=None, widths=None, **kwds): # Check input arguments. - if bool(colspecs is None) == bool(widths is None): + if colspecs is None and widths is None: + raise ValueError("Must specify either colspecs or widths") + elif colspecs is not None and widths is not None: raise ValueError("You must specify only one of 'widths' and " "'colspecs'") diff --git a/pandas/io/tests/test_parsers.py b/pandas/io/tests/test_parsers.py index 6668cfd73a6b7..9d751de6645ce 100644 --- a/pandas/io/tests/test_parsers.py +++ b/pandas/io/tests/test_parsers.py @@ -1995,8 +1995,11 @@ def test_fwf(self): StringIO(data3), colspecs=colspecs, delimiter='~', header=None) tm.assert_frame_equal(df, expected) - self.assertRaises(ValueError, read_fwf, StringIO(data3), - colspecs=colspecs, widths=[6, 10, 10, 7]) + with tm.assertRaisesRegexp(ValueError, "must specify only one of"): + read_fwf(StringIO(data3), colspecs=colspecs, widths=[6, 10, 10, 7]) + + with tm.assertRaisesRegexp(ValueError, "Must specify either"): + read_fwf(StringIO(data3)) def test_fwf_regression(self): # GH 3594