Skip to content

Commit cc64192

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

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
@@ -3278,6 +3278,8 @@ def _isindex(colspec):
32783278
if is_scalar(colspec):
32793279
if isinstance(colspec, int) and colspec not in data_dict:
32803280
colspec = orig_names[colspec]
3281+
elif colspec not in orig_names:
3282+
raise ValueError(f"'{colspec}' is not in list")
32813283
if _isindex(colspec):
32823284
continue
32833285
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)