Skip to content

Commit 6f65882

Browse files
committed
ENH: allow duplicates in index when parsing file, close #1173
1 parent dd89d21 commit 6f65882

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

pandas/io/parsers.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -653,12 +653,12 @@ def get_chunk(self, rows=None):
653653
else:
654654
index = Index(np.arange(len(content)))
655655

656-
if not index.is_unique:
657-
dups = index.get_duplicates()
658-
idx_str = 'Index' if not self._implicit_index else 'Implicit index'
659-
err_msg = ('%s (columns %s) have duplicate values %s'
660-
% (idx_str, self.index_col, str(dups)))
661-
raise Exception(err_msg)
656+
# if not index.is_unique:
657+
# dups = index.get_duplicates()
658+
# idx_str = 'Index' if not self._implicit_index else 'Implicit index'
659+
# err_msg = ('%s (columns %s) have duplicate values %s'
660+
# % (idx_str, self.index_col, str(dups)))
661+
# raise Exception(err_msg)
662662

663663
if len(self.columns) != len(zipped_content):
664664
raise Exception('wrong number of columns')

pandas/io/tests/test_parsers.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,10 @@ def test_read_table_duplicate_index(self):
325325
bar,12,13,14,15
326326
"""
327327

328-
self.assertRaises(Exception, read_csv, StringIO(data),
329-
index_col=0)
328+
result = read_csv(StringIO(data), index_col=0)
329+
expected = read_csv(StringIO(data)).set_index('index',
330+
verify_integrity=False)
331+
assert_frame_equal(result, expected)
330332

331333
def test_read_table_duplicate_index_implicit(self):
332334
data = """A,B,C,D
@@ -338,8 +340,8 @@ def test_read_table_duplicate_index_implicit(self):
338340
bar,12,13,14,15
339341
"""
340342

341-
self.assertRaises(Exception, read_csv, StringIO(data),
342-
index_col=0)
343+
# it works!
344+
result = read_csv(StringIO(data))
343345

344346
def test_parse_bools(self):
345347
data = """A,B

0 commit comments

Comments
 (0)