question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

layout.get doesn't find any entities when passed a numpy.int64 value for run

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:17

github_iconTop GitHub Comments

1reaction
Shotgunosinecommented, Sep 11, 2019

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.

1reaction
Shotgunosinecommented, Sep 11, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found