Skip to content

BUG: read_fwf: incorrect error message with no colspecs or widths #4774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 8, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ See :ref:`Internal Refactoring<whatsnew_0130.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
===========
Expand Down
4 changes: 3 additions & 1 deletion pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'")

Expand Down
7 changes: 5 additions & 2 deletions pandas/io/tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down