Skip to content

Commit

Permalink
Improve error msg for empty data (#1178)
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw authored Nov 6, 2024
1 parent f23a832 commit 070d433
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
13 changes: 11 additions & 2 deletions python/langsmith/evaluation/_arunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,18 @@ async def aget_evaluation_results(self) -> AsyncIterator[EvaluationResults]:
yield result

async def astart(self) -> _AsyncExperimentManager:
first_example = await aitertools.py_anext(await self.aget_examples())
try:
first_example = await aitertools.py_anext(await self.aget_examples())
except StopAsyncIteration:
raise ValueError(
"No examples found in the dataset. "
"Please ensure the data provided to aevaluate is not empty."
)
if not first_example:
raise ValueError("No examples found in the dataset.")
raise ValueError(
"No examples found in the dataset."
"Please ensure the data provided to aevaluate is not empty."
)
project = self._get_project(first_example)
self._print_experiment_start(project, first_example)
self._metadata["num_repetitions"] = self._num_repetitions
Expand Down
28 changes: 28 additions & 0 deletions python/tests/evaluation/test_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,3 +456,31 @@ def test_pytest_skip():
@test
async def test_async_pytest_skip():
pytest.skip("Skip this test")


async def test_aevaluate_good_error():
client = Client()
ds_name = "__Empty Dataset Do Not Modify"
if not client.has_dataset(dataset_name=ds_name):
client.create_dataset(dataset_name=ds_name)

async def predict(inputs: dict):
return {}

match_val = "No examples found in the dataset."
with pytest.raises(ValueError, match=match_val):
await aevaluate(
predict,
data=ds_name,
)

with pytest.raises(ValueError, match=match_val):
await aevaluate(
predict,
data=[],
)
with pytest.raises(ValueError, match=match_val):
await aevaluate(
predict,
data=(_ for _ in range(0)),
)

0 comments on commit 070d433

Please sign in to comment.