示例#1
0
def test_columnCount():
    model = DataFrameModel(pandas.DataFrame([0], columns=['A']))
    assert model.columnCount() == 1

    model = DataFrameModel(
        pandas.DataFrame(numpy.arange(100).reshape(1, 100),
                         columns=numpy.arange(100)))
    assert model.columnCount() == 100
示例#2
0
    def setDataFrame(self, dataFrame):
        self.df = dataFrame
        dataModel = DataFrameModel()
        dataModel.setDataFrame(self.df)

        self.dataModel = dataModel

        self.dataListView.setModel(dataModel)
        self.dataTableView.setViewModel(dataModel)
        self.dataComboBox.setModel(dataModel)

        # self.dataTableView.resizeColumnsToContents()

        # create a simple item model for our choosing combobox
        columnModel = QtGui.QStandardItemModel()
        for column in self.df.columns:
            columnModel.appendRow(QtGui.QStandardItem(column))
        self.chooseColumnComboBox.setModel(columnModel)

        self.tableViewColumnDtypes.setModel(dataModel.columnDtypeModel())
        self.tableViewColumnDtypes.horizontalHeader().setDefaultSectionSize(
            200)
        self.tableViewColumnDtypes.setItemDelegateForColumn(
            1, DtypeComboDelegate(self.tableViewColumnDtypes))
        dataModel.changingDtypeFailed.connect(self.changeColumnValue)
示例#3
0
def test_copyDataFrame(copy, operator):
    dataFrame = pandas.DataFrame([0], columns=['A'])
    model = DataFrameModel(dataFrame, copyDataFrame=copy)
    assert operator(id(model.dataFrame()), id(dataFrame))

    model.setDataFrame(dataFrame, copyDataFrame=copy)
    assert operator(id(model.dataFrame()), id(dataFrame))
示例#4
0
def test_TimestampFormat():
    model = DataFrameModel()
    assert model.timestampFormat == Qt.ISODate
    newFormat = u"yy-MM-dd hh:mm"
    model.timestampFormat = newFormat
    assert model.timestampFormat == newFormat

    with pytest.raises(TypeError) as excinfo:
        model.timestampFormat = "yy-MM-dd hh:mm"
    assert "unicode" in unicode(excinfo.value)
示例#5
0
def test_setDataFrame():
    dataFrame = pandas.DataFrame([0], columns=['A'])
    model = DataFrameModel()
    model.setDataFrame(dataFrame)
    assert not model.dataFrame().empty
    assert model.dataFrame() is dataFrame

    with pytest.raises(TypeError) as excinfo:
        model.setDataFrame(None)
    assert "pandas.core.frame.DataFrame" in unicode(excinfo.value)
示例#6
0
    def _previewFile(self):
        """Updates the preview widgets with new models for both tab panes.

        """
        dataFrame = self._loadCSVDataFrame()
        dataFrameModel = DataFrameModel(dataFrame)
        self._previewTableView.setModel(dataFrameModel)
        columnModel = dataFrameModel.columnDtypeModel()
        columnModel.changeFailed.connect(self.updateStatusBar)
        self._datatypeTableView.setModel(columnModel)
示例#7
0
def display_query(selcols):
    ## setup a new empty model
    model1 = DataFrameModel()
    ## setup an application and create a table view widget
    app = QtGui.QApplication([])
    widget1 = DataTableWidget()
    widget1.resize(1600, 800)
    widget1.show()
    ## asign the created model
    widget1.setViewModel(model1)
    ## fill the model with data
    model1.setDataFrame(selcols)
    ## start the app"""
    app.exec_()
    return
示例#8
0
    def accepted(self):
        """Successfully close the widget and return the loaded model.

        This method is also a `SLOT`.
        The dialog will be closed, when the `ok` button is pressed. If
        a `DataFrame` was loaded, it will be emitted by the signal `load`.

        """
        model = self._previewTableView.model()
        if model is not None:
            df = model.dataFrame().copy()
            dfModel = DataFrameModel(df)
            self.load.emit(dfModel, self._filename)
        self._resetWidgets()
        self.accept()
示例#9
0
def test_flags():
    model = DataFrameModel(pandas.DataFrame([0], columns=['A']))
    index = model.index(0, 0)
    assert index.isValid()
    assert model.flags(index) == Qt.ItemIsSelectable | Qt.ItemIsEnabled

    model.enableEditing(True)
    assert model.flags(
        index) == Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable

    model.setDataFrame(pandas.DataFrame([True], columns=['A']))
    index = model.index(0, 0)
    model.enableEditing(True)
    assert model.flags(
        index) != Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable
    assert model.flags(
        index
    ) == Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsUserCheckable
示例#10
0
    def test_remove_columns_random(self, dataFrame):

        columnNames = dataFrame.columns.tolist()
        columnNames = [(i, n) for i, n in enumerate(columnNames)]

        for cycle in xrange(1000):
            elements = random.randint(1, len(columnNames))
            names = random.sample(columnNames, elements)
            df = dataFrame.copy()
            model = DataFrameModel(df)
            assert not model.removeDataFrameColumns(names)
            model.enableEditing(True)
            model.removeDataFrameColumns(names)

            _columnSet = set(columnNames)
            _removedSet = set(names)
            remainingColumns = _columnSet - _removedSet
            for idx, col in remainingColumns:
                assert col in model.dataFrame().columns.tolist()
示例#11
0
    def test_editing(self, dataFrame, qtbot):
        model = DataFrameModel(dataFrame)

        tableView = QtGui.QTableView()

        qtbot.addWidget(tableView)
        tableView.setModel(model)

        delegate = TextDelegate(tableView)
        createDelegate(numpy.dtype('O'), 0, tableView)
        tableView.show()

        index = model.index(0, 0)
        preedit_data = index.data()

        assert not model.editable
        model.enableEditing(True)
        tableView.edit(index)
        editor = tableView.findChildren(QtGui.QLineEdit)[0]
        qtbot.keyPress(editor, QtCore.Qt.Key_F)
        qtbot.keyPress(editor, QtCore.Qt.Key_Enter)
        QtGui.QApplication.processEvents()
        with qtbot.waitSignal(timeout=100):
            assert index.data(QtCore.Qt.DisplayRole) == 'f'
示例#12
0
def test_rowCount():
    model = DataFrameModel(pandas.DataFrame([0], columns=['A']))
    assert model.rowCount() == 1
    model = DataFrameModel(pandas.DataFrame(numpy.arange(100), columns=['A']))
    assert model.rowCount() == 100
示例#13
0
def test_initDataFrame():
    model = DataFrameModel()
    assert model.dataFrame().empty
示例#14
0
def test_initDataFrameWithDataFrame():
    dataFrame = pandas.DataFrame([0], columns=['A'])
    model = DataFrameModel(dataFrame)
    assert not model.dataFrame().empty
    assert model.dataFrame() is dataFrame
示例#15
0
def dataModel2():
    df = pandas.DataFrame([[1,2,3,4,5,6,7,8]], columns=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'])
    model = DataFrameModel(df)
    return model
示例#16
0
def dataModel():
        df = pandas.DataFrame([10], columns=['A'])
        model = DataFrameModel(df)
        return model
示例#17
0
import pandas
import numpy
import sys
from pandasqt.excepthook import excepthook
sys.excepthook = excepthook

# use QtGui from the compat module to take care if correct sip version, etc.
from pandasqt.compat import QtGui
from pandasqt.models.DataFrameModel import DataFrameModel
from pandasqt.views.DataTableView import DataTableWidget
from pandasqt.views._ui import icons_rc
"""setup a new empty model"""
model = DataFrameModel()
"""setup an application and create a table view widget"""
app = QtGui.QApplication([])
widget = DataTableWidget()
widget.resize(800, 600)
widget.show()
"""asign the created model"""
widget.setViewModel(model)
"""create some test data"""
data = {
    'A': [10, 11, 12],
    'B': [20, 21, 22],
    'C': ['Peter Pan', 'Cpt. Hook', 'Tinkerbell']
}
df = pandas.DataFrame(data)
"""convert the column to the numpy.int8 datatype to test the delegates in the table
int8 is limited to -128-127
"""
df['A'] = df['A'].astype(numpy.int8)
示例#18
0
 def model(self, dataFrame):
     return DataFrameModel(dataFrame)
示例#19
0
def test_headerData(orientation, role, index, expectedHeader):
    model = DataFrameModel(pandas.DataFrame([0], columns=['A']))
    assert model.headerData(index, orientation, role) == expectedHeader