diff --git a/dataset/table.py b/dataset/table.py index 732964c..3fd0ff1 100644 --- a/dataset/table.py +++ b/dataset/table.py @@ -675,7 +675,7 @@ class Table(object): """Return the number of rows in the table.""" return self.count() - def distinct(self, *args, **_filter): + def distinct(self, *args, **kwargs): """Return all the unique (distinct) values for the given ``columns``. :: @@ -699,7 +699,9 @@ class Table(object): raise DatasetException("No such column: %s" % column) columns.append(self.table.c[column]) - clause = self._args_to_clause(_filter, clauses=clauses) + _limit = kwargs.pop("_limit", None) + _offset = kwargs.pop("_offset", 0) + clause = self._args_to_clause(kwargs, clauses=clauses) if not len(columns): return iter([]) @@ -707,6 +709,8 @@ class Table(object): columns, distinct=True, whereclause=clause, + limit=_limit, + offset=_offset, order_by=[c.asc() for c in columns], ) return self.db.query(q) diff --git a/test/test_dataset.py b/test/test_dataset.py index f7c94eb..41058f9 100644 --- a/test/test_dataset.py +++ b/test/test_dataset.py @@ -384,6 +384,10 @@ class TableTestCase(unittest.TestCase): assert len(x) == 3, x x = list(self.tbl.distinct("temperature", place=["B€rkeley", "G€lway"])) assert len(x) == 6, x + x = list(self.tbl.distinct("temperature", _limit=3, place=["B€rkeley", "G€lway"])) + assert len(x) == 3, x + x = list(self.tbl.distinct("temperature", _limit=6, _offset=1, place=["B€rkeley", "G€lway"])) + assert len(x) == 5, x def test_insert_many(self): data = TEST_DATA * 100