Skip to content

fix: sample voxelgrid points independently of DataFrame index - #370

Open
dajiaohuang wants to merge 1 commit into
daavoo:mainfrom
dajiaohuang:fix/voxelgrid-sampling-index-20261015
Open

dajiaohuang wants to merge 1 commit into
daavoo:mainfrom
dajiaohuang:fix/voxelgrid-sampling-index-20261015

Conversation

@dajiaohuang

Copy link
Copy Markdown

Problem

The documented points DataFrame selection workflow preserves row labels, but the nearest and highest voxelgrid samplers use those labels as .iloc positions. A valid point selection can therefore raise IndexError: positional indexers are out-of-bounds instead of returning a sample.

For example, for either sampler:

import pandas as pd
from pyntcloud import PyntCloud

coordinates = [0.0, 0.1, 0.2, 0.5, 0.9, 1.0]
cloud = PyntCloud(pd.DataFrame({axis: coordinates for axis in "xyz"}))
cloud.points = cloud.points.loc[cloud.points["x"] > 0.3]
voxelgrid_id = cloud.add_structure("voxelgrid")
sample = cloud.get_sample("voxelgrid_nearest", voxelgrid_id=voxelgrid_id)
# "voxelgrid_highest" fails for the same reason.

Change

Use a locally reset index for the grouping/index selection in both samplers, so the selected indices are positions. This does not reset the caller's point index or change the sampling algorithm. Add a public-API regression comparing the selected cloud with the same cloud indexed from zero.

Validation

Windows, Python 3.12.13, NumPy 2.2.6, pandas 2.2.3, SciPy 1.15.3:

  • Both public-API cases reproduce the out-of-bounds failure on 8368c6a; the two regression cases pass with this change.
  • Ruff 0.9.10 check and format check pass for the changed Python files; git diff --check passes.
  • Unit suite: 105 passed, 11 failed, unchanged from base. Selected integration coverage (core class, scalar fields, structures, filters, point/voxel samplers): 83 passed, 15 failed versus 81 passed, 15 failed on base. Existing failures concern voxel boundary expectations (the area of Stabilize voxel boundary binning across platforms in VoxelGrid #369) and four tests using sample is DataFrame; those are not changed here.
  • Synthetic PLY/NPZ/XYZ/OBJ round trips and the README HSV/voxelgrid/nearest/NPZ workflow pass. Matplotlib Agg rendering also runs.
  • Repository-wide flake8 still reports existing findings; the unchanged long docstring in this module also fails its default line-length check. No full CI/platform matrix or optional Open3D/PyVista/widget-rendering claim.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant