def _validate(self, stim): if not self._stim_matches_input_types(stim): from pliers.converters.base import get_converter in_type = self._input_type if self._input_type else self._optional_input_type converter = get_converter(type(stim), in_type) if converter: _old_stim = stim stim = converter.transform(stim) stim = _log_transformation(_old_stim, stim, converter) else: msg = "Transformers of type %s can only be applied to stimuli " \ " of type(s) %s (not type %s), and no applicable " \ "Converter was found." msg = msg % (self.__class__.__name__, in_type, stim.__class__.__name__) raise TypeError(msg) return stim
def _validate(self, stim): # Checks whether the current Transformer can handle the passed Stim. # If not, attempts a dynamic conversion before failing. if not self._stim_matches_input_types(stim): from pliers.converters.base import get_converter in_type = self._input_type if self._input_type \ else self._optional_input_type converter = get_converter(type(stim), in_type) if converter: _old_stim = stim stim = converter.transform(stim) stim = _log_transformation(_old_stim, stim, converter, True) else: msg = ("Transformers of type %s can only be applied to stimuli" " of type(s) %s (not type %s), and no applicable " "Converter was found.") msg = msg % (self.__class__.__name__, in_type, stim.__class__.__name__) raise TypeError(msg) return stim