@@ -32,25 +32,6 @@ def spacy_model():
3232 return nlp
3333
3434
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-
5435@pytest .fixture ()
5536def vetiver_client_with_prototype (spacy_model ): # With check_prototype=True
5637 df = pd .DataFrame ({"new_column" : ["one" , "two" , "three" ]})
@@ -82,37 +63,35 @@ def vetiver_client_no_prototype(spacy_model): # With check_prototype=False
8263 return client
8364
8465
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 )
8770
88- response = vetiver .predict (endpoint = vetiver_client_with_prototype , data = df )
8971
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 )
11087
88+ assert v .prototype .construct ().dict () == {"col" : "1" }
11189
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 ):
11392 df = pd .DataFrame ({"new_column" : ["turtles" , "i have a dog" ]})
11493
115- response = vetiver .predict (endpoint = vetiver_client_with_prototype_series , data = df )
94+ response = vetiver .predict (endpoint = vetiver_client_with_prototype , data = df )
11695
11796 assert isinstance (response , pd .DataFrame ), response
11897 assert response .to_dict () == {
0 commit comments