Replace the two _sliced_fields methods with one slice_fields helper - #314
Merged
Merged
Conversation
HaplotypeMatrix and GenotypeMatrix each carried an identical _sliced_fields method that read self.fields and self._accessible_idx and switched on a 'view' | 'underlying' string. One module-level slice_fields in accessible.py takes the accessible index explicitly instead: view callers pass self._accessible_idx, filter() passes nothing because its index already addresses the underlying array. Closes #313
nspope
approved these changes
Sep 23, 2026
nspope
left a comment
Collaborator
There was a problem hiding this comment.
Looks good, much tidier.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #313.
HaplotypeMatrix._sliced_fieldsandGenotypeMatrix._sliced_fieldswere the same function line for line. Both readself.fieldsandself._accessible_idx, and both switched on aspace='view' | 'underlying'string to decide whether to compose through the accessible index.This replaces them with one module-level
slice_fields(fields, keep_idx, accessible_idx=None)inpg_gpu/accessible.py. The accessible index is passed explicitly: view callers hand inself._accessible_idx, and the twofilter()callers pass nothing because their index already addresses the underlying array. Both matrix modules already import fromaccessible.py, so no new import edge.All eight call sites are updated and both methods are deleted.
grep -rn "_sliced_fields\|space=" pg_gpu/returns nothing.No new tests. The masked-field tests from #307 cover every call site:
tests/test_haplotype_matrix.py::test_variant_subset_methods_preserve_fields_under_accessible_masktests/test_haplotype_matrix.py::test_exclude_missing_sites_preserves_fields_under_accessible_masktests/test_genotype_matrix_coverage.py::TestFieldsUnderAccessibleMasktests/test_qc_fields.py::TestHaplotypeMatrixFilterFull non-slow suite passes locally on an A100 (1816 passed, 80 skipped, 19 xfailed). Ruff is clean.