Skip to content

Commit

Permalink
Treat columns as ordered throughout code
Browse files Browse the repository at this point in the history
The set() does not make anything any easier,
lists are closer to underlying representation.
  • Loading branch information
stefanw committed Jan 31, 2014
1 parent 89ebd62 commit 8f4cd59
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
7 changes: 5 additions & 2 deletions dataset/persistence/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def columns(self):
"""
Get a listing of all columns that exist in the table.
"""
return set(self.table.columns.keys())
return list(self.table.columns.keys())

def drop(self):
"""
Expand Down Expand Up @@ -184,7 +184,10 @@ def delete(self, **_filter):
self.database.executable.execute(stmt)

def _ensure_columns(self, row, types={}):
for column in set(row.keys()) - set(self.table.columns.keys()):
# Keep order of inserted columns
for column in row.keys():
if column in self.table.columns.keys():
continue
if column in types:
_type = types[column]
else:
Expand Down
4 changes: 2 additions & 2 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ database:

Now, let's list all columns available in the table ``user``:

>>> print db['user'].columns
set([u'id', u'name', u'email', u'pwd', u'country'])
>>> print(db['user'].columns)
[u'id', u'name', u'email', u'pwd', u'country']

Using ``len()`` we can get the total number of rows in a table:

Expand Down
3 changes: 1 addition & 2 deletions test/test_persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,7 @@ def test_drop_warning(self):

def test_columns(self):
cols = self.tbl.columns
assert isinstance(cols, set), 'columns should be a set'
assert len(cols) == 4, 'column count mismatch'
assert len(list(cols)) == 4, 'column count mismatch'
assert 'date' in cols and 'temperature' in cols and 'place' in cols

def test_iter(self):
Expand Down

0 comments on commit 8f4cd59

Please sign in to comment.