Skip to content

Replace the two _sliced_fields methods with one slice_fields helper - #314

Merged
nspope merged 1 commit into
mainfrom
refactor/slice-fields-helper
Sep 23, 2026
Merged

nspope merged 1 commit into
mainfrom
refactor/slice-fields-helper

Conversation

@andrewkern

Copy link
Copy Markdown
Member

Closes #313.

HaplotypeMatrix._sliced_fields and GenotypeMatrix._sliced_fields were the same function line for line. Both read self.fields and self._accessible_idx, and both switched on a space='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) in pg_gpu/accessible.py. The accessible index is passed explicitly: view callers hand in self._accessible_idx, and the two filter() callers pass nothing because their index already addresses the underlying array. Both matrix modules already import from accessible.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_mask
  • tests/test_haplotype_matrix.py::test_exclude_missing_sites_preserves_fields_under_accessible_mask
  • tests/test_genotype_matrix_coverage.py::TestFieldsUnderAccessibleMask
  • tests/test_qc_fields.py::TestHaplotypeMatrixFilter

Full non-slow suite passes locally on an A100 (1816 passed, 80 skipped, 19 xfailed). Ruff is clean.

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
@andrewkern
andrewkern requested a review from nspope September 23, 2026 23:02

@nspope nspope left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good, much tidier.

@nspope
nspope merged commit 66187fd into main Sep 23, 2026
1 check passed
@nspope
nspope deleted the refactor/slice-fields-helper branch September 23, 2026 23:12
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.

Replace the two _sliced_fields methods with one slice_fields helper in accessible.py

2 participants