Skip to content

Commit 47e63e6

Browse files
committed
add travis and fix typings
1 parent 094eb4c commit 47e63e6

8 files changed

+32
-15
lines changed

.flake8

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[flake8]
2+
max-line-length = 120

.travis.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
language: python
2+
python:
3+
- "3.6"
4+
5+
install:
6+
pip install -r requirements.txt
7+
8+
script:
9+
- flake8
10+
- mypy --config-file mypy.ini recommendations/*.py

mypy.ini

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[mypy]
2+
ignore_missing_imports = True
3+
disallow_untyped_calls = True
4+
disallow_untyped_defs = True
5+
disallow_incomplete_defs = True
6+
check_untyped_defs = True

recommendations/create_dataset.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import click
44
import logging
55
import pandas as pd
6-
import numpy as np
76
import psycopg2 as pg
87
from prettytable import PrettyTable
98
from lightfm.data import Dataset as LFMDataset
@@ -170,7 +169,7 @@ def build_lightfm_dataset(self) -> None:
170169
logging.info(
171170
f'The shape of self.interactions {self.interactions.shape} '
172171
f'and self.weights {self.weights.shape} represent the user-item matrix.')
173-
172+
174173

175174
@click.command()
176175
@click.option('--config', default='production', help='the deployment target')
@@ -187,4 +186,4 @@ def main(config: str) -> None:
187186
if __name__ == "__main__":
188187
logger = helpers.get_logger()
189188

190-
main()
189+
main()

recommendations/drop_data.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import helpers
66
import schema
77

8+
89
@click.command()
910
@click.option('--file', default='production', help='the dataset to drop from Postgres database')
1011
def main(file: str) -> None:
@@ -27,4 +28,4 @@ def main(file: str) -> None:
2728
if __name__ == "__main__":
2829
logger = helpers.get_logger()
2930

30-
main()
31+
main()

recommendations/helpers.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
from typing import Mapping
2-
from typing import Type
3-
from typing import List
1+
from typing import Dict
42
from typing import Any
53

64
from pathlib import Path
@@ -10,13 +8,13 @@
108
import logging
119
import pandas as pd
1210

13-
from config import Config
1411

15-
def clean_data(df: pd.DataFrame):
12+
def clean_data(df: pd.DataFrame) -> pd.DataFrame:
1613
df['product_name'] = df['product_name'].str.replace(',', '')
1714

1815
return df
1916

17+
2018
def get_logger() -> logging.Logger:
2119
logger = logging.getLogger('')
2220
handler = logging.StreamHandler()
@@ -29,7 +27,7 @@ def get_logger() -> logging.Logger:
2927
return logger
3028

3129

32-
def get_configuration(config: str, configurations: Mapping[str, Type[Config]]) -> Type[Config]:
30+
def get_configuration(config: str, configurations: Dict[str, Any]) -> Any:
3331
try:
3432
configuration = configurations[config]
3533
except KeyError:

recommendations/insert_data.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import helpers
88
import schema
99

10+
1011
@click.command()
1112
@click.option('--file', default='production', help='the dataset to load to Postgres database')
1213
def main(file: str) -> None:
@@ -40,11 +41,11 @@ def main(file: str) -> None:
4041
with open(file_name, 'r') as f:
4142
next(f)
4243
cur.copy_from(f, table_name, sep=',')
43-
44+
4445
conn.commit()
4546

4647

4748
if __name__ == "__main__":
4849
logger = helpers.get_logger()
4950

50-
main()
51+
main()

recommendations/schema.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
department_id integer PRIMARY KEY,
1919
department text
2020
)
21-
"""
22-
, 'dropquery': """DROP TABLE departments"""
21+
""",
22+
'dropquery': """DROP TABLE departments"""
2323
},
2424
'order_products_prior': {
2525
'filename': 'data/order_products__prior.csv',
@@ -76,4 +76,4 @@
7676
""",
7777
'dropquery': """DROP TABLE orders"""
7878
}
79-
}
79+
}

0 commit comments

Comments
 (0)