diff --git a/doc/source/whatsnew/v0.16.1.txt b/doc/source/whatsnew/v0.16.1.txt index dcddcaaad36d0..9f989b2cf0ea9 100644 --- a/doc/source/whatsnew/v0.16.1.txt +++ b/doc/source/whatsnew/v0.16.1.txt @@ -96,3 +96,5 @@ Bug Fixes - 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`) - Bug in ``read_csv`` and ``read_table`` when using ``skip_rows`` parameter if blank lines are present. (:issue:`9832`) + +- Bug in ``read_csv()`` interprets ``index_col=True`` as ``1`` (:issue:`9798`) diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index 637612d5fb09d..786d308c6770f 100644 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -652,6 +652,8 @@ def _clean_options(self, options, engine): # really delete this one keep_default_na = result.pop('keep_default_na') + if index_col is True: + raise ValueError("The value of index_col couldn't be 'True'") if _is_index_col(index_col): if not isinstance(index_col, (list, tuple, np.ndarray)): index_col = [index_col] diff --git a/pandas/io/tests/test_parsers.py b/pandas/io/tests/test_parsers.py index e549ec674b18d..b7016ad6cffae 100644 --- a/pandas/io/tests/test_parsers.py +++ b/pandas/io/tests/test_parsers.py @@ -520,6 +520,11 @@ def test_usecols_index_col_False(self): df = self.read_csv(StringIO(s_malformed), usecols=cols, index_col=False) tm.assert_frame_equal(expected, df) + def test_index_col_is_True(self): + # Issue 9798 + self.assertRaises(ValueError, self.read_csv, StringIO(self.ts_data), + index_col=True) + def test_converter_index_col_bug(self): # 1835 data = "A;B\n1;2\n3;4"