mirror of
https://github.com/kennethreitz/tablib.git
synced 2026-06-05 15:00:19 +00:00
+6
-6
@@ -940,7 +940,7 @@ class Dataset(object):
|
||||
return _dset
|
||||
|
||||
|
||||
def unique(self):
|
||||
def remove_duplicates(self):
|
||||
"""Removes all duplicate rows from the :class:`Dataset` object
|
||||
while maintaining the original order."""
|
||||
seen = set()
|
||||
@@ -961,19 +961,19 @@ class Dataset(object):
|
||||
# Don't return if no data
|
||||
if not self:
|
||||
return
|
||||
|
||||
|
||||
if rows is None:
|
||||
rows = list(range(self.height))
|
||||
|
||||
|
||||
if cols is None:
|
||||
cols = list(self.headers)
|
||||
|
||||
|
||||
#filter out impossible rows and columns
|
||||
rows = [row for row in rows if row in range(self.height)]
|
||||
cols = [header for header in cols if header in self.headers]
|
||||
|
||||
_dset = Dataset()
|
||||
|
||||
|
||||
#filtering rows and columns
|
||||
_dset.headers = list(cols)
|
||||
|
||||
@@ -989,7 +989,7 @@ class Dataset(object):
|
||||
|
||||
if row_no in rows:
|
||||
_dset.append(row=Row(data_row))
|
||||
|
||||
|
||||
return _dset
|
||||
|
||||
|
||||
|
||||
+5
-5
@@ -794,7 +794,7 @@ class TablibTestCase(unittest.TestCase):
|
||||
self.assertEqual(third_row, expected_third)
|
||||
|
||||
|
||||
def test_unique(self):
|
||||
def test_remove_duplicates(self):
|
||||
"""Unique Rows."""
|
||||
|
||||
self.founders.append(self.john)
|
||||
@@ -805,7 +805,7 @@ class TablibTestCase(unittest.TestCase):
|
||||
self.assertEqual(self.founders[2], self.founders[5])
|
||||
self.assertEqual(self.founders.height, 6)
|
||||
|
||||
self.founders.unique()
|
||||
self.founders.remove_duplicates()
|
||||
|
||||
self.assertEqual(self.founders[0], self.john)
|
||||
self.assertEqual(self.founders[1], self.george)
|
||||
@@ -832,16 +832,16 @@ class TablibTestCase(unittest.TestCase):
|
||||
|
||||
def test_subset(self):
|
||||
"""Create a subset of a dataset"""
|
||||
|
||||
|
||||
rows = (0, 2)
|
||||
columns = ('first_name','gpa')
|
||||
|
||||
|
||||
data.headers = self.headers
|
||||
|
||||
data.append(self.john)
|
||||
data.append(self.george)
|
||||
data.append(self.tom)
|
||||
|
||||
|
||||
#Verify data is truncated
|
||||
subset = data.subset(rows=rows, cols=columns)
|
||||
self.assertEqual(type(subset), tablib.Dataset)
|
||||
|
||||
Reference in New Issue
Block a user