Skip to content

Update pybids compatibility flattening#79

Merged
gkiar merged 4 commits into
pybidsfrom
b2t/pybids-compat
May 20, 2026
Merged

Update pybids compatibility flattening#79
gkiar merged 4 commits into
pybidsfrom
b2t/pybids-compat

Conversation

@kaitj
Copy link
Copy Markdown
Contributor

@kaitj kaitj commented May 15, 2026

Main change in PR is to update the flattening of the extra_entities. The .flatten() call ran into 2 issues:

  1. The extra_entities column was a MapType, which pyarrow didn't end up flattening during my tests.
  2. The flattening would have only occurred on the root directory as it was called after initial indexing, but before derivatives were added.

This PR adds a new private method that performs the flattening by pulling out all the entities from extra_entities and giving it its own column, before dropping the extra_entities column. This ends up being a closer match to pybids behaviour (I think) and allows for filtering by these extra entities when using the compatibility layer.

This a rough summary of the column differences between the 3 tools (OG pybids, b2t before PR, b2t after PR):

Entity OG pybids b2t (before this PR) b2t (after this PR) Status
extension Unique to OG pybids
subject Unique to OG pybids
extra_entities Unique to b2t (before this PR)
from Missing from b2t (before this PR)
mode Missing from b2t (before this PR)
to Missing from b2t (before this PR)
ext / sub Missing from OG pybids

Note

b2t uses abbreviations for subject and extension (pybids naming)
from and to were in the still in the `extra_entities`` for b2t (before this pr).

This also facilitates the extraction of unique values within the extra entities column. Should we / do we want to support the full subject and extension convention in the compatibility layer?

Some additional minor things:

  • Updated type hints
  • Removed an unused validate argument in BIDSLayout.__init__
  • Added an explicit .to_df() method that mirrors the BIDSLayout method in pybids. Probably not strictly necessary, but will ensure drop-in compatibility if anyone is using the method.

kaitj added 4 commits May 14, 2026 13:29
Removed the validate argument from layout initialization. Passing this previously had no effect as it wasn't used anywhere downstream nor did it throw any message about it. With this change, users can still pass the `validate` when initializing BIDSLayout without it doing anything since the method accepts **kwargs
pybids doesn't have a `.df` attribute to BIDSLayout, instead relying on
a `to_df()` method. To avoid breaking this and making it more plug-and-play,
add a method to mimic pybids behaviour and return the attribute value
Previous flattening, via the `.flatten()` method did not flatten the extra entities due to the type of the column. Expected StructType but got MapType instead.

This commit:
  - Adds a method, `_flatten_extra_entities`, that performs the flattening, and adds it to the entity map that is used elsewhere, while moving the root and path columns to the end of the table. The latter is not strictly necessary, but moved it to keep the entity columns together.
  - Removes the TODO note, as "extra_entities" is no longer a column that needs to be considered
@kaitj kaitj requested review from gkiar and nx10 May 15, 2026 17:37
@2593803287-hue
Copy link
Copy Markdown

Hi — I prepared a follow-up patch for PR #79 locally, but I don’t have push access to the upstream branch childmindresearch:b2t/pybids-compat, so I can’t update the PR directly.

Current PR head: af262b39dc2f698ec30278e485432790f8cbfa41
My local follow-up commit: 1d85b3cc8b1dd6f3eb217bce2c831ad57d1c8a5c

Patch file:
pr79-local-head.patch

Summary of the patch:

  • improves compatibility when entity metadata is missing or incomplete in self._tab.schema
  • falls back to entity.name when name/entity metadata is absent
  • makes extra_entities key expansion deterministic and safe for empty inputs

If someone with push access can apply it, the commands should be:

git checkout b2t/pybids-compat
git am pr79-local-head.patch
git push origin b2t/pybids-compat

@nx10
Copy link
Copy Markdown
Collaborator

nx10 commented May 17, 2026

@2593803287-hue - No patch is attached and the commit you mention isn't visible anywhere reachable. Please open a PR from your fork if you'd like the changes reviewed.

Copy link
Copy Markdown
Collaborator

@gkiar gkiar left a comment

Choose a reason for hiding this comment

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

@kaitj Thanks! Regarding this question:

This also facilitates the extraction of unique values within the extra entities column. Should we / do we want to support the full subject and extension convention in the compatibility layer?

This is currently supported, here, where we add both the short-name and long-name to the index.

LGTM!

@gkiar gkiar merged commit 716f521 into pybids May 20, 2026
@kaitj kaitj deleted the b2t/pybids-compat branch May 20, 2026 15:49
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.

4 participants