Repository: pudo/dataset

Issue:
Distinct does not support advanced queries
It looks like `.distinct` does not support advanced selections e.g. `table.distinct('key', key=[...])` like `.find` or `.count`. Is there a reason or is it just an oversight as it does not use `._args_to_clause` ?

Discussion:

Patch:
diff --git a/dataset/database.py b/dataset/database.py
index 8662b81..9f4276f 100644
--- a/dataset/database.py
+++ b/dataset/database.py
@@ -221,10 +221,6 @@ class Database(object):
         """Get a given table."""
         return self.get_table(table_name)
 
-    def _ipython_key_completions_(self):
-        """Completion for table names with IPython."""
-        return self.tables
-
     def query(self, query, *args, **kwargs):
         """Run a statement on the database directly.
 
diff --git a/dataset/table.py b/dataset/table.py
index 2bd5c55..bf829df 100644
--- a/dataset/table.py
+++ b/dataset/table.py
@@ -546,27 +546,23 @@ class Table(object):
         if not self.exists:
             return iter([])
 
-        filters = []
-        for column, value in _filter.items():
-            if not self.has_column(column):
-                raise DatasetException("No such column: %s" % column)
-            filters.append(self.table.c[column] == value)
-
         columns = []
+        clauses = []
         for column in args:
             if isinstance(column, ClauseElement):
-                filters.append(column)
+                clauses.append(column)
             else:
                 if not self.has_column(column):
                     raise DatasetException("No such column: %s" % column)
                 columns.append(self.table.c[column])
 
+        clause = self._args_to_clause(_filter, clauses=clauses)
         if not len(columns):
             return iter([])
 
         q = expression.select(columns,
                               distinct=True,
-                              whereclause=and_(*filters),
+                              whereclause=clause,
                               order_by=[c.asc() for c in columns])
         return self.db.query(q)
 


Test patch:
diff --git a/test/test_dataset.py b/test/test_dataset.py
index 4cd0645..6c5be07 100644
--- a/test/test_dataset.py
+++ b/test/test_dataset.py
@@ -360,6 +360,12 @@ class TableTestCase(unittest.TestCase):
             self.tbl.table.columns.date >= datetime(2011, 1, 2, 0, 0)))
         assert len(x) == 4, x
 
+        x = list(self.tbl.distinct('temperature', place='B€rkeley'))
+        assert len(x) == 3, x
+        x = list(self.tbl.distinct('temperature',
+                                   place=['B€rkeley', 'G€lway']))
+        assert len(x) == 6, x
+
     def test_insert_many(self):
         data = TEST_DATA * 100
         self.tbl.insert_many(data, chunk_size=13)