Exemple #1
0
def test_compute_column():
    t = Table({'a': [1, 2, 3], 'b': np.array([4, 5, 6])})
    t1 = Table({'a': [1, 2, 3], 'd': np.array([4, 5, 6])})
    t.stack(t1)

    t.c = t.a + t.a / 2
    records = [r for r in t.records()]
    assert records == [{
        'a': 1,
        'b': 4,
        'c': 1.5
    }, {
        'a': 2,
        'b': 5,
        'c': 3.0
    }, {
        'a': 3,
        'b': 6,
        'c': 4.5
    }, {
        'a': 1,
        'd': 4,
        'c': 1.5
    }, {
        'a': 2,
        'd': 5,
        'c': 3.0
    }, {
        'a': 3,
        'd': 6,
        'c': 4.5
    }]
Exemple #2
0
def test_compute_wrong_size():
    t = Table({'a': [1, 2, 3], 'b': np.array([4, 5, 6])})
    t1 = Table({'a': [1, 2, 3], 'd': np.array([4, 5, 6])})
    t.stack(t1)

    t.c = t.a + t.b / 2
    assert np.all(t.c.values == np.array([3, 4.5, 6]))
    assert np.all(t.c.index == np.array([1, 1, 1, 0, 0, 0]))
Exemple #3
0
def test_filter_3():
    t = Table()
    t.a = np.random.rand(10)
    t.b = pd.date_range('2000-01-01', freq='M', periods=10)
    t.c = np.array([1, 2])
    t.add_column('d', np.array([1, 2]), align='bottom')
    t1 = t.filter(t.c > 0)

    assert t1.c.values[0] == 1
    assert np.all(t1.d.values == np.array([]))
Exemple #4
0
def test_crop_2():
    t = Table()
    t.a = np.random.rand(10)
    t.b = pd.date_range('2000-01-01', freq='D', periods=10)
    t.c = np.array([1, 2])
    t.add_column('d', np.array([1, 2]), align='bottom')
    t1 = t.crop('d')

    assert np.all(t1.c.values == np.array([]))
    assert np.all(t1.d.values == np.array([1, 2]))
    assert np.all(t1.a.values == t.a.values[-2:])
    assert np.all(t1.b.values == t.b.values[-2:])
Exemple #5
0
def test_sieve():
    t = Table()
    t.a = np.arange(10)
    t.b = pd.date_range('2000-01-01', freq='D', periods=10)
    t.c = np.array(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'])

    t1 = t.sieve(np.array([0, 0, 0, 0, 0, 1, 1, 1, 0, 0], dtype=np.bool_))

    print(t1.b.values)
    assert t1.a.values[0] == 5
    assert t1.b.values[0] == np.datetime64('2000-01-06')
    assert t1.c.values[0] == 'f'
Exemple #6
0
def test_filter_date():
    t = Table()
    t.a = np.random.rand(10)
    t.b = pd.date_range('2000-01-01', freq='D', periods=10)
    t.c = np.array([1, 2])
    t.add_column('d', np.array([1, 2]), align='bottom')

    thres1 = np.array(['2000-01-03'], dtype=np.datetime64)
    thres2 = np.array(['2000-01-05'], dtype=np.datetime64)
    t1 = t.filter(t.b >= thres1)
    assert np.all(t1.c.values == np.array([]))
    assert np.all(t1.d.values == np.array([1, 2]))
    assert np.all(t1.a.values == t.a.values[2:])

    t1 = t.filter((t.b >= thres1) & (t.b <= thres2))
    assert np.all(t1.c.values == np.array([]))
    assert np.all(t1.d.values == np.array([]))
    assert np.all(t1.a.values == t.a.values[2:5])

    t1 = t.filter(t.b.date_range(fr=thres1, to=thres2))
    assert np.all(t1.c.values == np.array([]))
    assert np.all(t1.d.values == np.array([]))
    assert np.all(t1.a.values == t.a.values[2:5])