Skip to content

Commit

Permalink
Merge pull request #831 from janga1997/typeHint-loadData
Browse files Browse the repository at this point in the history
Add type hints to load_data
  • Loading branch information
drvinceknight authored Feb 10, 2017
2 parents d278a6e + 2990e46 commit 6d136e1
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions axelrod/load_data_.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import pkg_resources
from typing import List, Dict, Tuple, Union


def load_file(filename, directory):
def load_file(filename: str, directory: str) -> List[List[str]]:
"""Loads a data file stored in the Axelrod library's data subdirectory,
likely for parameters for a strategy."""
path = '/'.join((directory, filename))
data = pkg_resources.resource_string(__name__, path)
data = data.decode('UTF-8', 'replace')
data_bytes = pkg_resources.resource_string(__name__, path)
data = data_bytes.decode('UTF-8', 'replace')
rows = []
for line in data.split('\n'):
if line.startswith('#') or len(line) == 0:
Expand All @@ -16,7 +16,7 @@ def load_file(filename, directory):
return rows


def load_weights(filename="ann_weights.csv", directory="data"):
def load_weights(filename: str ="ann_weights.csv", directory: str ="data") -> Dict[str, Tuple[int, int, List[float]]]:
"""Load Neural Network Weights."""
rows = load_file(filename, directory)
d = dict()
Expand All @@ -28,7 +28,6 @@ def load_weights(filename="ann_weights.csv", directory="data"):
d[name] = (num_features, num_hidden, weights)
return d


def load_pso_tables(filename="pso_gambler.csv", directory="data"):
"""Load lookup tables."""
rows = load_file(filename, directory)
Expand Down

0 comments on commit 6d136e1

Please sign in to comment.