Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: better repr for Derivatives class #351

Merged
merged 3 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion nibabies/utils/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ def __init__(self, bids_root: Path | str, spec: dict | Path | str | None = None,
setattr(self, name, None)

def __repr__(self):
return '\n'.join([name for name in self.names if getattr(self, name)])
output = ["Derivatives |"]
output.extend([f" {attr}: {getattr(self, attr)}" for attr in self.names])
return '\n'.join(output)

def __contains__(self, val: str):
return val in self.names
Expand Down
3 changes: 3 additions & 0 deletions nibabies/utils/tests/test_bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def test_derivatives(
assert derivatives.aseg is None
assert derivatives.t1w_aseg is None
assert derivatives.t2w_aseg is None
assert "t1w_mask" in repr(derivatives)

derivatives.populate(deriv_dir, subject_id='01')
if mask:
Expand All @@ -111,3 +112,5 @@ def test_derivatives(
assert derivatives.references[aseg]
else:
assert derivatives.aseg == None
if t1w_mask:
assert "sub-01_space-T1w_desc-brain_mask.nii.gz" in repr(derivatives)
Loading