Skip to content

Commit 33ed494

Browse files
committed
removing more references to ptype
1 parent 052488a commit 33ed494

4 files changed

Lines changed: 44 additions & 20 deletions

File tree

.github/workflows/tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ jobs:
7878
python-version: 3.8
7979
- name: Install dependencies
8080
run: |
81-
python -m pip install --upgrade pip
82-
python -m pip install -e ".[dev]"
83-
- name: Run Docker
81+
python -m pip install ".[dev]"
82+
python -m pip install --upgrade git+https://github.com/rstudio/vetiver-python@${{ github.sha }}
83+
- name: run Docker
8484
run: |
8585
python script/setup-docker/docker.py
8686
docker build -t mock .

vetiver/prototype.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515

1616
class InvalidPTypeError(Exception):
1717
"""
18-
Throw an error if ptype cannot be recognised
18+
Throw an error if prototype cannot be recognised
1919
"""
2020

2121
def __init__(
2222
self,
23-
message="`ptype_data` must be a pd.DataFrame, a pydantic BaseModel or np.ndarray",
23+
message="`prototype_data` must be a pd.DataFrame, a pydantic BaseModel, dict or "
24+
"np.ndarray",
2425
):
2526
self.message = message
2627
super().__init__(self.message)
@@ -33,14 +34,14 @@ def __init__(
3334
you should write a function to create the prototype. Here is \
3435
a template for such a function: \
3536
36-
from pydantic import create_model
37-
from vetiver.prototype import vetiver_create_ptype
37+
from vetiver.prototype import vetiver_create_prototype
38+
from vetiver.types import create_prototype
3839
39-
@vetiver_create_ptype.register
40+
@vetiver_create_prototype.register
4041
def _(data: {_data_type}):
4142
data_dict = ... # convert data to a dictionary
42-
ptype = create_model("ptype", **data_dict)
43-
return ptype
43+
prototype = create_prototype(**data_dict)
44+
return prototype
4445
4546
If your datatype is a common type, please consider submitting \
4647
a pull request.
@@ -70,7 +71,7 @@ def vetiver_create_prototype(data):
7071
7172
Returns
7273
-------
73-
ptype : pydantic.main.BaseModel
74+
prototype : vetiver.Prototype
7475
Data prototype
7576
7677
"""
@@ -91,17 +92,17 @@ def _(data: pd.DataFrame):
9192
--------
9293
>>> from pydantic import BaseModel
9394
>>> df = pd.DataFrame({'x': [1, 2, 3], 'y': [4, 5, 6]})
94-
>>> prototype = vetiver_create_ptype(df)
95+
>>> prototype = vetiver_create_prototype(df)
9596
>>> issubclass(prototype, BaseModel)
9697
True
9798
>>> prototype()
98-
ptype(x=1, y=4)
99+
prototype(x=1, y=4)
99100
100101
The data prototype created for the dataframe is equivalent to:
101102
102103
>>> class another_prototype(BaseModel):
103104
... class Config:
104-
... title = 'ptype'
105+
... title = 'prototype'
105106
... x: int = 1
106107
... y: int = 4
107108
@@ -134,14 +135,14 @@ def _(data: np.ndarray):
134135
Examples
135136
--------
136137
>>> arr = np.array([[1, 4], [2, 5], [3, 6]])
137-
>>> prototype = vetiver_create_ptype(arr)
138+
>>> prototype = vetiver_create_prototype(arr)
138139
>>> prototype()
139-
ptype(0=1, 1=4)
140+
prototype(0=1, 1=4)
140141
141142
>>> arr2 = np.array([[1, 'a'], [2, 'b'], [3, 'c']], dtype=object)
142-
>>> prototype2 = vetiver_create_ptype(arr2)
143+
>>> prototype2 = vetiver_create_prototype(arr2)
143144
>>> prototype2()
144-
ptype(0=1, 1='a')
145+
prototype(0=1, 1='a')
145146
"""
146147

147148
def _item(value):

vetiver/tests/test_build_vetiver_model.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
model = get_mock_model().fit(X_df, y)
1414

1515

16+
class MockPrototype(pydantic.BaseModel):
17+
B: int
18+
C: int
19+
D: int
20+
21+
1622
def test_vetiver_model_array_prototype():
1723
vt1 = vt.VetiverModel(
1824
model=model,
@@ -24,6 +30,7 @@ def test_vetiver_model_array_prototype():
2430
)
2531

2632
assert vt1.model == model
33+
assert issubclass(vt1.prototype, vt.Prototype)
2734
assert isinstance(vt1.prototype.construct(), pydantic.BaseModel)
2835
assert list(vt1.prototype.__fields__.values())[0].type_ == int
2936

@@ -59,6 +66,22 @@ def test_vetiver_model_dict_prototype():
5966
assert list(vt3.prototype.__fields__.values())[0].type_ == int
6067

6168

69+
def test_vetiver_model_basemodel_prototype():
70+
71+
m = MockPrototype(B=4, C=0, D=0)
72+
vt4 = vt.VetiverModel(
73+
model=model,
74+
prototype_data=m,
75+
model_name="model",
76+
versioned=None,
77+
description=None,
78+
metadata=None,
79+
)
80+
81+
assert vt4.model == model
82+
assert vt4.prototype is m
83+
84+
6285
def test_vetiver_model_no_prototype():
6386
vt4 = vt.VetiverModel(
6487
model=model,

vetiver/vetiver_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ class VetiverModel:
4141
4242
Attributes
4343
----------
44-
prototype : pydantic.main.BaseModel
44+
prototype : vetiver.Prototype
4545
Data prototype
46-
handler_predict:
46+
handler_predict: Callable
4747
Method to make predictions from a trained model
4848
4949
Notes

0 commit comments

Comments
 (0)