Skip to content

Commit 3eb4784

Browse files
gfyoungjreback
authored andcommitted
BUG: don't raise on empty usecols
Title is self-explanatory. Author: gfyoung <[email protected]> Closes #13402 from gfyoung/empty-usecols-bug and squashes the following commits: 8eed8d1 [gfyoung] BUG: don't raise on empty usecols
1 parent d405bf2 commit 3eb4784

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

doc/source/whatsnew/v0.18.2.txt

+1
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ Bug Fixes
358358
- Bug in ``pd.read_csv()`` with ``engine='python'`` in which infinities of mixed-case forms were not being interpreted properly (:issue:`13274`)
359359
- Bug in ``pd.read_csv()`` with ``engine='python'`` in which trailing ``NaN`` values were not being parsed (:issue:`13320`)
360360
- Bug in ``pd.read_csv()`` that prevents ``usecols`` kwarg from accepting single-byte unicode strings (:issue:`13219`)
361+
- Bug in ``pd.read_csv()`` that prevents ``usecols`` from being an empty set (:issue:`13402`)
361362

362363

363364

pandas/io/parsers.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,8 @@ def _validate_usecols_arg(usecols):
944944

945945
if usecols is not None:
946946
usecols_dtype = lib.infer_dtype(usecols)
947-
if usecols_dtype not in ('integer', 'string', 'unicode'):
947+
if usecols_dtype not in ('empty', 'integer',
948+
'string', 'unicode'):
948949
raise ValueError(msg)
949950

950951
return usecols

pandas/io/tests/parser/usecols.py

+7
Original file line numberDiff line numberDiff line change
@@ -354,3 +354,10 @@ def test_usecols_with_multibyte_unicode_characters(self):
354354

355355
df = self.read_csv(StringIO(s), usecols=[u'あああ', u'いい'])
356356
tm.assert_frame_equal(df, expected)
357+
358+
def test_empty_usecols(self):
359+
# should not raise
360+
data = 'a,b,c\n1,2,3\n4,5,6'
361+
expected = DataFrame()
362+
result = self.read_csv(StringIO(data), usecols=set([]))
363+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)