Exemplo n.º 1
0
def test_np_groupby_1():
    a = _get_sample_rec_array()
    g = np_groupby(a['n'], a['o'], np.max)
    assert g.shape == (100,)
    assert g.dtype == [('f0', '<i8'), ('f1', '<f8')]
    assert np.all(g['f0'] == np.arange(100))
    assert np.all(g['f1'] > 450)
Exemplo n.º 2
0
def test_np_groupby_5():
    a = _get_sample_rec_array()
    def compute_some_thing(x):
        o, p = x['o'], x['p']
        return np.mean(o) / np.std(o) * np.min(p)
    g = np_groupby(a[['m', 'n']], a, compute_some_thing,
                   names=['m', 'n', 'its_complicated'])
    assert g.shape == (200,)
    assert g.dtype == [('m', '|S4'), ('n', '<i8'), ('its_complicated', '<f8')]
Exemplo n.º 3
0
def test_np_groupby_4():
    a = _get_sample_rec_array()
    g = np_groupby(a[['m', 'n']], a,
                   lambda x: np.mean(x['o']),
                   lambda x: np.std(x['o']),
                   lambda x: np.min(x['p']),
                   names=['m', 'n', 'mean_o', 'std_o', 'min_p'])
    assert g.shape == (200,)
    assert g.dtype == [('m', '|S4'), ('n', '<i8'), ('mean_o', '<f8'),
                       ('std_o', '<f8'), ('min_p', '<f8')]
Exemplo n.º 4
0
def test_rec_groupby_3():
    a = _get_sample_rec_array()
    def compute_some_thing(x):
        o, p = x['o'], x['p']
        return np.mean(o) / np.std(o) * np.min(p)
    
    g_r = rec_groupby(a, ['m', 'n'], (compute_some_thing, ['o', 'p'], 'its_complicated'))
    g_n = np_groupby(a[['m', 'n']], a, compute_some_thing,
                     names=['m', 'n', 'its_complicated'])
    
    assert np.all(g_r == g_n)
Exemplo n.º 5
0
def test_np_groupby_3():
    a = _get_sample_rec_array()
    g = np_groupby(a['n'], a['o'], np.max, np.min,
                   names=['n', 'max_o', 'min_o'])
    assert g.max_o[0] != g.min_o[0]
Exemplo n.º 6
0
def test_np_groupby_2():
    a = _get_sample_rec_array()
    g = np_groupby(a['n'], a['o'], np.max, names=['n', 'max_o'])
    assert g.shape == (100,)
    assert g.dtype == [('n', '<i8'), ('max_o', '<f8')]
Exemplo n.º 7
0
def test_rec_groupby_2():
    a = _get_sample_rec_array()
    assert np.all(rec_groupby(a, 'n', (np.max, 'o', 'max_o'),
                                      (np.min, 'o', 'min_o')) ==
                  np_groupby(a['n'], a['o'], np.max, np.min,
                             names=['n', 'max_o', 'min_o']))