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))
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 str(excinfo.value)
Example #3
0
    def open_merge_purge_dialog(self, model: DataFrameModel = None):
        if model is None:
            model = self.get_tree_selected_model()
        df = model.dataFrame()
        file_base, ext = os.path.splitext(model.filePath)
        dedupe_model = create_standard_item_model(df.columns)
        sort_model = create_standard_item_model(df.columns)

        self.dialog_merge_purge.set_handler_dedupe_on(
            column_model=dedupe_model, default_model=None)
        self.dialog_merge_purge.set_handler_sort_on(column_model=sort_model,
                                                    default_model=None)
        self.dialog_merge_purge.configure(source_path=model.filePath,
                                          dest_path=file_base + "_merged" +
                                          ext)
        self.dialog_merge_purge.show()
    def test_remove_columns_random(self, dataFrame):

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

        for cycle in range(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()
def test_initDataFrameWithDataFrame():
    dataFrame = pandas.DataFrame([0], columns=['A'])
    model = DataFrameModel(dataFrame)
    assert not model.dataFrame().empty
    assert model.dataFrame() is dataFrame
def test_initDataFrame():
    model = DataFrameModel()
    assert model.dataFrame().empty