File tree Expand file tree Collapse file tree 4 files changed +13
-7
lines changed
src/datasets/packaged_modules/bids Expand file tree Collapse file tree 4 files changed +13
-7
lines changed Original file line number Diff line number Diff line change 44
55<Tip >
66
7- To use the BIDS loader, you need to install the ` bids ` extra:
7+ To use the BIDS loader, you need to install the ` bids ` extra (which installs ` pybids ` and ` nibabel ` ) :
88
99``` bash
1010pip install datasets[bids]
Original file line number Diff line number Diff line change 210210
211211NIBABEL_REQUIRE = ["nibabel>=5.3.2" , "ipyniivue==2.4.2" ]
212212
213- PYBIDS_REQUIRE = ["pybids>=0.21.0" ]
213+ PYBIDS_REQUIRE = ["pybids>=0.21.0" ] + NIBABEL_REQUIRE
214214
215215EXTRAS_REQUIRE = {
216216 "audio" : AUDIO_REQUIRE ,
Original file line number Diff line number Diff line change 11import json
2+ import os
23from dataclasses import dataclass
34from typing import Optional
45
@@ -28,6 +29,8 @@ class Bids(datasets.GeneratorBasedBuilder):
2829 def _info (self ):
2930 if not config .PYBIDS_AVAILABLE :
3031 raise ImportError ("To load BIDS datasets, please install pybids: pip install pybids" )
32+ if not config .NIBABEL_AVAILABLE :
33+ raise ImportError ("To load BIDS datasets, please install nibabel: pip install nibabel" )
3134
3235 return datasets .DatasetInfo (
3336 features = datasets .Features (
@@ -46,8 +49,6 @@ def _info(self):
4649 )
4750
4851 def _split_generators (self , dl_manager ):
49- import os
50-
5152 from bids import BIDSLayout
5253
5354 if not self .config .data_dir :
Original file line number Diff line number Diff line change @@ -75,7 +75,6 @@ def test_bids_module_imports():
7575
7676def test_bids_requires_pybids (monkeypatch ):
7777 """Test helpful error when pybids not installed."""
78- import datasets .config
7978 from datasets .packaged_modules .bids .bids import Bids
8079
8180 monkeypatch .setattr (datasets .config , "PYBIDS_AVAILABLE" , False )
@@ -84,7 +83,10 @@ def test_bids_requires_pybids(monkeypatch):
8483 Bids ()
8584
8685
87- @pytest .mark .skipif (not datasets .config .PYBIDS_AVAILABLE , reason = "pybids not installed" )
86+ @pytest .mark .skipif (
87+ not datasets .config .PYBIDS_AVAILABLE or not datasets .config .NIBABEL_AVAILABLE ,
88+ reason = "pybids or nibabel not installed" ,
89+ )
8890def test_bids_loads_single_subject (minimal_bids_dataset ):
8991 from datasets import load_dataset
9092
@@ -100,7 +102,10 @@ def test_bids_loads_single_subject(minimal_bids_dataset):
100102 assert sample ["session" ] is None
101103
102104
103- @pytest .mark .skipif (not datasets .config .PYBIDS_AVAILABLE , reason = "pybids not installed" )
105+ @pytest .mark .skipif (
106+ not datasets .config .PYBIDS_AVAILABLE or not datasets .config .NIBABEL_AVAILABLE ,
107+ reason = "pybids or nibabel not installed" ,
108+ )
104109def test_bids_multi_subject (multi_subject_bids ):
105110 from datasets import load_dataset
106111
You can’t perform that action at this time.
0 commit comments