-
Notifications
You must be signed in to change notification settings - Fork 589
/
agg_tests.py
82 lines (64 loc) 路 2.46 KB
/
agg_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import vaex
import numpy as np
from common import *
# def test_count_multiple_selections():
def test_count_1d():
x = np.array([-1, -2, 0.5, 1.5, 4.5, 5], dtype='f8')
df = vaex.from_arrays(x=x)
bins = 5
binner = df._binner_scalar('x', [0, 5], bins)
grid = vaex.superagg.Grid([binner])
agg = vaex.agg.count()
grid = df._agg(agg, grid)
assert grid.tolist() == [0, 2, 1, 1, 0, 0, 1, 1]
def test_count_types(ds_local):
df = ds_local
assert df.count(df.x) is not None
assert df.count(df.datetime) is not None
assert df.min(df.datetime) is not None
assert df.max(df.datetime) is not None
assert df.minmax(df.datetime) is not None
assert df.std(df.datetime) is not None
def test_count_1d_ordinal():
x = np.array([-1, -2, 0, 1, 4, 5], dtype='i8')
df = vaex.from_arrays(x=x)
bins = 5
binner = df._binner_ordinal('x', 5)
grid = vaex.superagg.Grid([binner])
agg = vaex.agg.count()
grid = df._agg(agg, grid)
assert grid.tolist() == [0, 2, 1, 1, 0, 0, 1, 1]
def test_big_endian_binning():
x = np.arange(10, dtype='>f8')
y = np.zeros(10, dtype='>f8')
ds = vaex.from_arrays(x=x, y=y)
counts = ds.count(binby=[ds.x, ds.y], limits=[[-0.5, 9.5], [-0.5, 0.5]], shape=[10, 1])
assert counts.ravel().tolist() == np.ones(10).tolist()
def test_big_endian_binning_non_contiguous():
x = np.arange(20, dtype='>f8')[::2]
x[:] = np.arange(10, dtype='>f8')
y = np.arange(20, dtype='>f8')[::2]
y[:] = np.arange(10, dtype='>f8')
ds = vaex.from_arrays(x=x, y=y)
counts = ds.count(binby=[ds.x, ds.y], limits=[[-0.5, 9.5], [-0.5, 9.5]], shape=[10, 10])
assert np.diagonal(counts).tolist() == np.ones(10).tolist()
def test_strides():
ar = np.zeros((10, 2)).reshape(20)
x = ar[::2]
x[:] = np.arange(10)
ds = vaex.from_arrays(x=x)
counts = ds.count(binby=ds.x, limits=[-0.5, 9.5], shape=10)
assert counts.tolist() == np.ones(10).tolist()
def test_expr():
ar = np.zeros((10, 2)).reshape(20)
x = ar[::2]
x[:] = np.arange(10)
ds = vaex.from_arrays(x=x)
counts = ds.count('x*2', binby='x*2', limits=[-0.5, 19.5], shape=10)
assert counts.tolist() == np.ones(10).tolist()
def test_big_endian_binning():
x = np.arange(10, dtype='>f8')
y = np.zeros(10, dtype='>f8')
ds = vaex.from_arrays(x=x, y=y)
counts = ds.count(binby=[ds.x, ds.y], limits=[[-0.5, 9.5], [-0.5, 0.5]], shape=[10, 1])
assert counts.ravel().tolist() == np.ones(10).tolist()