Skip to content

Commit ae4ffac

Browse files
gfyoungjorisvandenbossche
authored andcommitted
BUG: Don't error when usecols is a numpy array (#14055)
Closes gh-12546.
1 parent 86a36f7 commit ae4ffac

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

doc/source/whatsnew/v0.19.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,7 @@ Bug Fixes
958958
- Bug in ``groupby().cumsum()`` calculating ``cumprod`` when ``axis=1``. (:issue:`13994`)
959959
- Bug in ``pd.read_csv()``, which may cause a segfault or corruption when iterating in large chunks over a stream/file under rare circumstances (:issue:`13703`)
960960
- Bug in ``pd.read_csv()``, which caused BOM files to be incorrectly parsed by not ignoring the BOM (:issue:`4793`)
961+
- Bug in ``pd.read_csv()`` with ``engine='python'`` which raised errors when a numpy array was passed in for ``usecols`` (:issue:`12546`)
961962
- Bug in ``pd.to_timedelta()`` in which the ``errors`` parameter was not being respected (:issue:`13613`)
962963
- Bug in ``io.json.json_normalize()``, where non-ascii keys raised an exception (:issue:`13213`)
963964
- Bug when passing a not-default-indexed ``Series`` as ``xerr`` or ``yerr`` in ``.plot()`` (:issue:`11858`)

pandas/io/parsers.py

+1
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,7 @@ def _validate_usecols_arg(usecols):
972972
'string', 'unicode'):
973973
raise ValueError(msg)
974974

975+
return set(usecols)
975976
return usecols
976977

977978

pandas/io/tests/parser/usecols.py

+10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from datetime import datetime
99
import nose
1010

11+
import numpy as np
1112
import pandas.util.testing as tm
1213

1314
from pandas import DataFrame
@@ -361,3 +362,12 @@ def test_empty_usecols(self):
361362
expected = DataFrame()
362363
result = self.read_csv(StringIO(data), usecols=set([]))
363364
tm.assert_frame_equal(result, expected)
365+
366+
def test_np_array_usecols(self):
367+
# See gh-12546
368+
data = 'a,b,c\n1,2,3'
369+
usecols = np.array(['a', 'b'])
370+
371+
expected = DataFrame([[1, 2]], columns=usecols)
372+
result = self.read_csv(StringIO(data), usecols=usecols)
373+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)