Skip to content

Commit

Permalink
Fix typo (#631)
Browse files Browse the repository at this point in the history
* Fix typo

* Deprecate function with typo, add new

---------

Co-authored-by: Kristian Aune <kraune@verizonmedia.com>
  • Loading branch information
kkraune and Kristian Aune committed Nov 16, 2023
1 parent dd409f5 commit 557c2af
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@
"from vespa.io import VespaResponse \n",
"\n",
"def callback(response:VespaResponse, id:str):\n",
" if not response.is_successfull():\n",
" if not response.is_successful():\n",
" print(f\"Document {id} was not fed to Vespa due to error: {response.get_json()}\")\n",
" \n",
"app.feed_iterable(feed_batch, callback=callback)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@
"from vespa.io import VespaResponse \n",
"\n",
"def callback(response:VespaResponse, id:str):\n",
" if not response.is_successfull():\n",
" if not response.is_successful():\n",
" print(f\"Document {id} was not fed to Vespa due to error: {response.get_json()}\")\n",
" \n",
"app.feed_iterable(feed_batch, callback=callback)"
Expand Down
2 changes: 1 addition & 1 deletion docs/sphinx/source/examples/multi-vector-indexing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@
" 'ranking.profile': 'unranked',\n",
" 'hits': 2\n",
"})\n",
"if not result.is_successfull():\n",
"if not result.is_successful():\n",
" raise ValueError(result.get_json())\n",
"if len(result.hits) != 2:\n",
" raise ValueError(\"Expected 2 hits, got {}\".format(len(result.hits)))\n",
Expand Down
6 changes: 3 additions & 3 deletions docs/sphinx/source/examples/pyvespa-examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
"with app.syncio(connections=1) as session:\n",
" for u in get_feed(\"point\"):\n",
" response:VespaResponse = session.update_data(data_id=u[\"id\"], schema=\"neighbors\", fields=u[\"fields\"], create=True)\n",
" if not response.is_successfull():\n",
" if not response.is_successful():\n",
" print(\"Update failed for document {}\".format(u[\"id\"]) + \" with status code {}\".format(response.status_code) + \n",
" \" with response {}\".format(response.get_json()))\n",
" "
Expand Down Expand Up @@ -235,7 +235,7 @@
" 'presentation.format.tensors': 'short-value'\n",
"})\n",
"\n",
"if not response.is_successfull():\n",
"if not response.is_successful():\n",
" print(\"Query failed with status code {}\".format(response.status_code) + \n",
" \" with response {}\".format(response.get_json()))\n",
" raise Exception(\"Query failed\")\n",
Expand Down Expand Up @@ -503,7 +503,7 @@
"source": [
"for u in get_feed(\"point_angular\"):\n",
" response:VespaResponse = session.update_data(data_id=u[\"id\"], schema=\"neighbors\", fields=u[\"fields\"])\n",
" if not response.is_successfull():\n",
" if not response.is_successful():\n",
" print(\"Update failed for document {}\".format(u[\"id\"]) + \" with status code {}\".format(response.status_code) + \n",
" \" with response {}\".format(response.get_json()))"
]
Expand Down
12 changes: 6 additions & 6 deletions docs/sphinx/source/getting-started-pyvespa-cloud.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@
"from vespa.io import VespaResponse, VespaQueryResponse\n",
"\n",
"def callback(response:VespaResponse, id:str):\n",
" if not response.is_successfull():\n",
" if not response.is_successful():\n",
" print(f\"Error when feeding document {id}: {response.get_json()}\")\n",
"\n",
"app.feed_iterable(vespa_feed, schema=\"doc\", namespace=\"tutorial\", callback=callback)"
Expand Down Expand Up @@ -496,7 +496,7 @@
" query=query, \n",
" ranking=\"bm25\"\n",
" )\n",
" assert(response.is_successfull())\n",
" assert(response.is_successful())\n",
" print(display_hits_as_df(response, [\"id\", \"title\"]))"
]
},
Expand Down Expand Up @@ -528,7 +528,7 @@
" \"input.query(q)\": f\"embed({query})\"\n",
" }\n",
" )\n",
" assert(response.is_successfull())\n",
" assert(response.is_successful())\n",
" print(display_hits_as_df(response, [\"id\", \"title\"]))"
]
},
Expand Down Expand Up @@ -566,7 +566,7 @@
" \"input.query(q)\": f\"embed({query})\"\n",
" }\n",
" )\n",
" assert(response.is_successfull())\n",
" assert(response.is_successful())\n",
" print(display_hits_as_df(response, [\"id\", \"title\"]))"
]
},
Expand Down Expand Up @@ -599,7 +599,7 @@
" \"input.query(q)\": f\"embed({query})\"\n",
" }\n",
" )\n",
" assert(response.is_successfull())\n",
" assert(response.is_successful())\n",
" print(display_hits_as_df(response, [\"id\", \"title\"]))"
]
},
Expand Down Expand Up @@ -630,7 +630,7 @@
" \"input.query(q)\": f\"embed({query})\"\n",
" }\n",
" )\n",
" assert(response.is_successfull())\n",
" assert(response.is_successful())\n",
" print(display_hits_as_df(response, [\"id\", \"title\"]))"
]
},
Expand Down
12 changes: 6 additions & 6 deletions docs/sphinx/source/getting-started-pyvespa.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
"from vespa.io import VespaResponse, VespaQueryResponse\n",
"\n",
"def callback(response:VespaResponse, id:str):\n",
" if not response.is_successfull():\n",
" if not response.is_successful():\n",
" print(f\"Error when feeding document {id}: {response.get_json()}\")\n",
"\n",
"app.feed_iterable(vespa_feed, schema=\"doc\", namespace=\"tutorial\", callback=callback)"
Expand Down Expand Up @@ -283,7 +283,7 @@
" query=query, \n",
" ranking=\"bm25\"\n",
" )\n",
" assert(response.is_successfull())\n",
" assert(response.is_successful())\n",
" print(display_hits_as_df(response, [\"id\", \"title\"]))"
]
},
Expand Down Expand Up @@ -315,7 +315,7 @@
" \"input.query(q)\": f\"embed({query})\"\n",
" }\n",
" )\n",
" assert(response.is_successfull())\n",
" assert(response.is_successful())\n",
" print(display_hits_as_df(response, [\"id\", \"title\"]))"
]
},
Expand Down Expand Up @@ -354,7 +354,7 @@
" \"input.query(q)\": f\"embed({query})\"\n",
" }\n",
" )\n",
" assert(response.is_successfull())\n",
" assert(response.is_successful())\n",
" print(display_hits_as_df(response, [\"id\", \"title\"]))"
]
},
Expand Down Expand Up @@ -393,7 +393,7 @@
" \"input.query(q)\": f\"embed({query})\"\n",
" }\n",
" )\n",
" assert(response.is_successfull())\n",
" assert(response.is_successful())\n",
" print(display_hits_as_df(response, [\"id\", \"title\"]))"
]
},
Expand Down Expand Up @@ -424,7 +424,7 @@
" \"input.query(q)\": f\"embed({query})\"\n",
" }\n",
" )\n",
" assert(response.is_successfull())\n",
" assert(response.is_successful())\n",
" print(display_hits_as_df(response, [\"id\", \"title\"]))"
]
},
Expand Down
10 changes: 5 additions & 5 deletions docs/sphinx/source/query.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
" hits=1, \n",
" query=\"Is remdesivir an effective treatment for COVID-19?\", \n",
" ranking=\"bm25\")\n",
" print(response.is_successfull())\n",
" print(response.is_successful())\n",
" print(response.url)\n"
]
},
Expand Down Expand Up @@ -115,7 +115,7 @@
" \"presentation.timing\": True\n",
" }\n",
" )\n",
" print(response.is_successfull())\n"
" print(response.is_successful())\n"
]
},
{
Expand Down Expand Up @@ -200,7 +200,7 @@
" \"presentation.timing\": True\n",
" }\n",
" )\n",
" print(response.is_successfull())"
" print(response.is_successful())"
]
},
{
Expand Down Expand Up @@ -231,7 +231,7 @@
" \"timeout\": \"1ms\"\n",
" }\n",
" )\n",
" print(response.is_successfull())\n",
" print(response.is_successful())\n",
" except VespaError as e:\n",
" print(str(e))\n",
" \n",
Expand All @@ -258,7 +258,7 @@
" \"yql\": \"select * from sources * where userQuery()\"\n",
" }\n",
" )\n",
" print(response.is_successfull())\n",
" print(response.is_successful())\n",
" except VespaError as e:\n",
" print(str(e))\n",
" "
Expand Down
10 changes: 5 additions & 5 deletions docs/sphinx/source/reads-writes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
"from vespa.io import VespaResponse\n",
"\n",
"def callback(response:VespaResponse, id:str):\n",
" if not response.is_successfull():\n",
" if not response.is_successful():\n",
" print(f\"Failed to feed document {id} with status code {response.status_code}: Reason {response.get_json()}\")\n",
" "
]
Expand Down Expand Up @@ -499,7 +499,7 @@
" \"popularity\": 1.0,\n",
" }\n",
" )\n",
" print(response.is_successfull())\n",
" print(response.is_successful())\n",
" print(response.get_json())"
]
},
Expand All @@ -524,7 +524,7 @@
" namespace=\"benchmark\",\n",
" data_id=\"1\",\n",
" )\n",
" print(response.is_successfull())\n",
" print(response.is_successful())\n",
" print(response.get_json())"
]
},
Expand Down Expand Up @@ -554,7 +554,7 @@
" fields={ \"popularity\": 3.0 }, \n",
" create=True\n",
" )\n",
" print(response.is_successfull())\n",
" print(response.is_successful())\n",
" print(response.get_json())"
]
},
Expand All @@ -571,7 +571,7 @@
" namespace=\"benchmark\",\n",
" data_id=\"does-not-exist\",\n",
" )\n",
" print(response.is_successfull())\n",
" print(response.is_successful())\n",
" print(response.get_json())"
]
},
Expand Down
7 changes: 7 additions & 0 deletions vespa/io.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from typing import Optional, Dict, List

class VespaResponse(object):
Expand Down Expand Up @@ -25,6 +26,12 @@ def get_status_code(self) -> int:
return self.status_code

def is_successfull(self) -> bool:
"""[Deprecated] Use is_successful() instead"""
warnings.warn("is_successfull is deprecated, use is_successful() instead.",
DeprecationWarning)
return self.status_code == 200

def is_successful(self) -> bool:
"""True if status code is 200."""
return self.status_code == 200

Expand Down
20 changes: 10 additions & 10 deletions vespa/test_integration_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def execute_data_operations(

response:VespaResponse = app.get_data(schema=schema_name, data_id=fields_to_send["id"])
self.assertEqual(response.status_code, 404)
self.assertFalse(response.is_successfull())
self.assertFalse(response.is_successful())

#
# Feed a data point
Expand Down Expand Up @@ -355,7 +355,7 @@ def execute_data_operations(
#
# Deleted data should be gone
response: VespaResponse = app.get_data(schema=schema_name, data_id=fields_to_send["id"])
self.assertFalse(response.is_successfull())
self.assertFalse(response.is_successful())

#
# Update a non-existent data point
Expand Down Expand Up @@ -411,7 +411,7 @@ def execute_data_operations(
response.json["id"],
"id:{}:{}::{}".format(schema_name, schema_name, fields_to_send["id"]),
)
self.assertTrue(response.is_successfull())
self.assertTrue(response.is_successful())
self.assertTrue("trace" in response.json)

async def execute_async_data_operations(
Expand Down Expand Up @@ -484,7 +484,7 @@ async def execute_async_data_operations(
schema=schema_name, data_id=fields_to_send[0]["id"], timeout=180
)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.is_successfull(), True)
self.assertEqual(response.is_successful(), True)
result = response.json
self.assertDictEqual(
result,
Expand Down Expand Up @@ -583,7 +583,7 @@ async def execute_async_data_operations(
)
for query in queries:
self.assertEqual(query.result().status_code, 200)
self.assertEqual(query.result().is_successfull(), True)
self.assertEqual(query.result().is_successful(), True)


def get_model_endpoints_when_no_model_is_available(
Expand Down Expand Up @@ -870,17 +870,17 @@ def test_streaming(self):
self.app.wait_for_application_up(300)

def callback(response:VespaResponse, id:str):
if not response.is_successfull():
if not response.is_successful():
print("Id " + id + " + failed : " + response.json)

self.app.feed_iterable(docs, schema="mail", namespace="test", callback=callback)
from vespa.io import VespaQueryResponse
response:VespaQueryResponse = self.app.query(yql="select * from sources * where title contains 'title'", groupname="a@hotmail.com")
self.assertTrue(response.is_successfull())
self.assertTrue(response.is_successful())
self.assertEqual(response.number_documents_retrieved, 1)

response:VespaQueryResponse = self.app.query(yql="select * from sources * where title contains 'title'", groupname="b@hotmail.com")
self.assertTrue(response.is_successfull())
self.assertTrue(response.is_successful())
self.assertEqual(response.number_documents_retrieved, 2)

with pytest.raises(Exception):
Expand All @@ -889,12 +889,12 @@ def callback(response:VespaResponse, id:str):
self.app.delete_data(schema="mail", namespace="test", data_id=2, groupname="b@hotmail.com")

response:VespaQueryResponse = self.app.query(yql="select * from sources * where title contains 'title'", groupname="b@hotmail.com")
self.assertTrue(response.is_successfull())
self.assertTrue(response.is_successful())
self.assertEqual(response.number_documents_retrieved, 1)

self.app.update_data(schema="mail", namespace="test", data_id=1, groupname="b@hotmail.com", fields={"title": "this is a new foo"})
response:VespaQueryResponse = self.app.query(yql="select * from sources * where title contains 'foo'", groupname="b@hotmail.com")
self.assertTrue(response.is_successfull())
self.assertTrue(response.is_successful())
self.assertEqual(response.number_documents_retrieved, 1)

response = self.app.get_data(schema="mail", namespace="test", data_id=1, groupname="b@hotmail.com")
Expand Down
2 changes: 1 addition & 1 deletion vespa/test_integration_vespa_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_key_cert_arguments(self):
},
self.app.get_data(schema="msmarco", data_id="1").json,
)
self.assertEqual(self.app.get_data(schema="msmarco", data_id="1").is_successfull(), False)
self.assertEqual(self.app.get_data(schema="msmarco", data_id="1").is_successful(), False)
with pytest.raises(HTTPError):
self.app.get_data(schema="msmarco", data_id="1", raise_on_not_found=True)

Expand Down
2 changes: 1 addition & 1 deletion vespa/test_integration_vespa_cloud_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_right_endpoint_used_with_token(self):
},
self.app.get_data(schema="msmarco", data_id="1").json,
)
self.assertEqual(self.app.get_data(schema="msmarco", data_id="1").is_successfull(), False)
self.assertEqual(self.app.get_data(schema="msmarco", data_id="1").is_successful(), False)
with pytest.raises(HTTPError):
self.app.get_data(schema="msmarco", data_id="1",raise_on_not_found=True)

Expand Down
2 changes: 1 addition & 1 deletion vespa/test_integration_vespa_cloud_vector_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def callback(response:VespaResponse, id:str):
nonlocal ok
nonlocal start_time
nonlocal callbacks
if response.is_successfull():
if response.is_successful():
ok +=1
callbacks +=1

Expand Down

0 comments on commit 557c2af

Please sign in to comment.