Skip to content

Commit

Permalink
Rename index column to __index__ to reduce likelyhood of collision
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro committed Oct 15, 2024
1 parent 14849d5 commit 2be0c36
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions holoviews/operation/datashader.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,9 @@ def _process(self, element, key=None):
if sel_fn:
if isinstance(params["vdims"], (Dimension, str)):
params["vdims"] = [params["vdims"]]
sum_agg = ds.summary(**{str(params["vdims"][0]): agg_fn, "index": ds.where(sel_fn)})
sum_agg = ds.summary(**{str(params["vdims"][0]): agg_fn, "__index__": ds.where(sel_fn)})
agg = self._apply_datashader(dfdata, cvs_fn, sum_agg, agg_kwargs, x, y)
_ignore = [*params["vdims"], "index"]
_ignore = [*params["vdims"], "__index__"]
sel_vdims = [s for s in agg if s not in _ignore]
params["vdims"] = [*params["vdims"], *sel_vdims]
else:
Expand Down Expand Up @@ -422,13 +422,13 @@ def _apply_datashader(self, dfdata, cvs_fn, agg_fn, agg_kwargs, x, y):
agg = cvs_fn(dfdata, x.name, y.name, agg_fn, **agg_kwargs)

is_where_index = ds15 and isinstance(agg_fn, ds.where) and isinstance(agg_fn.column, rd.SpecialColumn)
is_summary_index = isinstance(agg_fn, ds.summary) and "index" in agg
is_summary_index = isinstance(agg_fn, ds.summary) and "__index__" in agg
if is_where_index or is_summary_index:
if is_where_index:
data = agg.data
agg = agg.to_dataset(name="index")
agg = agg.to_dataset(name="__index__")
else: # summary index
data = agg.index.data
data = agg["__index__"].data
neg1 = data == -1
for col in dfdata.columns:
if col in agg.coords:
Expand Down
6 changes: 3 additions & 3 deletions holoviews/tests/operation/test_datashader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1314,12 +1314,12 @@ def test_rasterize_where_agg_no_column(point_plot, agg_input_fn, index_col):
rast_input = dict(dynamic=False, x_range=(-1, 1), y_range=(-1, 1), width=2, height=2)
img = rasterize(point_plot, aggregator=agg_fn, **rast_input)

assert list(img.data) == ["index", "s", "val", "cat"]
assert list(img.data) == ["__index__", "s", "val", "cat"]
assert list(img.vdims) == ["val", "s", "cat"] # val first and no index

# N=100 in point_data is chosen to have a big enough sample size
# so that the index are not the same for the different agg_input_fn
np.testing.assert_array_equal(img.data["index"].data.flatten(), index_col)
np.testing.assert_array_equal(img.data["__index__"].data.flatten(), index_col)

img_simple = rasterize(point_plot, aggregator=agg_input_fn("val"), **rast_input)
np.testing.assert_array_equal(img_simple["val"], img["val"])
Expand Down Expand Up @@ -1357,7 +1357,7 @@ def test_rasterize_selector(point_plot, sel_fn):
img = rasterize(point_plot, selector=sel_fn("val"), **rast_input)

# Count is from the aggregator
assert list(img.data) == ["Count", "index", "s", "val", "cat"]
assert list(img.data) == ["Count", "__index__", "s", "val", "cat"]
assert list(img.vdims) == ["Count", "s", "val", "cat"] # no index

# The output for the selector should be equal to the output for the aggregator using
Expand Down

0 comments on commit 2be0c36

Please sign in to comment.