Skip to content

Commit 91c9856

Browse files
authored
Merge pull request #92 from rstudio/cleaning
Cleaning
2 parents 9772ec1 + f47ed5b commit 91c9856

16 files changed

+70
-36
lines changed

.github/workflows/precommit.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Code Checks
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: ['main']
7+
pull_request:
8+
release:
9+
types: [published]
10+
11+
jobs:
12+
pre-commit:
13+
name: "Run pre-commit"
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
- uses: actions/setup-python@v2
18+
- uses: pre-commit/action@v2.0.3

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22

3-
exclude: "(.*\\.csv)|(^pins/tests/_snapshots)"
3+
exclude: "(.*\\.csv)|(^examples/)|(^vetiver/tests/snapshots/)"
44
repos:
55
- repo: https://github.com/pre-commit/pre-commit-hooks
66
rev: v2.4.0

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ help:
2020
@echo "clean-test - remove test and coverage artifacts"
2121
@echo "lint - check style with flake8"
2222
@echo "test - run tests quickly with the default Python"
23+
@echo "test-rsc - run tests for rsconnect"
2324
@echo "coverage - check code coverage quickly with the default Python"
2425
@echo "docs - generate Sphinx HTML documentation, including API docs"
2526
@echo "cdocs - cleanout previous build & generate Sphinx HTML documentation, including API docs"
@@ -54,6 +55,9 @@ lint:
5455
flake8 vetiver
5556

5657
test: clean-test
58+
pytest -m 'not rsc_test'
59+
60+
test-rsc: clean-test
5761
pytest
5862

5963
coverage:

examples/coffeeratings.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,32 @@
66
from pathlib import Path
77

88
# Load training data
9-
raw = pd.read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-07-07/coffee_ratings.csv')
9+
raw = pd.read_csv(
10+
"https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-07-07/coffee_ratings.csv"
11+
)
1012
df = pd.DataFrame(raw)
11-
coffee = df[["total_cup_points", "aroma", "flavor", "sweetness", "acidity", \
12-
"body", "uniformity", "balance"]].dropna()
13-
14-
X_train, X_test, y_train, y_test = model_selection.train_test_split(coffee.iloc[:,1:],coffee['total_cup_points'],test_size=0.2)
13+
coffee = df[
14+
[
15+
"total_cup_points",
16+
"aroma",
17+
"flavor",
18+
"sweetness",
19+
"acidity",
20+
"body",
21+
"uniformity",
22+
"balance",
23+
]
24+
].dropna()
25+
26+
X_train, X_test, y_train, y_test = model_selection.train_test_split(
27+
coffee.iloc[:, 1:], coffee["total_cup_points"], test_size=0.2
28+
)
1529

1630
# fit model
1731
lr_fit = LinearRegression().fit(X_train, y_train)
1832

1933
# create vetiver model
20-
v = vetiver.VetiverModel(lr_fit, ptype_data=X_train, model_name = "v")
34+
v = vetiver.VetiverModel(lr_fit, ptype_data=X_train, model_name="v")
2135

2236
# version model via pin
2337
from pins import board_folder
@@ -27,12 +41,12 @@
2741
model_board = board_folder(path=path, versioned=True, allow_pickle_read=True)
2842
vetiver_pin_write(board=model_board, model=v)
2943

30-
myapp = vetiver.VetiverAPI(v, check_ptype = True)
44+
myapp = vetiver.VetiverAPI(v, check_ptype=True)
3145
api = myapp.app
3246

3347
# next, run myapp.run() to start API and see visual documentation
3448
# create app.py file that includes pinned VetiverAPI to be deployed
35-
vetiver.vetiver_write_app(model_board, "v", file = path+"app.py")
49+
vetiver.vetiver_write_app(model_board, "v", file=path + "app.py")
3650

3751
# automatically create requirements.txt
3852
vetiver.load_pkgs(model=v, path=path)

examples/coffeeratings/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import pins
33

44
# edited to reflect Docker container path, and allow_pickle_read=True
5-
b = pins.board_folder('/code/app', allow_pickle_read=True)
6-
v = vetiver.vetiver_pin_read(b, 'v', version = '20220415T174503Z-06d9b')
5+
b = pins.board_folder("/code/app", allow_pickle_read=True)
6+
v = vetiver.vetiver_pin_read(b, "v", version="20220415T174503Z-06d9b")
77

88
vetiver_api = vetiver.VetiverAPI(v)
99
api = vetiver_api.app

examples/coffeeratings/vetiver_requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,4 @@ uvicorn==0.17.6
7272
# via vetiver
7373

7474
# manually edited to reflect appropriate versions of packages currently being developed
75-
git+https://github.com/isabelizimm/vetiver-python.git@37dff15a63238b1e6c44788af70473f19c29d83e
75+
git+https://github.com/isabelizimm/vetiver-python.git@37dff15a63238b1e6c44788af70473f19c29d83e

vetiver/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
from .handlers.base import BaseHandler, create_handler, InvalidModelError # noqa
1515
from .handlers.sklearn import SKLearnHandler # noqa
1616
from .handlers.torch import TorchHandler # noqa
17-
from .rsconnect import deploy_rsconnect # noqa
18-
from .monitor import compute_metrics, pin_metrics, plot_metrics, _rolling_df # noqa
17+
from .rsconnect import deploy_rsconnect # noqa
18+
from .monitor import compute_metrics, pin_metrics, plot_metrics, _rolling_df # noqa
1919

2020
__author__ = "Isabel Zimmerman <isabel.zimmerman@rstudio.com>"
2121
__all__ = []

vetiver/data/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def __dir__():
1212

1313
def __getattr__(k):
1414
import pandas as pd
15+
1516
f_path = sources.get("mtcars")
1617
if k == "chicago":
1718
f_path = sources.get("chicago")

vetiver/pin_read_write.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,14 @@ def vetiver_pin_read(board, name: str, version: str = None) -> VetiverModel:
6161
6262
Notes
6363
-----
64-
If reading a board from RSConnect, the `board` argument must be in "username/modelname" format.
64+
If reading a board from RSConnect, the `board` argument must be in
65+
"username/modelname" format.
6566
6667
"""
6768

6869
warnings.warn(
69-
"vetiver_pin_read will be removed in v1.0.0. Use classmethod VetiverModel.from_pin() instead",
70+
"vetiver_pin_read will be removed in v1.0.0. Use classmethod "
71+
"VetiverModel.from_pin() instead",
7072
DeprecationWarning,
7173
)
7274

vetiver/ptype.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class NoAvailablePTypeError(Exception):
1919

2020
def __init__(
2121
self,
22-
message="There is no method available to create a 0-row input data prototype for `model`",
22+
message="There is no method to create a 0-row input data prototype for `model`",
2323
):
2424
self.message = message
2525
super().__init__(self.message)

0 commit comments

Comments
 (0)