Repository: bids-standard/pybids

Issue:
Rename transform broken
When I have a `Rename` transform in my model, the following happens:

```
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-22-8ba03ea32733> in <module>
----> 1 analysis.setup(desc='preproc', subject=participants, drop_na=True)
      2 l1 = analysis.steps[0]
      3 l2 = analysis.steps[1]
      4 l3 = analysis.steps[2]
      5 # on0 = l1.output_nodes[0]

/opt/conda/envs/neuro/lib/python3.6/site-packages/bids/analysis/analysis.py in setup(self, steps, agg_func, **kwargs)
     92                 continue
     93 
---> 94             b.setup(input_nodes, **selectors)
     95             input_nodes = b.output_nodes
     96 

/opt/conda/envs/neuro/lib/python3.6/site-packages/bids/analysis/analysis.py in setup(self, input_nodes, **kwargs)
    212             coll = apply_transformations(coll, self.transformations)
    213             if X:
--> 214                 transform.Select(coll, X)
    215 
    216             node = AnalysisNode(self.level, coll, self.contrasts, input_nodes,

/opt/conda/envs/neuro/lib/python3.6/site-packages/bids/analysis/transformations/base.py in __new__(cls, collection, variables, *args, **kwargs)
     85         t = super(Transformation, cls).__new__(cls)
     86         t._setup(collection, variables, *args, **kwargs)
---> 87         return t.transform()
     88 
     89     def _setup(self, collection, variables, *args, **kwargs):

/opt/conda/envs/neuro/lib/python3.6/site-packages/bids/analysis/transformations/base.py in transform(self)
    241                     'numpy': col.values.values}[self._input_type]
    242 
--> 243         data = [select_type(c) for c in variables]
    244 
    245         if not self._loopable:

/opt/conda/envs/neuro/lib/python3.6/site-packages/bids/analysis/transformations/base.py in <listcomp>(.0)
    241                     'numpy': col.values.values}[self._input_type]
    242 
--> 243         data = [select_type(c) for c in variables]
    244 
    245         if not self._loopable:

/opt/conda/envs/neuro/lib/python3.6/site-packages/bids/analysis/transformations/base.py in select_type(col)
    239         def select_type(col):
    240             return {'variable': col, 'pandas': col.values,
--> 241                     'numpy': col.values.values}[self._input_type]
    242 
    243         data = [select_type(c) for c in variables]

AttributeError: 'numpy.ndarray' object has no attribute 'values'
```

Removing the `Rename` and simply using the original name results in a working model.


Discussion:

Resolving patch:
diff --git a/bids/analysis/transformations/munge.py b/bids/analysis/transformations/munge.py
--- a/bids/analysis/transformations/munge.py
+++ b/bids/analysis/transformations/munge.py
@@ -195,7 +195,7 @@ def _transform(self, var):
         ''' Rename happens automatically in the base class, so all we need to
         do is unset the original variable in the collection. '''
         self.collection.variables.pop(var.name)
-        return var.values.values
+        return var.values
 
 
 class Replace(Transformation):
diff --git a/bids/variables/kollekshuns.py b/bids/variables/kollekshuns.py
--- a/bids/variables/kollekshuns.py
+++ b/bids/variables/kollekshuns.py
@@ -177,7 +177,7 @@ def _index_entities(self):
             self.entities = {}
         else:
             keep = all_ents.columns[constant]
-            ents = {k: all_ents[k].iloc[0] for k in keep}
+            ents = {k: all_ents[k].dropna().iloc[0] for k in keep}
             self.entities = {k: v for k, v in ents.items() if pd.notnull(v)}
 
     def __getitem__(self, var):
diff --git a/bids/variables/variables.py b/bids/variables/variables.py
--- a/bids/variables/variables.py
+++ b/bids/variables/variables.py
@@ -208,7 +208,7 @@ def _index_entities(self):
             self.entities = {}
         else:
             keep = self.index.columns[constant]
-            self.entities = {k: self.index[k].iloc[0] for k in keep}
+            self.entities = {k: self.index[k].dropna().iloc[0] for k in keep}
 
 
 class SimpleVariable(BIDSVariable):


Test patch: