Skip to content

Commit 0033f0a

Browse files
committed
TST: tweak #2733 test and raise exception when usecols + python engine
1 parent 86a3cb2 commit 0033f0a

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

pandas/io/parsers.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ def _read(filepath_or_buffer, kwds):
245245
'dayfirst': False,
246246
'date_parser': None,
247247

248+
'usecols': None,
249+
248250
# 'nrows': None,
249251
# 'iterator': False,
250252
'chunksize': None,
@@ -268,7 +270,6 @@ def _read(filepath_or_buffer, kwds):
268270
'warn_bad_lines': True,
269271
'factorize': True,
270272
'dtype': None,
271-
'usecols': None,
272273
'decimal': b'.'
273274
}
274275

@@ -1120,6 +1121,10 @@ def __init__(self, f, **kwds):
11201121
self.buf = []
11211122
self.pos = 0
11221123

1124+
if kwds['usecols'] is not None:
1125+
raise Exception("usecols not supported with engine='python'"
1126+
" or multicharacter separators (yet).")
1127+
11231128
self.header = kwds['header']
11241129
self.encoding = kwds['encoding']
11251130
self.compression = kwds['compression']

pandas/io/tests/test_parsers.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -1869,7 +1869,6 @@ def test_usecols_implicit_index_col(self):
18691869
tm.assert_frame_equal(result, expected)
18701870

18711871
def test_usecols_with_whitespace(self):
1872-
# #2733
18731872
data = 'a b c\n4 apple bat 5.7\n8 orange cow 10'
18741873

18751874
result = self.read_csv(StringIO(data), delim_whitespace=True,
@@ -1879,6 +1878,17 @@ def test_usecols_with_whitespace(self):
18791878

18801879
tm.assert_frame_equal(result, expected)
18811880

1881+
def test_usecols_regex_sep(self):
1882+
# #2733
1883+
data = 'a b c\n4 apple bat 5.7\n8 orange cow 10'
1884+
1885+
self.assertRaises(Exception, self.read_csv, StringIO(data),
1886+
sep='\s+', usecols=('a', 'b'))
1887+
1888+
# expected = DataFrame({'a': ['apple', 'orange'],
1889+
# 'b': ['bat', 'cow']}, index=[4, 8])
1890+
# tm.assert_frame_equal(result, expected)
1891+
18821892
def test_pure_python_failover(self):
18831893
data = "a,b,c\n1,2,3#ignore this!\n4,5,6#ignorethistoo"
18841894

0 commit comments

Comments
 (0)