Skip to content

Commit

Permalink
fix a problem where linked selections were resulting in repeated colu…
Browse files Browse the repository at this point in the history
…mns (#6336)
  • Loading branch information
grapesmoker authored Oct 16, 2024
1 parent 0201b94 commit ee7a485
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
8 changes: 5 additions & 3 deletions holoviews/element/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,20 @@ def _get_index_selection(self, index, index_cols):
self._index_skip = True
if not index:
return None, None, None
ds = self.clone(kdims=index_cols, new_type=Dataset)
clone_vdims = [vdim.name for vdim in self.vdims if vdim.name not in index_cols]
cols = clone_vdims + index_cols
ds = self.clone(kdims=index_cols, vdims=clone_vdims, new_type=Dataset)
if len(index_cols) == 1:
index_dim = index_cols[0]
vals = dim(index_dim).apply(ds.iloc[index], expanded=False)
vals = dim(index_dim).apply(ds.iloc[index, cols], expanded=False)
if vals.dtype.kind == 'O' and all(isinstance(v, np.ndarray) for v in vals):
vals = [v for arr in vals for v in util.unique_iterator(arr)]
expr = dim(index_dim).isin(list(util.unique_iterator(vals)))
else:
get_shape = dim(self.dataset.get_dimension(index_cols[0]), np.shape)
index_cols = [dim(self.dataset.get_dimension(c), np.ravel) for c in index_cols]
vals = dim(index_cols[0], util.unique_zip, *index_cols[1:]).apply(
ds.iloc[index], expanded=True, flat=True
ds.iloc[index, cols], expanded=True, flat=True
)
contains = dim(index_cols[0], util.lzip, *index_cols[1:]).isin(vals, object=True)
expr = dim(contains, np.reshape, get_shape)
Expand Down
24 changes: 24 additions & 0 deletions holoviews/tests/element/test_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
)
from holoviews.element.comparison import ComparisonTestCase
from holoviews.element.selection import spatial_select_columnar
from holoviews.util.transform import dim

from ..utils import dask_switcher

Expand Down Expand Up @@ -61,6 +62,29 @@
dd_available = pytest.mark.skipif(dd is None, reason='dask.dataframe not available')


class TestIndexExpr(ComparisonTestCase):

def setUp(self):
import holoviews.plotting.bokeh # noqa
super().setUp()
self._backend = Store.current_backend
Store.set_current_backend('bokeh')

def tearDown(self):
Store.current_backend = self._backend

def test_index_selection_on_id_column(self):
# tests issue in https://github.com/holoviz/holoviews/pull/6336
x, y = np.random.randn(2, 100)
idx = np.arange(100)

points = Points(
{'x': x, 'y': y, 'id': idx}, kdims=['x', 'y'], vdims=['id'], datatype=['dataframe']
)
sel, _, _ = points._get_index_selection([3, 7], ['id'])
assert sel == dim('id').isin([3, 7])


class TestSelection1DExpr(ComparisonTestCase):

def setUp(self):
Expand Down

0 comments on commit ee7a485

Please sign in to comment.