Skip to content

Commit 3c95f7e

Browse files
committed
BUG: read_fwf: incorrect error message with no colspecs or widths
1 parent 08c191c commit 3c95f7e

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

doc/source/release.rst

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 5 additions & 2 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy