Skip to content

Commit 8c35454

Browse files
committed
Fix type def from linter
1 parent c873d63 commit 8c35454

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

examples/tools/hunting-anomalies/build-lookup-table.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import os
2-
import pandas as pd # type: ignore
2+
import pandas as pd # type: ignore
33
from collections import defaultdict
44
import pickle
55
import json
6+
from typing import DefaultDict, Dict, Any, BinaryIO
67

78
# Directory containing the daily CSV files
89
data_dir = "./aggregates_day/"
@@ -34,7 +35,9 @@
3435
print("Building lookup table...")
3536

3637
# Now, build the lookup table with rolling averages and percentage price change
37-
lookup_table = defaultdict(dict) # Nested dict: ticker -> date -> stats
38+
lookup_table: DefaultDict[str, Dict[str, Any]] = defaultdict(
39+
dict
40+
) # Nested dict: ticker -> date -> stats
3841

3942
for ticker, records in trades_data.items():
4043
# Convert records to DataFrame
@@ -79,16 +82,16 @@
7982
print("Lookup table built successfully.")
8083

8184
# Convert defaultdict to regular dict for JSON serialization
82-
lookup_table = {k: v for k, v in lookup_table.items()}
85+
lookup_table_dict = {k: v for k, v in lookup_table.items()}
8386

8487
# Save the lookup table to a JSON file
8588
with open("lookup_table.json", "w") as f:
86-
json.dump(lookup_table, f, indent=4)
89+
json.dump(lookup_table_dict, f, indent=4)
8790

8891
print("Lookup table saved to 'lookup_table.json'.")
8992

9093
# Save the lookup table to a file for later use
91-
with open("lookup_table.pkl", "wb") as f:
92-
pickle.dump(lookup_table, f)
94+
with open("lookup_table.pkl", "wb") as f: # type: BinaryIO
95+
pickle.dump(lookup_table_dict, f)
9396

9497
print("Lookup table saved to 'lookup_table.pkl'.")

0 commit comments

Comments
 (0)