Skip to content

Respect boolean masks when assigning to L - #948

Open
ktz03 wants to merge 1 commit into
AnswerDotAI:mainfrom
ktz03:fix/l-boolean-mask-assignment-0417
Open

ktz03 wants to merge 1 commit into
AnswerDotAI:mainfrom
ktz03:fix/l-boolean-mask-assignment-0417

Conversation

@ktz03

@ktz03 ktz03 commented Oct 16, 2026

Copy link
Copy Markdown

Fixes #947, reported by @j45856021-dev.

Assigning through a boolean mask to a list-backed L treats False and True as integer indices 0 and 1. For example, values = L(10,20,30); values[[False,False,True]] = 99 produces [99,99,30] instead of [10,20,99], and an all-false mask still changes data.

Normalize Python boolean index lists with the existing mask2idxs helper before assignment. Preserve the original path for native array selectors. Update the owning notebook and regenerate fastcore/foundation.py; add scalar/iterable and all-false-mask regressions plus native NumPy selector controls.

Validation on Windows with Python 3.12.14, fastcore 2.2.34 and nbdev 3.3.25:

  • nbdev-test nbs/02_foundation.ipynb --n-workers 1 --verbose: identical added tests fail on the unchanged baseline and pass with the fix.
  • A 46-configuration public-API matrix covers list, tuple, L and iterator masks, scalar/iterable replacements, all-false/all-true/empty selectors and integer/slice controls. All 28 affected cases are corrected; all 18 previously working cases retain their outputs.
  • nbdev-export --path nbs/02_foundation.ipynb and the official notebook-cleaning check pass.
  • The full nbdev-test --n-workers 1 --verbose command was run on both versions. It retains five pre-existing failing notebooks on Windows: 01_basics, 03_xtras, 03a_parallel, 03b_net and 12_tools; the added foundation regression is the sixth failure on the baseline and passes after the fix. The full suite is not claimed as passing. No tests or CI settings were changed to suppress these failures.

This addresses Python boolean masks. NumPy boolean scalars inside index lists remain unsupported with NumPy 2.5.4. Other operating systems, documentation rendering and performance were not tested.

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.

L.__setitem__ treats boolean masks as integer indices

1 participant