Check if reshapable, and if so reshape, otherwise throw exception
@@ -45,7 +45,11 @@ class BIDSVariable(metaclass=ABCMeta):
"""
result = deepcopy(self)
if data is not None:
- if data.squeeze().shape != self.values.squeeze().shape:
+ if data.shape != self.values.shape:
+ # If data can be re-shaped safely, do so
+ if data.squeeze().shape == self.values.squeeze().shape:
+ data = data.reshape(self.values.shape)
+ else:
raise ValueError("Replacement data has shape %s; must have"
" same shape as existing data %s." %
(data.shape, self.values.shape))
