layout.get doesn't find any entities when passed a numpy.int64 value for run
See original GitHub issueWhen 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.
Issue Analytics
- State:
- Created 4 years ago
- Comments:17
Top Results From Across the Web
Difficulty determining the type of a numpy int64 - Stack Overflow
I'm having trouble identifying numpy.int64 objects, in order to convert them to base python int for json serialisation. isinstance usually ...
Read more >NumPy User Guide
It is a Python library that provides a multidi- mensional array object, various derived objects (such as masked arrays and matrices), and an...
Read more >Your First Machine Learning Project in Python Step-By-Step
It is probably caused by a mix of tabs and spaces. The indentation can be any consistent white space . It is recommended...
Read more >Apache Beam Programming Guide
When you run your Beam driver program, the Pipeline Runner that you ... user passes --help as a command-line argument, and a default...
Read more >Advanced Python
Tabular Data Parsing: CSV. Table Data: Rows and Fields. Tables consist of records (rows) and fields (column values). Tabular data may ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.