Fix for transpose().transpose() with duplicate keys

#199
This commit is contained in:
2016-02-07 07:29:08 -05:00
parent 1ec9c18a66
commit fcc9700d11
2 changed files with 12 additions and 4 deletions
+3 -3
View File
@@ -895,17 +895,17 @@ class Dataset(object):
new_headers = [self.headers[0]] + self[self.headers[0]]
_dset.headers = new_headers
for column in self.headers:
for index, column in enumerate(self.headers):
if column == self.headers[0]:
# It's in the headers, so skip it
continue
# Adding the column name as now they're a regular column
row_data = [column] + self[column]
# Use `get_col(index)` in case there are repeated values
row_data = [column] + self.get_col(index)
row_data = Row(row_data)
_dset.append(row=row_data)
return _dset
+9 -1
View File
@@ -241,7 +241,6 @@ class TablibTestCase(unittest.TestCase):
# Delete from invalid index
self.assertRaises(IndexError, self.founders.__delitem__, 3)
def test_csv_export(self):
"""Verify exporting dataset object as CSV."""
@@ -738,6 +737,15 @@ class TablibTestCase(unittest.TestCase):
self.assertEqual(second_row,
("gpa",90, 67, 50))
def test_transpose_multiple_headers(self):
data = tablib.Dataset()
data.headers = ("first_name", "last_name", "age")
data.append(('John', 'Adams', 90))
data.append(('George', 'Washington', 67))
data.append(('John', 'Tyler', 71))
self.assertEqual(data.transpose().transpose().dict, data.dict)
def test_row_stacking(self):
"""Row stacking."""