Exemple #1
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 #2
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 #3
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 #4
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])