-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: DIA-1862: Improve SDK coverage and data flow #6993
Open
robot-ci-heartex
wants to merge
12
commits into
develop
Choose a base branch
from
fb-dia-1862
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+101
−23
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0813d91
[submodules] Bump HumanSignal/label-studio-sdk version
fern-api[bot] b5432bc
[submodules] Bump HumanSignal/label-studio-sdk version
224e489
[submodules] Bump HumanSignal/label-studio-sdk version
fern-api[bot] ada722b
[submodules] Bump HumanSignal/label-studio-sdk version
1d49c6b
[submodules] Bump HumanSignal/label-studio-sdk version
d4bf43a
Add edition type in /version
431bde8
Add tests
4dff6d0
Fix tests
81462d0
Update tests
ad35640
[submodules] Bump HumanSignal/label-studio-sdk version
96d2374
[submodules] Bump HumanSignal/label-studio-sdk version
fern-api[bot] e0e1243
[submodules] Bump HumanSignal/label-studio-sdk version
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import pytest | ||
from label_studio_sdk.client import LabelStudio | ||
from label_studio_sdk.data_manager import Column, Filters, Operator, Type | ||
|
||
from .common import LABEL_CONFIG_AND_TASKS | ||
|
||
|
||
@pytest.fixture | ||
def test_project_with_view(django_live_url, business_client): | ||
ls = LabelStudio(base_url=django_live_url, api_key=business_client.api_key) | ||
p = ls.projects.create(title='New Project', label_config=LABEL_CONFIG_AND_TASKS['label_config']) | ||
|
||
project = ls.projects.get(id=p.id) | ||
|
||
task_data = [{'data': {'my_text': 'Test task ' + str(i)}} for i in range(10)] | ||
ls.projects.import_tasks(id=project.id, request=task_data) | ||
orig_tasks = [] | ||
for task in ls.tasks.list(project=project.id): | ||
orig_tasks.append(task) | ||
|
||
filters = Filters.create( | ||
Filters.OR, | ||
[Filters.item(Column.id, Operator.EQUAL, Type.Number, Filters.value(t.id)) for t in orig_tasks[::2]], | ||
) | ||
|
||
view = ls.views.create( | ||
project=project.id, data=dict(title='Test View', filters=filters, ordering=['-' + Column.id]) | ||
) | ||
return ls, project, orig_tasks, view |
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,58 @@ | ||
import pandas as pd | ||
import pytest | ||
|
||
from label_studio.tests.sdk.common import LABEL_CONFIG_AND_TASKS | ||
|
||
pytestmark = pytest.mark.django_db | ||
from label_studio_sdk.client import LabelStudio | ||
|
||
|
||
@pytest.fixture | ||
def test_project(django_live_url, business_client): | ||
ls = LabelStudio(base_url=django_live_url, api_key=business_client.api_key) | ||
project = ls.projects.create(title='Export Test Project', label_config=LABEL_CONFIG_AND_TASKS['label_config']) | ||
ls.projects.import_tasks(id=project.id, request=LABEL_CONFIG_AND_TASKS['tasks_for_import']) | ||
return ls, project | ||
|
||
|
||
def test_export_formats(test_project): | ||
ls, project = test_project | ||
|
||
# Get available export formats | ||
formats = ls.projects.exports.list_formats(project.id) | ||
assert len(formats) > 0 | ||
|
||
|
||
def test_direct_export(test_project): | ||
ls, project = test_project | ||
|
||
# Test JSON export | ||
json_data = ls.projects.exports.as_json(project.id) | ||
assert isinstance(json_data, list) | ||
assert len(json_data) == 1 | ||
|
||
# Test pandas export | ||
df = ls.projects.exports.as_pandas(project.id) | ||
assert isinstance(df, pd.DataFrame) | ||
assert len(df) == 1 | ||
|
||
# Test low level export - import new task without annotations | ||
ls.projects.import_tasks( | ||
id=project.id, | ||
request={ | ||
'data': { | ||
'my_text': 'Opossums are great', | ||
'ref_id': 456, | ||
'meta_info': {'timestamp': '2020-03-09 18:15:28.212882', 'location': 'North Pole'}, | ||
} | ||
}, | ||
) | ||
data = ls.projects.exports.download_sync(project.id, download_all_tasks=False) | ||
from label_studio_sdk.projects.exports.client_ext import _bytestream_to_json | ||
|
||
assert len(_bytestream_to_json(data)) == 1 | ||
|
||
data = ls.projects.exports.download_sync(project.id, download_all_tasks=True) | ||
from label_studio_sdk.projects.exports.client_ext import _bytestream_to_json | ||
|
||
assert len(_bytestream_to_json(data)) == 2 |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to have these as fixtures now with the current way we use pytest, but looking forward to progressively replacing them with something like Factory Boy when available (cc @mcanu )