Skip to content

fix(python): include row IDs in sampled Torch batches - #11735

Merged
Xuanwo merged 2 commits into
lance-format:mainfrom
zhangyue19921010:fix/python-sampled-dataset-row-ids
Dec 2, 2026
Merged

Xuanwo merged 2 commits into
lance-format:mainfrom
zhangyue19921010:fix/python-sampled-dataset-row-ids

Conversation

@zhangyue19921010

Copy link
Copy Markdown
Collaborator

Problem

Sampled Torch batches omit the row IDs requested by with_row_id=True.

Solution

Forward the request to native scans. For uniform and stratified takes, add _rowid to a copy of the projection and keep any existing expression under that name. Partial filtered sampling keeps its existing single-column filter and row selection.

Result

Sampled IDs match the scanner across fragments and deletions in both row-ID modes. All 131 selected sampler tests passed. The separate distributed loader test fails on main because its fixture constructs the wrong sampler.

Fixes #11734

Problem

Positive sample counts drop the row IDs requested by the Torch dataset.

Solution

Pass the row ID request to the native full and filtered scans. For take
sampling, add the system field to a copy of the requested projection.

Result

Sampled row IDs match the selected records across fragments and
deletions. The single-column partial filter keeps its previous row set.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@github-actions github-actions Bot added A-python Python bindings bug Something isn't working labels Dec 2, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Dec 2, 2026
### Problem

With `with_row_id=True`, sampled Torch batches contain a vector column and `_rowid`. Calling `size()` on the batch raised `AttributeError` during accelerated `IVF_PQ` training.

### Solution

Read both columns from the batch in `compute_partitions()`. A regression test checks sampled partition assignments against source row IDs across three fragments.

### Result

All six failing CI cases passed locally. The vector index, Torch KMeans, and sampler suites had 465 passing tests and six GPU-dependent skips.
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Dec 2, 2026

@lance-gatekeeper lance-gatekeeper Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Gate recommendation: approve.

No blocking issues found. Sampling preserves source row IDs and existing projections, and partition assignment carries those IDs through invalid-vector filtering and residual generation.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Dec 2, 2026
@Xuanwo
Xuanwo merged commit 38040f8 into lance-format:main Dec 2, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-python Python bindings bug Something isn't working K-approved Latest Gatekeeper recommendation permits acceptance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: sampled Torch batches omit requested row IDs

2 participants