Пример #1
0
def test_seriescolumn():

    dm1 = DataMatrix(length=2)
    dm1.col1 = SeriesColumn(2)
    dm1.col1 = 1, 2
    dm1.col_shared = SeriesColumn(2)
    dm1.col_shared = 3, 4
    dm2 = DataMatrix(length=2)
    dm2.col2 = SeriesColumn(2)
    dm2.col2 = 5, 6
    dm2.col_shared = SeriesColumn(2)
    dm2.col_shared = 7, 8
    dm3 = dm1 << dm2
    check_series(dm3.col1,
                 [[1, 1], [2, 2], [np.nan, np.nan], [np.nan, np.nan]])
    check_series(dm3.col_shared, [[3, 3], [4, 4], [7, 7], [8, 8]])
    check_series(dm3.col2,
                 [[np.nan, np.nan], [np.nan, np.nan], [5, 5], [6, 6]])
    dm3.i = [4, 0, 2, 1]
    dm4 = dm3.i <= 2
    dm5 = (dm3.i <= 2) | (dm3.i >= 3)
    check_integrity(dm1)
    check_integrity(dm2)
    check_integrity(dm3)
    check_integrity(dm4)
    check_integrity(dm5)
Пример #2
0
def check_shuffle(col_type):

    dm = DataMatrix(length=3, default_col_type=col_type)
    dm.col1 = 11, 12, 13
    dm.col2 = 1, 2, 3
    dm = operations.shuffle(dm)
    for row in dm:
        ok_(row.col1 == row.col2 + 10)
    dm.col1 = operations.shuffle(dm.col1)
    dm.col2 = operations.shuffle(dm.col2)
    check_integrity(dm)
Пример #3
0
def check_shuffle(col_type):

	dm = DataMatrix(length=3, default_col_type=col_type)
	dm.col1 = 11,12,13
	dm.col2 = 1,2,3
	dm = operations.shuffle(dm)
	for row in dm:
		ok_(row.col1 == row.col2+10)
	dm.col1 = operations.shuffle(dm.col1)
	dm.col2 = operations.shuffle(dm.col2)
	check_integrity(dm)
Пример #4
0
def check_iteration(col_type):

	dm = DataMatrix(length=2, default_col_type=col_type)
	dm.col1 = 1, 2
	dm.col2 = 3, 4
	# Row iteration
	ref = [
		[('col1', 1), ('col2', 3)],
		[('col1', 2), ('col2', 4)]
		]
	for row, rowref in zip(dm, ref):
		assert(list(row) == rowref)
	# Column iteration
	ref = [
		('col1', [1,2]),
		('col2', [3,4])
		]
	for (name, col), (ref_name, ref_col) in zip(dm.columns, ref):
		assert(name == ref_name)
		assert(list(col) == ref_col)
	# Cells within column iteration
	ref = [1,2]
	for val, ref_val in zip(dm.col1, ref):
		assert(val == ref_val)
	# Cells within row iteration
	ref = [
		('col1', 1),
		('col2', 3)
		]
	for (name, val), (ref_name, ref_val) in zip(dm[0], ref):
		assert(val == ref_val)
		assert(name == ref_name)
Пример #5
0
def check_nan_sort():

	dm = DataMatrix(length=3, default_col_type=FloatColumn)
	dm.col1 = 2,np.nan,1
	dm.col2 = 1,2,np.nan
	dm = operations.sort(dm, by=dm.col1)
	check_col(dm.col1, [1, 2, np.nan])
	check_col(dm.col2, [np.nan, 1, 2])
	dm = operations.sort(dm, by=dm.col2)
	check_col(dm.col1, [2, np.nan, 1])
	check_col(dm.col2, [1, 2, np.nan])
	dm.col1 = operations.sort(dm.col1)
	dm.col2 = operations.sort(dm.col2)
	check_col(dm.col1, [1, 2, np.nan])
	check_col(dm.col2, [1, 2, np.nan])
	check_integrity(dm)
Пример #6
0
def check_nan_sort():

    dm = DataMatrix(length=3, default_col_type=FloatColumn)
    dm.col1 = 2, np.nan, 1
    dm.col2 = 1, 2, np.nan
    dm = operations.sort(dm, by=dm.col1)
    check_col(dm.col1, [1, 2, np.nan])
    check_col(dm.col2, [np.nan, 1, 2])
    dm = operations.sort(dm, by=dm.col2)
    check_col(dm.col1, [2, np.nan, 1])
    check_col(dm.col2, [1, 2, np.nan])
    dm.col1 = operations.sort(dm.col1)
    dm.col2 = operations.sort(dm.col2)
    check_col(dm.col1, [1, 2, np.nan])
    check_col(dm.col2, [1, 2, np.nan])
    check_integrity(dm)
Пример #7
0
def check_sort(col_type):

	dm = DataMatrix(length=3, default_col_type=col_type)
	dm.col1 = 3,2,1
	dm.col2 = 1,2,3
	dm = operations.sort(dm, by=dm.col1)
	check_col(dm.col1, [1, 2, 3])
	check_col(dm.col2, [3, 2, 1])
	dm = operations.sort(dm, by=dm.col2)
	check_col(dm.col1, [3, 2, 1])
	check_col(dm.col2, [1, 2, 3])
	dm.col2 = operations.sort(dm.col2, by=dm.col1)
	check_col(dm.col2, [3, 2, 1])
	dm.col1 = operations.sort(dm.col1)
	dm.col2 = operations.sort(dm.col2)
	check_col(dm.col1, [1, 2, 3])
	check_col(dm.col2, [1, 2, 3])
	check_integrity(dm)
Пример #8
0
def check_sort(col_type):

    dm = DataMatrix(length=3, default_col_type=col_type)
    dm.col1 = 3, 2, 1
    dm.col2 = 1, 2, 3
    dm = operations.sort(dm, by=dm.col1)
    check_col(dm.col1, [1, 2, 3])
    check_col(dm.col2, [3, 2, 1])
    dm = operations.sort(dm, by=dm.col2)
    check_col(dm.col1, [3, 2, 1])
    check_col(dm.col2, [1, 2, 3])
    dm.col2 = operations.sort(dm.col2, by=dm.col1)
    check_col(dm.col2, [3, 2, 1])
    dm.col1 = operations.sort(dm.col1)
    dm.col2 = operations.sort(dm.col2)
    check_col(dm.col1, [1, 2, 3])
    check_col(dm.col2, [1, 2, 3])
    check_integrity(dm)
Пример #9
0
def check_concat(col_type, invalid):

    dm1 = DataMatrix(length=2, default_col_type=col_type)
    dm1.col1 = 1, 2
    dm1.col_shared = 3, 4
    dm2 = DataMatrix(length=2, default_col_type=col_type)
    dm2.col2 = 5, 6
    dm2.col_shared = 7, 8
    dm3 = dm1 << dm2
    check_col(dm3.col1, [1, 2, invalid, invalid])
    check_col(dm3.col_shared, [3, 4, 7, 8])
    check_col(dm3.col2, [invalid, invalid, 5, 6])
Пример #10
0
def check_concat(col_type, invalid):

	dm1 = DataMatrix(length=2, default_col_type=col_type)
	dm1.col1 = 1, 2
	dm1.col_shared = 3, 4
	dm2 = DataMatrix(length=2, default_col_type=col_type)
	dm2.col2 = 5, 6
	dm2.col_shared = 7, 8
	dm3 = dm1 << dm2
	check_col(dm3.col1, [1,2,invalid,invalid])
	check_col(dm3.col_shared, [3,4,7,8])
	check_col(dm3.col2, [invalid,invalid,5,6])
Пример #11
0
def test_seriescolumn():

	dm1 = DataMatrix(length=2)
	dm1.col1 = SeriesColumn(2)
	dm1.col1 = 1, 2
	dm1.col_shared = SeriesColumn(2)
	dm1.col_shared = 3, 4
	dm2 = DataMatrix(length=2)
	dm2.col2 = SeriesColumn(2)
	dm2.col2 = 5, 6
	dm2.col_shared = SeriesColumn(2)
	dm2.col_shared = 7, 8
	dm3 = dm1 << dm2
	check_series(dm3.col1, [[1,1],[2,2],[0,0],[0,0]])
	check_series(dm3.col_shared, [[3,3],[4,4],[7,7],[8,8]])
	check_series(dm3.col2, [[0,0],[0,0],[5,5],[6,6]])
	dm3.i = [4,0,2,1]
	dm4 = dm3.i <= 2
	dm5 = (dm3.i <= 2) | (dm3.i >= 3)
	check_integrity(dm1)
	check_integrity(dm2)
	check_integrity(dm3)
	check_integrity(dm4)
	check_integrity(dm5)
Пример #12
0
def check_iteration(col_type):

    dm = DataMatrix(length=2, default_col_type=col_type)
    dm.col1 = 1, 2
    dm.col2 = 3, 4
    # Row iteration
    ref = [[('col1', 1), ('col2', 3)], [('col1', 2), ('col2', 4)]]
    for row, rowref in zip(dm, ref):
        assert (list(row) == rowref)
    # Column iteration
    ref = [('col1', [1, 2]), ('col2', [3, 4])]
    for (name, col), (ref_name, ref_col) in zip(dm.columns, ref):
        assert (name == ref_name)
        assert (list(col) == ref_col)
    # Cells within column iteration
    ref = [1, 2]
    for val, ref_val in zip(dm.col1, ref):
        assert (val == ref_val)
    # Cells within row iteration
    ref = [('col1', 1), ('col2', 3)]
    for (name, val), (ref_name, ref_val) in zip(dm[0], ref):
        assert (val == ref_val)
        assert (name == ref_name)
Пример #13
0
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

qdatamatatrix is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with qdatamatatrix.  If not, see <http://www.gnu.org/licenses/>.
"""

from datamatrix import DataMatrix
from qdatamatrix import QDataMatrix
import sys
from qtpy import QtWidgets
import qtpy

dm = DataMatrix(length=3)
dm.col1 = 1, 2, 3
dm.col2 = 'a', 'b', 'c'
print(dm)

app = QtWidgets.QApplication(sys.argv)
qdm = QDataMatrix(dm)
qdm.resize(600,400)
# qdm.refresh()
qdm.show()
sys.exit(app.exec_())
Пример #14
0
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

qdatamatatrix is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with qdatamatatrix.  If not, see <http://www.gnu.org/licenses/>.
"""

from datamatrix import DataMatrix
from qdatamatrix import QDataMatrix
import sys
from qtpy import QtWidgets
import qtpy

dm = DataMatrix(length=3)
dm.col1 = 1, 2, 3
dm.col2 = 'a', 'b', 'c'
print(dm)

app = QtWidgets.QApplication(sys.argv)
qdm = QDataMatrix(dm)
qdm.resize(600, 400)
# qdm.refresh()
qdm.show()
sys.exit(app.exec_())
Пример #15
0
You should have received a copy of the GNU General Public License
along with qdatamatatrix.  If not, see <http://www.gnu.org/licenses/>.
"""

from datamatrix import DataMatrix
from qdatamatrix import QDataMatrix
import sys
from qtpy import QtWidgets
import qtpy


def show():
    print(qdm._dm)
    for n, c in qdm._dm.columns:
        print(n, repr(c._rowid))


dm = DataMatrix(length=4)
dm.sorted = False
dm.col1 = range(4)
dm.col3 = ['a', 'b', 'c', 'd']
dm.col2 = ['e', 'f', 'g', 'h']
print(dm)
app = QtWidgets.QApplication(sys.argv)
qdm = QDataMatrix(dm, read_only=False)
qdm.resize(600, 400)
qdm.changed.connect(show)
qdm.show()
sys.exit(app.exec_())