@@ -32,25 +32,6 @@ def spacy_model():
32
32
return nlp
33
33
34
34
35
- @pytest .fixture (scope = "function" )
36
- @pytest .mark .parametrize ("data" , ["a" , 1 , [1 , 2 , 3 ]])
37
- def test_bad_prototype_data (data , spacy_model ):
38
- with pytest .raises (TypeError ):
39
- vetiver .VetiverModel (spacy_model , "animals" , prototype_data = data )
40
-
41
-
42
- @pytest .fixture (scope = "function" )
43
- @pytest .mark .parametrize (
44
- pd .DataFrame (
45
- {"col" : ["1" , "2" ], "col2" : [1 , 2 ]},
46
- pd .DataFrame ({"col" : ["1" , "2" ], "col2" : [1 , 2 ]}),
47
- )
48
- )
49
- def test_bad_prototype_shape (data , spacy_model ):
50
- with pytest .raises (ValueError ):
51
- vetiver .VetiverModel (spacy_model , "animals" , prototype_data = data )
52
-
53
-
54
35
@pytest .fixture ()
55
36
def vetiver_client_with_prototype (spacy_model ): # With check_prototype=True
56
37
df = pd .DataFrame ({"new_column" : ["one" , "two" , "three" ]})
@@ -82,37 +63,35 @@ def vetiver_client_no_prototype(spacy_model): # With check_prototype=False
82
63
return client
83
64
84
65
85
- def test_vetiver_predict_with_prototype (vetiver_client_with_prototype ):
86
- df = pd .DataFrame ({"new_column" : ["turtles" , "i have a dog" ]})
66
+ @pytest .mark .parametrize ("data" , ["a" , 1 , [1 , 2 , 3 ]])
67
+ def test_bad_prototype_data (data , spacy_model ):
68
+ with pytest .raises (TypeError ):
69
+ vetiver .VetiverModel (spacy_model , "animals" , prototype_data = data )
87
70
88
- response = vetiver .predict (endpoint = vetiver_client_with_prototype , data = df )
89
71
90
- assert isinstance (response , pd .DataFrame ), response
91
- assert response .to_dict () == {
92
- "0" : {
93
- "text" : "turtles" ,
94
- "ents" : [],
95
- "sents" : [{"start" : 0 , "end" : 7 }],
96
- "tokens" : [{"id" : 0 , "start" : 0 , "end" : 7 }],
97
- },
98
- "1" : {
99
- "text" : "i have a dog" ,
100
- "ents" : [{"start" : 9 , "end" : 12 , "label" : "ANIMAL" }],
101
- "sents" : nan ,
102
- "tokens" : [
103
- {"id" : 0 , "start" : 0 , "end" : 1 },
104
- {"id" : 1 , "start" : 2 , "end" : 6 },
105
- {"id" : 2 , "start" : 7 , "end" : 8 },
106
- {"id" : 3 , "start" : 9 , "end" : 12 },
107
- ],
108
- },
109
- }
72
+ @pytest .mark .parametrize (
73
+ "data" ,
74
+ [
75
+ {"col" : ["1" , "2" ], "col2" : [1 , 2 ]},
76
+ pd .DataFrame ({"col" : ["1" , "2" ], "col2" : [1 , 2 ]}),
77
+ ],
78
+ )
79
+ def test_bad_prototype_shape (data , spacy_model ):
80
+ with pytest .raises (ValueError ):
81
+ vetiver .VetiverModel (spacy_model , "animals" , prototype_data = data )
82
+
83
+
84
+ @pytest .mark .parametrize ("data" , [{"col" : "1" }, pd .DataFrame ({"col" : ["1" ]})])
85
+ def test_good_prototype_shape (data , spacy_model ):
86
+ v = vetiver .VetiverModel (spacy_model , "animals" , prototype_data = data )
110
87
88
+ assert v .prototype .construct ().dict () == {"col" : "1" }
111
89
112
- def test_vetiver_predict_with_prototype_series (vetiver_client_with_prototype_series ):
90
+
91
+ def test_vetiver_predict_with_prototype (vetiver_client_with_prototype ):
113
92
df = pd .DataFrame ({"new_column" : ["turtles" , "i have a dog" ]})
114
93
115
- response = vetiver .predict (endpoint = vetiver_client_with_prototype_series , data = df )
94
+ response = vetiver .predict (endpoint = vetiver_client_with_prototype , data = df )
116
95
117
96
assert isinstance (response , pd .DataFrame ), response
118
97
assert response .to_dict () == {
0 commit comments