Beispiel #1
0
 def test_random_test(self):
     for i in range(100):
         n = random.randint(1, 2 ** 20)
         w = random.randint(1, 2 ** 10)
         x = np.random.rand(n)
         y = rollingrank.rollingrank(x, window=w, n_jobs=1)
         y_parallel = rollingrank.rollingrank(x, window=w)
         np.testing.assert_array_equal(y_parallel, y)
Beispiel #2
0
 def test_nan_pct(self):
     x = np.array([1, np.nan, 2, np.nan, 3])
     y = rollingrank.rollingrank(x, window=3, pct=True)
     np.testing.assert_array_equal(y, [np.nan, np.nan, 1, np.nan, 1])
Beispiel #3
0
 def test_nan_window1(self):
     x = np.array([1, np.nan, 2])
     y = rollingrank.rollingrank(x, window=1)
     np.testing.assert_array_equal(y, [1, np.nan, 1])
Beispiel #4
0
 def test_nan(self):
     x = np.array([1, np.nan, 2, np.nan, 3])
     y = rollingrank.rollingrank(x, window=3)
     np.testing.assert_array_equal(y, [np.nan, np.nan, 2, np.nan, 2])
Beispiel #5
0
 def test_parallel(self):
     x = np.random.rand(2 ** 20)
     y = rollingrank.rollingrank(x, window=3, n_jobs=1)
     y_parallel = rollingrank.rollingrank(x, window=3)
     np.testing.assert_array_equal(y_parallel, y)
Beispiel #6
0
def bench_nan():
    rollingrank.rollingrank(x_nan, window=window)
Beispiel #7
0
def bench_single():
    rollingrank.rollingrank(x, window=window, n_jobs=1)
Beispiel #8
0
import numpy as np
import rollingrank

x = np.array([0.1, 0.2, 0.3, 0.25, 0.1, 0.2, 0.3])
y = rollingrank.rollingrank(x, window=3)
print(y)

y = rollingrank.rollingrank(x, window=3, pct=True)
print(y)
Beispiel #9
0
 def test_rollingrank_large_window(self):
     x = np.array([0.1, 0.2, 0.3, 0.25, 0.1, 0.2, 0.3])
     y = rollingrank.rollingrank(x, window=8)
     np.testing.assert_array_equal(y, [np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan])
Beispiel #10
0
 def test_window1(self):
     x = np.array([0.1, 0.2, 0.3, 0.25, 0.1, 0.2, 0.3])
     y = rollingrank.rollingrank(x, window=1)
     np.testing.assert_array_equal(y, [1, 1, 1, 1, 1, 1, 1])
Beispiel #11
0
 def test_method_first(self):
     x = np.array([0.1, 0.1])
     y = rollingrank.rollingrank(x, window=2, method='first')
     np.testing.assert_array_equal(y, [np.nan, 2])
Beispiel #12
0
 def test_method_average(self):
     x = np.array([0.1, 0.1])
     y = rollingrank.rollingrank(x, window=2, method='average')
     np.testing.assert_array_equal(y, [np.nan, 1.5])
Beispiel #13
0
 def test_method_default(self):
     x = np.array([0.1, 0.1])
     y = rollingrank.rollingrank(x, window=2)
     np.testing.assert_array_equal(y, [np.nan, 1.5])
Beispiel #14
0
 def test_float16(self):
     x = np.array([-1, 0, 1, 3, 2]).astype(np.float16)
     y = rollingrank.rollingrank(x, window=3)
     np.testing.assert_array_equal(y, [np.nan, np.nan, 3, 3, 2])
Beispiel #15
0
 def test_complex_case(self):
     x = np.array([0.1, 0.2, 0.3, 0.2, 0.1, 0.2, 0.3])
     y = rollingrank.rollingrank(x, window=3)
     np.testing.assert_array_equal(y, [np.nan, np.nan, 3, 1.5, 1, 2.5, 3])
Beispiel #16
0
 def test_rollingrank_pct_pandas(self):
     x = np.array([0.1, 0.2, 0.3, 0.25, 0.1, 0.2, 0.3])
     y = rollingrank.rollingrank(x, window=3, pct=True, pct_mode='pandas')
     np.testing.assert_array_equal(y, [np.nan, np.nan, 1, 2.0 / 3, 1.0 / 3, 2.0 / 3, 1])
Beispiel #17
0
 def test_list_input(self):
     x = [0.1, 0.2, 0.3, 0.2, 0.1, 0.2, 0.3]
     y = rollingrank.rollingrank(x, window=3)
     np.testing.assert_array_equal(y, [np.nan, np.nan, 3, 1.5, 1, 2.5, 3])
Beispiel #18
0
 def test_rollingrank_pct_closed(self):
     x = np.array([0.1, 0.2, 0.3, 0.25, 0.1, 0.2, 0.3])
     y = rollingrank.rollingrank(x, window=3, pct=True, pct_mode='closed')
     np.testing.assert_array_equal(y, [np.nan, np.nan, 1, 0.5, 0, 0.5, 1])
Beispiel #19
0
def bench():
    rollingrank.rollingrank(x, window=window)
Beispiel #20
0
 def test_normal_case(self):
     x = np.array([0.1, 0.2, 0.3, 0.25, 0.1, 0.2, 0.3])
     y = rollingrank.rollingrank(x, window=3)
     np.testing.assert_array_equal(y, [np.nan, np.nan, 3, 2, 1, 2, 3])
Beispiel #21
0
def bench_float():
    rollingrank.rollingrank(x.astype('float32'), window=window)
Beispiel #22
0
 def test_rollingrank_pct_closed_window1(self):
     x = np.array([0.1, 0.2, 0.3, 0.25, 0.1, 0.2, 0.3])
     y = rollingrank.rollingrank(x, window=1, pct=True, pct_mode='closed')
     np.testing.assert_array_equal(y, [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5])
Beispiel #23
0
def bench_pct():
    rollingrank.rollingrank(x, window=window, pct=True)
Beispiel #24
0
 def test_pandas_series_input(self):
     x = np.array([0.1, 0.2, 0.3, 0.2, 0.1, 0.2, 0.3])
     y = rollingrank.rollingrank(pd.Series(x), window=3)
     np.testing.assert_array_equal(y, [np.nan, np.nan, 3, 1.5, 1, 2.5, 3])