def setData(self, index, value, role=DTYPE_CHANGE_ROLE):
        if role != DTYPE_CHANGE_ROLE or not index.isValid():
            return False

        if not self.editable():
            return False

        self.layoutAboutToBeChanged.emit()

        dtype = SupportedDtypes.dtype(value)
        currentDtype = np.dtype(index.data(role=DTYPE_ROLE))

        if dtype is not None:
            if dtype != currentDtype:
                col = index.column()
                #row = self._dataFrame.columns[index.column()]
                columnName = self._dataFrame.columns[index.row()]

                try:
                    if dtype == np.dtype('<M8[ns]'):
                        if currentDtype in SupportedDtypes.boolTypes():
                            raise Exception, u"Can't convert a boolean value into a datetime value."
                        self._dataFrame[columnName] = self._dataFrame[columnName].apply(pandas.to_datetime)
                    else:
                        self._dataFrame[columnName] = self._dataFrame[columnName].astype(dtype)
                    self.dtypeChanged.emit(index.row(), dtype)
                    self.layoutChanged.emit()

                    return True
                except Exception, e:
                    message = 'Could not change datatype %s of column %s to datatype %s' % (currentDtype, columnName, dtype)
                    self.changeFailed.emit(message, index, dtype)
                    raise
                    # self._dataFrame[columnName] = self._dataFrame[columnName].astype(currentDtype)
                    # self.layoutChanged.emit()
                    # self.dtypeChanged.emit(columnName)
                    #raise NotImplementedError, "dtype changing not fully working, original error:\n{}".format(e)
        return False
Widget templates want to reuse their own blocks.
dataset/ETHPy150Open datalyze-solutions/pandas-qt/pandasqt/models/ColumnDtypeModel.py/ColumnDtypeModel.setData--crossover with--dataset/ETHPy150Open funkybob/django-sniplates/tests/test_reuse.py/TestReuse.test_reuse_in_widget