def addDataFrameColumn(self, columnName, dtype, defaultValue):
        if not self.editable or dtype not in SupportedDtypes.allTypes():
            return False

        elements = self.rowCount()
        columnPosition = self.columnCount()

        newColumn = pandas.Series([defaultValue]*elements, index=self._dataFrame.index, dtype=dtype)

        self.beginInsertColumns(QtCore.QModelIndex(), columnPosition - 1, columnPosition - 1)
        try:
            self._dataFrame.insert(columnPosition, columnName, newColumn, allow_duplicates=False)
        except ValueError, e:
            # columnName does already exist
            return False
예제 #2
0
class PandasCellPayload(MimeDataPayload):
    
    _allowedDtypes = SupportedDtypes.allTypes()

    def __init__(self, dfindex, column, value, dtype, parentId):
        """store dataframe information in a pickable object
        
        Args:
            dfindex (pandas.index): index of the dragged data.
            column (str): name of column to be dragged.
            value (object): value on according position.
            dtype (pandas dtype): data type of column.
            parentId (str): hex(id(...)) of according DataFrameModel.

        """
        super(PandasCellPayload, self).__init__()
        self.dfindex = dfindex
        self.column = column
        self.value = value
        self.dtype = dtype
        self.parentId = parentId
        
    def setAllowedDtypes(self, dtypes):
        """set the allowed dtypes used by the dropped widget to determin if we accept or decline the data.
        Defaults to allTypes.
        
        Args:
            dtypes(SupportedDtypes type): combination of SupportedDtypes types. 
                e.x. SupportedDtypes.intTypes() + SupportedDtypes.floatTypes()
        
        """
        self._allowedDtypes = dtypes

    def allowedDtypes(self):
        """return allowedDtypes"""
        return self._allowedDtypes
    
    def isValid(self):
        """check if the dtype is in allowedDtypes. Used to accept or decline a drop in the view."""
        if self.dtype in self._allowedDtypes:
            return True
        else:
            return False
예제 #3
0
    def addDataFrameColumn(self, columnName, dtype, defaultValue):
        if not self.editable or dtype not in SupportedDtypes.allTypes():
            return False

        elements = self.rowCount()
        columnPosition = self.columnCount()

        newColumn = pandas.Series([defaultValue] * elements,
                                  index=self._dataFrame.index,
                                  dtype=dtype)

        self.beginInsertColumns(QtCore.QModelIndex(), columnPosition - 1,
                                columnPosition - 1)
        try:
            self._dataFrame.insert(columnPosition,
                                   columnName,
                                   newColumn,
                                   allow_duplicates=False)
        except ValueError, e:
            # columnName does already exist
            return False