Skip to content

fix: Set selected_index to the row's position in the whole table - #1283

Merged
kylebarron merged 2 commits into
mainfrom
kyle/fix-selected-index
Sep 29, 2026
Merged

kylebarron merged 2 commits into
mainfrom
kyle/fix-selected-index

Conversation

@kylebarron

Copy link
Copy Markdown
Member

Note

This PR was written by Claude (Claude Code), not by @kylebarron.

Problem

selected_index is documented as the row that was clicked, usable as gdf.iloc[layer.selected_index]. Three things made it wrong:

  1. A click on the first row was ignored. onClick returned early on !pickingInfo.index, and index 0 is falsy. deck.gl uses -1, not 0, when nothing was picked.
  2. With more than one record batch, the index was the row's position within its batch. Each batch is rendered as its own deck.gl layer, and the picking info from @geoarrow/deck.gl-geoarrow is relative to that layer's batch. For a 4-row table in batches of 2, clicking the 4th row gave selected_index == 1. Lonboard splits large tables into batches automatically, so this affects anyone with large data.
  3. Clicking a HeatmapLayer set selected_index to an arbitrary number, such as 2490556 for a 3-row table. deck.gl's HeatmapLayer doesn't support picking: it draws the heatmap's colors in the picking pass, and deck.gl decodes the color under the cursor as an index.

There was no issue for these. The first two were found while testing the deck.gl 9.4 upgrade (#1272) and exist on deck.gl 9.3 too. The third was found while fixing them.

Changes

This PR has two commits, so the heatmap change can be dropped or split out.

Commit 1: the index

  • onClick moves from BaseLayerModel to BaseArrowLayerModel. It receives the batch index of the layer that was clicked, returns when index < 0, and adds the number of rows in all earlier batches.
  • The H3, A5, geohash and S2 models called baseLayerProps() without a batch index. They now pass it.

Commit 2: the heatmap

  • HeatmapModel sets pickable: false, as BitmapModel already does.

Behavior changes to be aware of

  • Anyone who worked around the old value, for example by adding the batch offset themselves, will now get an index that is offset twice. For tables with a single batch, the only change is that row 0 works.
  • H3, A5, geohash and S2 layers with extension props given as arrays (e.g. get_filter_value) used the first batch's values for every batch. They now use each batch's own values. This is a side effect of passing the batch index.
  • Layers that aren't backed by an Arrow table (bitmap, bitmap tile, raster, surface) no longer get an onClick handler. They never set selected_index before either: they always report index 0, which the old check discarded.
  • A heatmap is no longer pickable, so it no longer blocks clicks and hovers on layers underneath it. The Python pickable trait has no effect on a heatmap.

The tooltip, the side panel and Map.on_click are unaffected. They use the picked row object and the coordinate, not the index.

Tests

tests/ui/test_picking.py goes from 4 tests to 26. Each one clicks a feature in the browser and checks the value Python receives.

Test Checks
test_click_sets_selected_index ×4 (existing) Last row of a single batch
test_click_first_row_sets_selected_index ×4 Row 0 gives 0
test_click_in_later_batch_sets_table_index ×12 6 rows in batches of 2; rows 2, 3 and 5
test_click_multipolygon_in_later_batch_sets_table_index Counts rows, not the parts of a multi-part geometry
test_click_h3_cell_sets_table_index ×3 An H3 layer in two batches; rows 0, 2 and 3
test_click_on_empty_map_does_not_set_selected_index A click on empty map sets nothing
test_click_heatmap_does_not_set_selected_index A click on a heatmap sets nothing

The ×4 and ×12 tests are parametrized over scatterplot, path, polygon and solid polygon layers.

Against main's frontend code, 21 of the 26 fail and 5 pass. The 5 are the 4 existing tests and the empty-map click.

Geohash, S2, text, column, point cloud, arc and trips layers were also clicked in a browser with the fix, on tables in two batches, and gave the right index. Those checks aren't part of the test suite.

Checks

  • pytest: 250 passed, 1 skipped.
  • pnpm test: 6 passed.
  • biome check: clean.
  • tsc --noEmit: 7 errors, the same 7 as main.

Not verified

  • The A5 layer wasn't clicked in a browser. It uses the same code path as the H3, geohash and S2 layers.
  • Raster and surface layers were checked by reading the code only.

🤖 Written by Claude Code

kylebarron and others added 2 commits September 29, 2026 13:45
`selected_index` is documented as usable with `gdf.iloc[layer.selected_index]`,
but two things made it wrong:

- A click on the first row was ignored. `onClick` returned early on
  `!pickingInfo.index`, and index 0 is falsy. deck.gl uses -1, not 0, when
  nothing was picked.
- With more than one record batch, the index was the row's position within
  its batch. Each batch is rendered as its own deck.gl layer, and the picking
  info from `@geoarrow/deck.gl-geoarrow` is relative to that layer's batch.
  Lonboard splits large tables into batches automatically, so users with
  large data got the wrong row.

`onClick` now lives on `BaseArrowLayerModel`, receives the batch index of the
layer that was clicked, and adds the number of rows in all earlier batches.

The H3, A5, geohash and S2 models called `baseLayerProps()` without the batch
index. They now pass it, which also means that extension props given as
arrays (e.g. `get_filter_value`) use the values of the right batch instead of
always those of the first batch.

Layers that are not backed by an Arrow table (bitmap, bitmap tile, raster,
surface) no longer get an `onClick` handler. They have no rows to select, and
they never set `selected_index` before either: they always report index 0,
which the old check discarded.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Clicking a heatmap set `selected_index` to an arbitrary number, e.g. 2490556
for a table with 3 rows.

deck.gl's HeatmapLayer doesn't support picking: its shader has no picking
module, so in the picking pass it draws the heatmap colors, and deck.gl
decodes the color under the cursor as if it were an object index. A heatmap
is also an aggregation of all rows, so there is no single row that a click
could select.

Turn picking off for the heatmap, as is already done for the BitmapLayer.
This also means that the heatmap no longer hides pickable layers underneath
it from clicks and hovers.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@ds-release-bot ds-release-bot Bot added the fix label Sep 29, 2026
@kylebarron
kylebarron merged commit 081cdbe into main Sep 29, 2026
5 checks passed
@kylebarron
kylebarron deleted the kyle/fix-selected-index branch September 29, 2026 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant