Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first_n, last_n, max_n and min_n reductions #1184

Merged
merged 8 commits into from
Mar 6, 2023
Merged
14 changes: 10 additions & 4 deletions datashader/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,20 @@ def make_append(bases, cols, calls, glyph, categorical, antialias):
if antialias:
args.append("aa_factor")

body.append('{0}(x, y, {1})'.format(func_name, ', '.join(args)))

where_reduction = len(bases) == 1 and isinstance(bases[0], where)
if where_reduction:
update_index_arg_name = next(names)
args.append(update_index_arg_name)

# where reduction needs access to the return of the contained
# reduction, which is the preceding one here.
body[-2] = 'if ' + body[-2] + ' >= 0:'
body[-1] = ' ' + body[-1]
body[-1] = f'{update_index_arg_name} = {body[-1]}'
body.append(f'if {update_index_arg_name} >= 0:')
call = ' {0}(x, y, {1})'.format(func_name, ', '.join(args))
else:
call = '{0}(x, y, {1})'.format(func_name, ', '.join(args))

body.append(call)

body = ['{0} = {1}[y, x]'.format(name, arg_lk[agg])
for agg, name in local_lk.items()] + body
Expand Down
25 changes: 14 additions & 11 deletions datashader/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def line(self, source, x=None, y=None, agg=None, axis=0, geometry=None,

if not isinstance(non_cat_agg, (
rd.any, rd.count, rd.max, rd.min, rd.sum, rd.summary, rd._sum_zero,
rd.first, rd.last, rd.mean, rd.where
rd.first, rd.last, rd.mean
)):
raise NotImplementedError(
f"{type(non_cat_agg)} reduction not implemented for antialiased lines")
Expand Down Expand Up @@ -1312,16 +1312,19 @@ def _cols_to_keep(columns, glyph, agg):
for col in glyph.required_columns():
cols_to_keep[col] = True

if hasattr(agg, 'values'):
for subagg in agg.values:
if subagg.column is not None:
cols_to_keep[subagg.column] = True
elif hasattr(agg, 'columns'):
for column in agg.columns:
if column is not None:
cols_to_keep[column] = True
elif agg.column is not None:
cols_to_keep[agg.column] = True
def recurse(cols_to_keep, agg):
if hasattr(agg, 'values'):
for subagg in agg.values:
recurse(cols_to_keep, subagg)
elif hasattr(agg, 'columns'):
for column in agg.columns:
if column is not None:
cols_to_keep[column] = True
elif agg.column is not None:
cols_to_keep[agg.column] = True

recurse(cols_to_keep, agg)

return [col for col, keepit in cols_to_keep.items() if keepit]


Expand Down
2 changes: 0 additions & 2 deletions datashader/glyphs/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -1096,11 +1096,9 @@ def _aa_stage_2_clear(aggs_and_copies, antialias_zeroes):

@ngjit
def _aa_stage_2_copy_back(aggs_and_copies):
k = 0
# Numba access to heterogeneous tuples is only permitted using literal_unroll.
for agg_and_copy in literal_unroll(aggs_and_copies):
agg_and_copy[0][:] = agg_and_copy[1][:]
k += 1


def _build_extend_line_axis0_multi(draw_segment, expand_aggs_and_cols, use_2_stage_agg):
Expand Down
Loading