Skip to content

fix: plot_grid IndexError when highlighted indexes exceed the grid (small datasets) #705

Closed

Description

@Jammy2211

Overview

aplt.plot_grid(..., indexes=...) raises IndexError when a highlighted index lies outside the plotted grid. HowToLens chapter_1_introduction/tutorial_2_ray_tracing.py hard-codes indexes for its 101x101 grid; under PYAUTO_SMALL_DATASETS=1 the grid is capped to 16x16 (256 points), so index 5118 is out of bounds and the tutorial crashes. Reproduced on PyAutoArray main (e398b80) and HowToLens main on 2026-11-20:

File ".../autoarray/plot/grid.py", line 175, in plot_grid
    grid[idx_list, 1],
IndexError: index 5118 is out of bounds for axis 0 with size 256

Plan

  • Make plot_grid drop highlighted indexes that fall outside the grid, instead of crashing.
  • Skip an index group entirely when none of its indexes survive, keeping each surviving group's colour.
  • Log one message saying how many indexes were dropped, so a genuine mistake is still visible.
  • Add unit tests for in-range, partly out-of-range and fully out-of-range index groups.
  • Witness: the HowToLens tutorial exits 0 with and without PYAUTO_SMALL_DATASETS=1.
  • Tutorial stays unchanged: the fix belongs in the library.

effective level: supervised; merge mode: auto-merge on green if the Witness passes after a merge slot (shift worker ends at PR-open; close-out decides)

Detailed implementation plan

Affected repositories

  • PyAutoArray (primary, the only edited repo)
  • HowToLens (witness only, no edits)

Work classification

Library (bug)

Branch survey

Repository Current Branch Dirty?
./array/PyAutoArray main clean
./lens/HowToLens main clean

Suggested branch: feature/plot-grid-small-datasets-indexes
Worktree root: ~/Code/PyAutoLabs-wt/plot-grid-small-datasets-indexes/

Implementation steps

  1. autoarray/plot/grid.py, plot_grid, the if indexes is not None: block: for each idx_list, convert to an integer numpy array, keep entries with -n <= idx < n (n = grid.shape[0]), continue if empty, else scatter as before with colour colors[i % len(colors)]. Count dropped entries; if any, logger.info once naming the count and grid size.
  2. test_autoarray/plot/test_grid.py (new): plot_grid with ax supplied, assert collections/offsets for the three cases and that no exception is raised.

Testing

  • python -m pytest -q -n 4 test_autoarray/plot
  • Witness script with and without PYAUTO_SMALL_DATASETS=1.
  • Targeted smoke via pyauto-heart smoke --targeted.

Original prompt: PyAutoMind draft/bug/autoarray/plot_grid_indexerror_under_small_datasets.md (shift 2026-11-20-am).

Activity

  1. Jammy2211 commented on Nov 20, 2026

    @Jammy2211
    CollaboratorAuthor

    PR opened: #706 (shift 2026-11-20-am). Gate: tests, Witness, targeted smoke, independent review CLEAN, Heart GREEN. Labelled decision-taken: boolean-mask groups are kept as masks, a change from the plan's integer conversion, made after the review. Ends at PR-open for the close-out / /prm.

  2. Jammy2211 commented on Nov 20, 2026

    @Jammy2211
    CollaboratorAuthor

    Shipped. #706 merged (0f4e8a0, 2026-11-20) via human /prm after review of shift 2026-11-20-am.

    plot_grid(indexes=...) now drops highlighted indexes that fall outside the grid and logs one INFO line with the count, instead of raising IndexError; empty groups are skipped and each surviving group keeps its colour (bool-mask groups preserved via flatnonzero). HowToLens chapter_1_introduction/tutorial_2_ray_tracing.py now runs under PYAUTO_SMALL_DATASETS=1.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions