Skip to content

Commit 8225c8b

Browse files
committed
BUG: parase_dates column is in dataframe (pandas-dev#31251)
1 parent ca84bd0 commit 8225c8b

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

pandas/io/parsers.py

+2
Original file line numberDiff line numberDiff line change
@@ -3282,6 +3282,8 @@ def _isindex(colspec):
32823282
if is_scalar(colspec):
32833283
if isinstance(colspec, int) and colspec not in data_dict:
32843284
colspec = orig_names[colspec]
3285+
elif colspec not in orig_names:
3286+
raise ValueError(f"'{colspec}' is not in list")
32853287
if _isindex(colspec):
32863288
continue
32873289
data_dict[colspec] = converter(data_dict[colspec])

pandas/tests/io/parser/test_parse_dates.py

+11
Original file line numberDiff line numberDiff line change
@@ -1516,3 +1516,14 @@ def test_hypothesis_delimited_date(date_format, dayfirst, delimiter, test_dateti
15161516

15171517
assert except_out_dateutil == except_in_dateutil
15181518
assert result == expected
1519+
1520+
1521+
def test_missing_column(all_parsers):
1522+
parser = all_parsers
1523+
content = StringIO("time,val\n" "212.23, 32\n")
1524+
date_cols = ["time"]
1525+
msg = "'time' is not in list"
1526+
with pytest.raises(ValueError, match=msg):
1527+
parser.read_csv(
1528+
content, sep=",", usecols=["val"], parse_dates=date_cols,
1529+
)

0 commit comments

Comments
 (0)