|
18 | 18 | """ |
19 | 19 |
|
20 | 20 | from datamatrix.py3compat import * |
21 | | -from datamatrix import DataMatrix, MixedColumn, IntColumn, FloatColumn |
| 21 | +from datamatrix import DataMatrix, MixedColumn, IntColumn, FloatColumn, \ |
| 22 | + MultiDimensionalColumn |
22 | 23 | from datamatrix import functional as fnc |
23 | | -from testcases.test_tools import capture_stdout |
| 24 | +from testcases.test_tools import capture_stdout, check_series |
24 | 25 |
|
25 | 26 |
|
26 | | -def test_map_(): |
| 27 | +def test_map(): |
27 | 28 |
|
28 | 29 | for coltype in (MixedColumn, FloatColumn, IntColumn): |
29 | 30 | dm = DataMatrix(length=2, default_col_type=coltype) |
30 | 31 | dm.a = 1, 2 |
31 | 32 | dm.a = fnc.map_(lambda x: x*2, dm.a) |
32 | 33 | assert dm.a == [2, 4] |
33 | 34 | assert isinstance(dm.a, coltype) |
| 35 | + dm.a = 1, 2 |
| 36 | + dm.a = dm.a @ (lambda x: x*2) |
| 37 | + assert dm.a == [2, 4] |
| 38 | + assert isinstance(dm.a, coltype) |
34 | 39 | dm = fnc.map_(lambda **d: {'a' : 0}, dm) |
35 | 40 | assert dm.a == [0, 0] |
36 | 41 | assert isinstance(dm.a, coltype) |
37 | 42 |
|
38 | 43 |
|
39 | | -def test_filter_(): |
| 44 | +def test_map_multidimensional(): |
| 45 | + dm = DataMatrix(length=2) |
| 46 | + dm.m = MultiDimensionalColumn(shape=(3,)) |
| 47 | + dm.m = [[1,2,3], [4,5,6]] |
| 48 | + dm.mean = dm.m @ (lambda a: a.mean()) |
| 49 | + assert dm.mean == [2, 5] |
| 50 | + dm.half = dm.m @ (lambda a: a / 2) |
| 51 | + check_series(dm.half, [[0.5, 1., 1.5], [2, 2.5, 3.]]) |
| 52 | + dm.short = dm.m @ (lambda a: a[:2]) |
| 53 | + check_series(dm.short, [[1, 2], [4, 5]]) |
| 54 | + |
| 55 | + |
| 56 | +def test_filter(): |
40 | 57 |
|
41 | 58 | dm = DataMatrix(length=4) |
42 | 59 | dm.a = range(4) |
|
0 commit comments