Skip to content

Commit bdc1a45

Browse files
committed
fix tests util import
1 parent aad6b6e commit bdc1a45

File tree

2 files changed

+65
-71
lines changed

2 files changed

+65
-71
lines changed

tests/test_signals.py

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,77 @@
11
import unittest
2+
import random
3+
import string
4+
from typing import Callable, Optional
25

36
import numpy as np
4-
import pandas as pd # type: ignore
7+
import pandas as pd
58

69
from numerai_tools.signals import (
710
churn,
811
turnover,
912
calculate_max_churn_and_turnover,
1013
)
11-
from .util import (
12-
generate_fake_universe,
13-
generate_new_submission,
14-
)
14+
15+
16+
def generate_unique_values(generator: Callable, length: int, num_rows: int) -> list:
17+
"""Generates a list of unique values using the provided generator function."""
18+
values: set[str] = set()
19+
while len(values) < num_rows:
20+
new_value = generator(length)
21+
values.add(new_value)
22+
return list(values)
23+
24+
25+
def generate_ticker_ascii_uppercase(length: int) -> str:
26+
return "".join(random.choices(string.ascii_uppercase, k=length))
27+
28+
29+
def generate_fake_universe(
30+
date_value: str = "20130308", ticker_col: str = "numerai_ticker"
31+
) -> pd.DataFrame:
32+
num_rows = 100
33+
data = {
34+
"date": [date_value for _ in range(num_rows)],
35+
ticker_col: [
36+
ticker + " US"
37+
for ticker in generate_unique_values(
38+
generate_ticker_ascii_uppercase, 3, num_rows
39+
)
40+
],
41+
}
42+
43+
uni = pd.DataFrame(data)
44+
return uni
45+
46+
47+
def generate_new_submission(
48+
universe: pd.DataFrame,
49+
date_value: str = "2013-03-08",
50+
ticker_col: str = "numerai_ticker",
51+
legacy_headers: bool = False,
52+
date_col: Optional[str] = None,
53+
) -> pd.DataFrame:
54+
if legacy_headers and date_col is None:
55+
date_col = "friday_date"
56+
elif date_col is None:
57+
date_col = date_col
58+
else:
59+
date_col = "date"
60+
61+
rows = []
62+
for ticker in universe[ticker_col].unique():
63+
if legacy_headers:
64+
rows.append(
65+
{
66+
ticker_col: ticker,
67+
"signal": random.random(),
68+
"data_type": "live",
69+
date_col: date_value,
70+
}
71+
)
72+
else:
73+
rows.append({ticker_col: ticker, "signal": random.random()})
74+
return pd.DataFrame(rows)
1575

1676

1777
class TestSignals(unittest.TestCase):

tests/util.py

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)