Skip to content

Commit

Permalink
Merge pull request #1216 from quantopian/relabel-fix
Browse files Browse the repository at this point in the history
Relabel fix
  • Loading branch information
llllllllll committed Aug 23, 2015
2 parents 8b67291 + c91c800 commit fca1877
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions blaze/compute/sql.py
Expand Up @@ -686,6 +686,7 @@ def post_compute(t, s, **kwargs):

@dispatch(ReLabel, Selectable)
def compute_up(t, s, **kwargs):
s = s.alias()
columns = [getattr(s.c, col).label(new_col)
if col != new_col else
getattr(s.c, col)
Expand Down
30 changes: 27 additions & 3 deletions blaze/compute/tests/test_sql_compute.py
Expand Up @@ -16,8 +16,8 @@

from blaze.compute.sql import compute, select, lower_column, compute_up
from blaze.expr import (
symbol, discover, transform, summary, by, sin, join,
floor, cos, merge, nunique, mean, sum, count, exp, concat,
symbol, transform, summary, by, sin, join,
floor, cos, merge, nunique, mean, sum, count, exp
)
from blaze.compatibility import xfail
from blaze.utils import tmpfile, example
Expand Down Expand Up @@ -538,11 +538,35 @@ def test_label():

def test_relabel():
result = compute(t.relabel({'name': 'NAME', 'id': 'ID'}), s)
expected = select([s.c.name.label('NAME'), s.c.amount, s.c.id.label('ID')])
from_ = s.alias()
expected = select([
from_.c.name.label('NAME'),
from_.c.amount,
from_.c.id.label('ID'),
])

assert str(result) == str(expected)


def test_relabel_selection():
result = compute(
t[['name', 'id']].relabel(name='new_name', id='new_id'),
s,
)
assert normalize(str(result)) == normalize(
"""
select
anon_1.name as new_name,
anon_1.id as new_id
from
(select
accounts.name as name,
accounts.id as id
from accounts) as anon_1
""",
)


def test_merge():
col = (t['amount'] * 2).label('new')

Expand Down
2 changes: 2 additions & 0 deletions docs/source/whatsnew/0.8.3.txt
Expand Up @@ -69,3 +69,5 @@ Bug Fixes
(:issue:`1207`)
* Fixed a bug where the wrong value was being passed into
:func:`~blaze.expr.datetime.time` (:issue:`1213`)
* Fixed a bug in sql relabel that prevented relabeling anything that generated
a subselect. (:issue:`1216`)

0 comments on commit fca1877

Please sign in to comment.