mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-09 03:43:49 +08:00
TST: Convert test_munge.py tests to unittest format
This commit is contained in:
+32
-31
@@ -17,43 +17,44 @@ import random
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
from numpy.testing import assert_almost_equal
|
||||
|
||||
from unittest import TestCase
|
||||
from zipline.utils.munge import bfill, ffill
|
||||
|
||||
|
||||
def test_bfill():
|
||||
# test ndim=1
|
||||
N = 100
|
||||
s = pd.Series(np.random.randn(N))
|
||||
mask = random.sample(range(N), 10)
|
||||
s.iloc[mask] = np.nan
|
||||
class MungeTests(TestCase):
|
||||
def test_bfill(self):
|
||||
# test ndim=1
|
||||
N = 100
|
||||
s = pd.Series(np.random.randn(N))
|
||||
mask = random.sample(range(N), 10)
|
||||
s.iloc[mask] = np.nan
|
||||
|
||||
correct = s.bfill().values
|
||||
test = bfill(s.values)
|
||||
assert_almost_equal(correct, test)
|
||||
correct = s.bfill().values
|
||||
test = bfill(s.values)
|
||||
assert_almost_equal(correct, test)
|
||||
|
||||
# test ndim=2
|
||||
df = pd.DataFrame(np.random.randn(N, N))
|
||||
df.iloc[mask] = np.nan
|
||||
correct = df.bfill().values
|
||||
test = bfill(df.values)
|
||||
assert_almost_equal(correct, test)
|
||||
# test ndim=2
|
||||
df = pd.DataFrame(np.random.randn(N, N))
|
||||
df.iloc[mask] = np.nan
|
||||
correct = df.bfill().values
|
||||
test = bfill(df.values)
|
||||
assert_almost_equal(correct, test)
|
||||
|
||||
|
||||
def test_ffill():
|
||||
# test ndim=1
|
||||
N = 100
|
||||
s = pd.Series(np.random.randn(N))
|
||||
mask = random.sample(range(N), 10)
|
||||
s.iloc[mask] = np.nan
|
||||
def test_ffill(self):
|
||||
# test ndim=1
|
||||
N = 100
|
||||
s = pd.Series(np.random.randn(N))
|
||||
mask = random.sample(range(N), 10)
|
||||
s.iloc[mask] = np.nan
|
||||
|
||||
correct = s.ffill().values
|
||||
test = ffill(s.values)
|
||||
assert_almost_equal(correct, test)
|
||||
correct = s.ffill().values
|
||||
test = ffill(s.values)
|
||||
assert_almost_equal(correct, test)
|
||||
|
||||
# test ndim=2
|
||||
df = pd.DataFrame(np.random.randn(N, N))
|
||||
df.iloc[mask] = np.nan
|
||||
correct = df.ffill().values
|
||||
test = ffill(df.values)
|
||||
assert_almost_equal(correct, test)
|
||||
# test ndim=2
|
||||
df = pd.DataFrame(np.random.randn(N, N))
|
||||
df.iloc[mask] = np.nan
|
||||
correct = df.ffill().values
|
||||
test = ffill(df.values)
|
||||
assert_almost_equal(correct, test)
|
||||
|
||||
Reference in New Issue
Block a user