-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from jlowin/df
Add support for pandas results
- Loading branch information
Showing
8 changed files
with
150 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import pandas as pd | ||
import pytest | ||
from controlflow import Task | ||
from pydantic import BaseModel | ||
|
||
|
||
class Name(BaseModel): | ||
first: str | ||
last: str | ||
|
||
|
||
@pytest.mark.usefixtures("unit_test_instructions") | ||
class TestTaskResults: | ||
def test_task_int_result(self): | ||
task = Task("return 3", result_type=int) | ||
assert task.run() == 3 | ||
|
||
def test_task_pydantic_result(self): | ||
task = Task("the name is John Doe", result_type=Name) | ||
result = task.run() | ||
assert isinstance(result, Name) | ||
assert result == Name(first="John", last="Doe") | ||
|
||
def test_task_dataframe_result(self): | ||
task = Task( | ||
'return a dataframe with column "x" that has values 1 and 2 and column "y" that has values 3 and 4', | ||
result_type=pd.DataFrame, | ||
) | ||
result = task.run() | ||
assert isinstance(result, pd.DataFrame) | ||
assert result == pd.DataFrame(data={"x": [1, 2], "y": [3, 4]}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import pytest | ||
from controlflow import instructions | ||
|
||
|
||
@pytest.fixture | ||
def unit_test_instructions(): | ||
with instructions( | ||
"You are being unit tested. Be as fast and concise as possible. Do not post unecessary messages." | ||
): | ||
yield |
Empty file.