Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic update of dependencies #2

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
name: Python checks

on: [push]
on:
push:

jobs:
styles:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8]
# strategy:
# matrix:
# python-version: [3.7, 3.8]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
- name: Checkout source code from Github
uses: actions/checkout@v3
with:
python-version: ${{ matrix.python-version }}
fetch-depth: 0
# - name: Set up Python ${{ matrix.python-version }}
# uses: actions/setup-python@v2
# with:
# python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest mypy
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install flake8 mypy
if [ -f docker/requirements.txt ]; then pip install -r docker/requirements.txt; fi

- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 ./src --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings.
flake8 ./src --count --exit-zero --max-complexity=10 --max-line-length=120 --statistics
- name: Static typing
run: |
mypy --no-warn-no-return --ignore-missing-imports ./src
run: mypy --no-warn-no-return --ignore-missing-imports ./src
- name: Test
# env:
# PYTHONPATH: "${PYTHONPATH}:/src"
run: cd src && export PYTHONPATH="${PYTHONPATH}:/src" && echo $PYTHONPATH && pytest tests
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,6 @@ dmypy.json


.idea/
src/ml_pipelines
.env
src/ml_pipelines/*
!src/ml_pipelines/.gitkeep
19 changes: 2 additions & 17 deletions docker/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
click==7.1.2
fastapi==0.61.2
flake8==3.8.4
h11==0.11.0
importlib-metadata==3.4.0
joblib==1.0.0
mccabe==0.6.1
mypy==0.800
mypy-extensions==0.4.3
numpy==1.20.1
pandas==1.2.1
psycopg2==2.9.3
pycodestyle==2.6.0
pydantic==1.7.2
pyflakes==2.2.0
python-dateutil==2.8.1
pytz==2021.1
scikit-learn==0.24.1
scipy==1.6.0
six==1.15.0
starlette==0.13.6
threadpoolctl==2.1.0
typed-ast==1.4.2
typing-extensions==3.7.4.3
uvicorn==0.12.3
zipp==3.4.0
pytest==7.1.2
pytest-asyncio==0.19.0
Empty file added src/ml_pipelines/.gitkeep
Empty file.
2 changes: 2 additions & 0 deletions src/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
addopts = -p no:warnings
2 changes: 1 addition & 1 deletion src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async def predict(item: Item, response: Response):
status_code=status.HTTP_404_NOT_FOUND)

# make prediction
df = convert_item_to_df(item)
df = await convert_item_to_df(item)
prediction = CACHE['ml_pipeline'].predict(df)[0]

# save features + prediction + pipeline version
Expand Down
33 changes: 33 additions & 0 deletions src/tests/unit_tests/test_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import pytest
import pandas as pd
from utils.helpers import convert_item_to_df
from models.item_model import Item

@pytest.mark.asyncio
async def test_convert_item_to_df():
item = Item(
CRIM=0.00632, ZN=18.0, INDUS=2.31, CHAS=0, NOX=0.538, RM=6.575, AGE=65.2,
DIS=4.09, RAD=1, TAX=296.0, PTRATIO=15.3, B=396.9, LSTAT=4.98
)

converted_item = await convert_item_to_df(item)
expected = {
'CRIM': 0.00632,
'ZN': 18.0,
'INDUS': 2.31,
'CHAS': 0,
'NOX': 0.538,
'RM': 6.575,
'AGE': 65.2,
'DIS': 4.09,
'RAD': 1,
'TAX': 296.0,
'PTRATIO': 15.3,
'B': 396.9,
'LSTAT': 4.98
}

assert type(converted_item) == pd.DataFrame

for key, val in expected.items():
assert converted_item[key][0] == val
2 changes: 1 addition & 1 deletion src/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def save_prediction(row: list) -> None:
execute_query(query, row)


def convert_item_to_df(item: Item) -> pd.DataFrame:
async def convert_item_to_df(item: Item) -> pd.DataFrame:
"""Convert Item to the pandas DataFrame"""
items = {}
for key, value in item.dict().items():
Expand Down