diff --git a/doc/source/whatsnew/v0.18.2.txt b/doc/source/whatsnew/v0.18.2.txt index 8b80901774828..105194e504f45 100644 --- a/doc/source/whatsnew/v0.18.2.txt +++ b/doc/source/whatsnew/v0.18.2.txt @@ -358,6 +358,7 @@ Bug Fixes - Bug in ``pd.read_csv()`` with ``engine='python'`` in which infinities of mixed-case forms were not being interpreted properly (:issue:`13274`) - Bug in ``pd.read_csv()`` with ``engine='python'`` in which trailing ``NaN`` values were not being parsed (:issue:`13320`) - Bug in ``pd.read_csv()`` that prevents ``usecols`` kwarg from accepting single-byte unicode strings (:issue:`13219`) +- Bug in ``pd.read_csv()`` that prevents ``usecols`` from being an empty set (:issue:`13402`) diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index 4e954979f7d08..475eb73812666 100755 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -944,7 +944,8 @@ def _validate_usecols_arg(usecols): if usecols is not None: usecols_dtype = lib.infer_dtype(usecols) - if usecols_dtype not in ('integer', 'string', 'unicode'): + if usecols_dtype not in ('empty', 'integer', + 'string', 'unicode'): raise ValueError(msg) return usecols diff --git a/pandas/io/tests/parser/usecols.py b/pandas/io/tests/parser/usecols.py index 0d3ae95f0d1d4..8e34018df279b 100644 --- a/pandas/io/tests/parser/usecols.py +++ b/pandas/io/tests/parser/usecols.py @@ -354,3 +354,10 @@ def test_usecols_with_multibyte_unicode_characters(self): df = self.read_csv(StringIO(s), usecols=[u'あああ', u'いい']) tm.assert_frame_equal(df, expected) + + def test_empty_usecols(self): + # should not raise + data = 'a,b,c\n1,2,3\n4,5,6' + expected = DataFrame() + result = self.read_csv(StringIO(data), usecols=set([])) + tm.assert_frame_equal(result, expected)