Skip to content

Commit

Permalink
allow setting new entries on sql translator
Browse files Browse the repository at this point in the history
  • Loading branch information
machow committed Aug 9, 2019
1 parent 206c851 commit b9c81d7
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions siuba/sql/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ def sql_astype(col, _type):
# TODO: generalize case where doesn't use col
# need better handeling of vector funcs
# TODO: delete this, len() is not a method anywhere, or vect func
len = lambda col: sql.func.count()
len = lambda col: sql.func.count(),
n_distinct = lambda col: sql.func.count(sql.func.distinct(col))
)

base_win = dict(
Expand Down Expand Up @@ -254,10 +255,10 @@ def sql_astype(col, _type):
# alias to LazyTbl.no_win.dense_rank...
# LazyTbl.agg.dense_rank...

from collections.abc import Mapping
from collections.abc import MutableMapping
import itertools

class SqlTranslator(Mapping):
class SqlTranslator(MutableMapping):
def __init__(self, d, **kwargs):
self.d = d
self.kwargs = kwargs
Expand All @@ -275,3 +276,10 @@ def __getitem__(self, x):
return self.kwargs[x]
except KeyError:
return self.d[x]

def __setitem__(self, k, v):
self.d[k] = v

def __delitem__(self, k):
del self.d[k]

0 comments on commit b9c81d7

Please sign in to comment.