@@ -32,7 +32,26 @@ def spacy_model():
32
32
return nlp
33
33
34
34
35
- @pytest .fixture
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
+ @pytest .fixture ()
36
55
def vetiver_client_with_prototype (spacy_model ): # With check_prototype=True
37
56
df = pd .DataFrame ({"new_column" : ["one" , "two" , "three" ]})
38
57
v = vetiver .VetiverModel (spacy_model , "animals" , prototype_data = df )
@@ -43,6 +62,16 @@ def vetiver_client_with_prototype(spacy_model): # With check_prototype=True
43
62
return client
44
63
45
64
65
+ @pytest .fixture (scope = "function" )
66
+ def vetiver_client_with_prototype_series (spacy_model ): # With check_prototype=True
67
+ df = pd .Series ({"new_column" : ["one" , "two" , "three" ]})
68
+ v = vetiver .VetiverModel (spacy_model , "animals" , prototype_data = df )
69
+ app = vetiver .VetiverAPI (v , check_prototype = True )
70
+ app .app .root_path = "/predict"
71
+ client = TestClient (app .app )
72
+ return client
73
+
74
+
46
75
@pytest .fixture
47
76
def vetiver_client_no_prototype (spacy_model ): # With check_prototype=False
48
77
v = vetiver .VetiverModel (spacy_model , "animals" )
@@ -80,6 +109,33 @@ def test_vetiver_predict_with_prototype(vetiver_client_with_prototype):
80
109
}
81
110
82
111
112
+ def test_vetiver_predict_with_prototype_series (vetiver_client_with_prototype_series ):
113
+ df = pd .DataFrame ({"new_column" : ["turtles" , "i have a dog" ]})
114
+
115
+ response = vetiver .predict (endpoint = vetiver_client_with_prototype_series , data = df )
116
+
117
+ assert isinstance (response , pd .DataFrame ), response
118
+ assert response .to_dict () == {
119
+ "0" : {
120
+ "text" : "turtles" ,
121
+ "ents" : [],
122
+ "sents" : [{"start" : 0 , "end" : 7 }],
123
+ "tokens" : [{"id" : 0 , "start" : 0 , "end" : 7 }],
124
+ },
125
+ "1" : {
126
+ "text" : "i have a dog" ,
127
+ "ents" : [{"start" : 9 , "end" : 12 , "label" : "ANIMAL" }],
128
+ "sents" : nan ,
129
+ "tokens" : [
130
+ {"id" : 0 , "start" : 0 , "end" : 1 },
131
+ {"id" : 1 , "start" : 2 , "end" : 6 },
132
+ {"id" : 2 , "start" : 7 , "end" : 8 },
133
+ {"id" : 3 , "start" : 9 , "end" : 12 },
134
+ ],
135
+ },
136
+ }
137
+
138
+
83
139
def test_vetiver_predict_no_prototype (vetiver_client_no_prototype ):
84
140
df = pd .DataFrame ({"uhhh" : ["turtles" , "i have a dog" ]})
85
141
0 commit comments