Skip to content

refactor: generalize format_bids_path (schema-driven) - #112

Open
kaitj wants to merge 3 commits into
feat/generalize-ents/phase3from
feat/generalize-ents/phase4
Open

refactor: generalize format_bids_path (schema-driven)#112
kaitj wants to merge 3 commits into
feat/generalize-ents/phase3from
feat/generalize-ents/phase4

Conversation

@kaitj

@kaitj kaitj commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

This PR:

Phase 4 of the generalized entities refactor, building on top of phase 3 (#111). A refactor to make format_bids_path schema-driven with a cleanup pass.

  • format_bids_path is now schema-driven - the public signature gains an optional schema: SchemaSpec parameter, with logic moved to a private _format_bids_path(..., adapter) helper. The special entity set is derived from the schema (entities with format == "special") instead of a hardcoded literal, and directory prepending iterates get_entity_directory_order(adapter) in reverse instead of hardcoding sub / ses, fixing a KeyError on non-subject datasets (e.g. tpl-* derivatives). Backwards compatible
  • Dead code removed - droped production-uncalled _filter_include / _filter_exclude / _multi_pattern_filter cluster and its orphaned test
  • ** Cache invalidation** - clear_schema_caches() now also clears the _load_from_path, entity_arrow_schema and _lookups_from_arrow caches, covering full set of schema/adapter derived LRU caches; also fixed stale docstring reference to nonexistent bids2table.set_bids_schema.
  • Tests: added non-subject (tpl-MNI152NLin2009Asym/...) round-trip cases and a parse-again assertion to test_format_bids_path

Type of Change

  • Bug fix
  • Enhancement / feature
  • Documentation
  • Other

Related Issue(s)


Stack created with GitHub Stacks CLIGive Feedback 💬

@kaitj kaitj changed the title refactor: generalize format_bids_path (schema-driven) refactor: generalize format_bids_path (schema-driven) Aug 18, 2026
@kaitj
kaitj marked this pull request as ready for review August 20, 2026 18:14
@kaitj

kaitj commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

think the CI failed to run here during GH down time when this was pushed

@kaitj
kaitj force-pushed the feat/generalize-ents/phase4 branch from 0348920 to dce321d Compare August 27, 2026 20:28
@github-actions

github-actions Bot commented Aug 27, 2026

Copy link
Copy Markdown

Coverage

Coverage Report
FileStmtsMissCoverMissing
__init__.py100100% 
__main__.py86891%127, 185, 187–188, 193, 223, 227, 231
_entities.py154299%70, 389
_indexing.py3051695%72, 243, 252–253, 442–443, 460–462, 465–467, 469, 675, 774, 778
_logging.py31487%31, 38, 40–41
_metadata.py49492%40–41, 67, 72
_pathlib.py21386%19, 21, 23
_schema.py120199%298
_version.py110100% 
pybids
   __init__.py40100% 
   _bidsfile.py381366%67–69, 73–75, 79–81, 85–87, 91
   _layout.py1664573%68, 77, 86, 109, 119–120, 123, 143–144, 158–159, 173–174, 177–181, 185, 187–188, 191–192, 219, 224, 238, 315–317, 379–384, 386, 389–394, 396, 450, 470
   _utils.py14564%47–51
TOTAL100910190% 

Tests Skipped Failures Errors Time
222 0 💤 0 ❌ 0 🔥 28.065s ⏱️

@kaitj
kaitj force-pushed the feat/generalize-ents/phase4 branch from dce321d to f266435 Compare August 27, 2026 20:30
@github-actions

github-actions Bot commented Aug 27, 2026

Copy link
Copy Markdown

Benchmark Results

Local index (1 workers) Remote index (4 workers) Bold query Metadata query Subject query
feat/generalize-ents/phase4 202.441 (202.635 ± 1.263) ms 233.140 (232.926 ± 1.590) s 324.459 (345.812 ± 62.175) µs 328.671 (328.066 ± 39.574) µs 31.045 (34.250 ± 8.419) µs
main 206.652 (206.774 ± 0.743) ms 229.827 (230.850 ± 1.948) s 364.020 (368.748 ± 47.859) µs 344.646 (349.989 ± 40.250) µs 29.628 (33.623 ± 9.221) µs
v2.3.1 203.331 (203.721 ± 1.116) ms 231.462 (231.689 ± 1.895) s 375.672 (378.784 ± 56.118) µs 358.914 (370.279 ± 68.690) µs 29.059 (32.009 ± 6.382) µs
feat/generalize-ents/phase4 vs main ratio ⚪ 0.980 ⚪ 1.014 🟢 0.891 ⚪ 0.954 ⚪ 1.048
feat/generalize-ents/phase4 vs v2.3.1 ratio ⚪ 0.996 ⚪ 1.007 🟢 0.864 🟢 0.916 🔴 1.068

median (mean ± std)

🔴 Slower   ⚪ No change (<5 %)   🟢 Faster

- Derive the special-entity set (datatype/suffix/ext) and directory
  ordering from the BIDS schema instead of hardcoded constants
- Prepend directory entities by reversed `get_entity_directory_order`,
  fixing the KeyError on non-sub datasets (e.g. tpl-* derivatives)
- Add optional `schema` param to `format_bids_path`; move logic into
  private `_format_bids_path` helper
- Remove the uncalled _filter_include/_filter_exclude/_multi_pattern_filter
  cluster and its orphaned test
- Also clear the _load_from_path, entity_arrow_schema, and
  _lookups_from_arrow LRU caches so all schema-derived caches are covered
- Fix stale set_bids_schema reference and slim the docstring
- Add tpl-* (non-sub) path cases to test_format_bids_path
- Assert the parsed entities survive a second parse of the formatted path
@kaitj
kaitj force-pushed the feat/generalize-ents/phase4 branch from f266435 to a5c1d15 Compare September 2, 2026 17:38
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.

Generalize entities [Phase 4]

1 participant