Skip to content

Commit 53f2ea4

Browse files
author
lucas
committed
BUG: Issue 9798 fixed
BUG: #9798 `index_col` shouldn't accept the value `True` move the check to ``TextFileReader`` ``clean_options``
1 parent 9e4e447 commit 53f2ea4

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

doc/source/whatsnew/v0.16.1.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,5 @@ Bug Fixes
9696

9797
- Fixed bug where ``DataFrame.plot()`` raised an error when both ``color`` and ``style`` keywords were passed and there was no color symbol in the style strings (:issue:`9671`)
9898
- Bug in ``read_csv`` and ``read_table`` when using ``skip_rows`` parameter if blank lines are present. (:issue:`9832`)
99+
100+
- Bug in ``read_csv()`` interprets ``index_col=True`` as ``1`` (:issue:`9798`)

pandas/io/parsers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,8 @@ def _clean_options(self, options, engine):
652652
# really delete this one
653653
keep_default_na = result.pop('keep_default_na')
654654

655+
if index_col is True:
656+
raise ValueError("The value of index_col couldn't be 'True'")
655657
if _is_index_col(index_col):
656658
if not isinstance(index_col, (list, tuple, np.ndarray)):
657659
index_col = [index_col]

pandas/io/tests/test_parsers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,11 @@ def test_usecols_index_col_False(self):
520520
df = self.read_csv(StringIO(s_malformed), usecols=cols, index_col=False)
521521
tm.assert_frame_equal(expected, df)
522522

523+
def test_index_col_is_True(self):
524+
# Issue 9798
525+
self.assertRaises(ValueError, self.read_csv, StringIO(self.ts_data),
526+
index_col=True)
527+
523528
def test_converter_index_col_bug(self):
524529
# 1835
525530
data = "A;B\n1;2\n3;4"

0 commit comments

Comments
 (0)