-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BUG: Thoroughly dedup columns in read_csv
- Loading branch information
Showing
6 changed files
with
61 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
Tests that duplicate columns are handled appropriately when parsed by the | ||
CSV engine. They are either ignored or are thoroughly de-duplicated. | ||
""" | ||
|
||
from pandas.compat import StringIO | ||
|
||
|
||
class DupeColumnTests(object): | ||
def test_basic(self): | ||
# TODO: add test for condition "mangle_dupe_cols=False" | ||
# once it is actually supported (gh-12935) | ||
data = "a,a,b,b,b\n1,2,3,4,5" | ||
|
||
for method in ("read_csv", "read_table"): | ||
# Check default behavior. | ||
expected = ["a", "a.1", "b", "b.1", "b.2"] | ||
df = getattr(self, method)(StringIO(data), sep=",") | ||
assert list(df.columns) == expected | ||
|
||
df = getattr(self, method)(StringIO(data), sep=",", | ||
mangle_dupe_cols=True) | ||
assert list(df.columns) == expected | ||
|
||
def test_thorough_mangle(self): | ||
# see gh-17060 | ||
data = "a,a,a.1\n1,2,3" | ||
df = self.read_csv(StringIO(data), sep=",", mangle_dupe_cols=True) | ||
assert list(df.columns) == ["a", "a.1", "a.1.1"] | ||
|
||
data = "a,a,a.1,a.1.1,a.1.1.1,a.1.1.1.1\n1,2,3,4,5,6" | ||
df = self.read_csv(StringIO(data), sep=",", mangle_dupe_cols=True) | ||
assert list(df.columns) == ["a", "a.1", "a.1.1", "a.1.1.1", | ||
"a.1.1.1.1", "a.1.1.1.1.1"] | ||
|
||
data = "a,a,a.3,a.1,a.2,a,a\n1,2,3,4,5,6,7" | ||
df = self.read_csv(StringIO(data), sep=",", mangle_dupe_cols=True) | ||
assert list(df.columns) == ["a", "a.1", "a.3", "a.1.1", | ||
"a.2", "a.2.1", "a.3.1"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters