pybids: layout.get doesn't find any entities when passed a numpy.int64 value for run
When doing a layout.get()
, if the type of the run argument is np.int64, it fails to find any entities. Here’s a minimal reproduction using pybids test data:
In [1]: from os.path import join
...: from bids.analysis import Analysis
...: from bids.analysis.analysis import ContrastInfo, DesignMatrixInfo
...: from bids.layout import BIDSLayout
...: from bids.tests import get_test_data_path
...: import numpy as np
...:
...: def analysis():
...: layout_path = join(get_test_data_path(), 'ds005')
...: layout = BIDSLayout(layout_path)
...: json_file = join(layout_path, 'models', 'ds-005_type-test_model.json')
...: analysis = Analysis(layout, json_file)
...: analysis.setup(scan_length=480, subject=['01', '02'])
...: return analysis
...: foo = analysis()
In [2]: layout_path = join(get_test_data_path(), 'ds005')
...: layout = BIDSLayout(layout_path)
...: layout.get_runs()
Out[2]: [1, 2, 3]
In [3]: layout.get(suffix="bold",subject='01', run=1)
Out[3]: [<BIDSImageFile filename='/gpfs/gsfs11/users/MBDU/midla/notebooks/code/pybids/bids/tests/data/ds005/sub-01/func/sub-01_task-mixedgamblestask_run-01_bold.nii.gz'>]
In [4]: layout.get(suffix="bold",subject='01', run=np.int64(1))
...:
Out[4]: []
In [5]: # Now just to show that pybids itself is generating numpy.int64 run values, here's the output from get design matrix
In [6]: for _, _, ents in foo.steps[0].get_design_matrix():
...: break
...: ents
Out[6]:
{'task': 'mixedgamblestask',
'run': 1,
'suffix': 'bold',
'datatype': 'func',
'subject': '01'}
In [7]: type(ents['run'])
Out[7]: numpy.int64
In [8]: layout.get(**ents)
Out[8]: []
In [9]: ents['run']=1
...: layout.get(**ents)
Out[9]: [<BIDSImageFile filename='/gpfs/gsfs11/users/MBDU/midla/notebooks/code/pybids/bids/tests/data/ds005/sub-01/func/sub-01_task-mixedgamblestask_run-01_bold.nii.gz'>]
And before anyone suggests that the solution is to avoid passing int64s as run numbers, notice that get_design_matrix
returns an int64. I’ve reproduced the above results with both 0.9.2 and 0.9.3.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 17
Commits related to this issue
- fix: automatically sanitizes dtype of qet() arguments; closes #490 — committed to bids-standard/pybids by tyarkoni 5 years ago
Also, that solution precludes having any other method directly call _build_file_query unless type enforcement code is replicated there. There’s a current todo to have to_df directly call _bild_flie_query.
You could crib the try except structure from my pr to deal with cases when lists are passed. The tests in that PR also check list cases.