Skip to content

Commit 19c670f

Browse files
authored
[AL-5662] Add batch export v2 (#1116)
1 parent bfabd85 commit 19c670f

File tree

5 files changed

+56
-2
lines changed

5 files changed

+56
-2
lines changed

labelbox/schema/batch.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import Generator, TYPE_CHECKING
2+
23
from labelbox.orm.db_object import DbObject, experimental
34
from labelbox.orm import query
45
from labelbox.orm.model import Entity, Field, Relationship

labelbox/schema/export_filters.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ class SharedExportFilters(TypedDict):
3737

3838

3939
class ProjectExportFilters(SharedExportFilters):
40-
pass
40+
batch_id: Optional[str]
41+
""" Batch id to export
42+
Example:
43+
>>> "clgo3lyax0000veeezdbu3ws4"
44+
"""
4145

4246

4347
class DatasetExportFilters(SharedExportFilters):
@@ -178,4 +182,12 @@ def _get_timezone() -> str:
178182
"operator": "is",
179183
"type": "data_row_id"
180184
})
185+
186+
batch_id = filters.get("batch_id")
187+
if batch_id:
188+
search_query.append({
189+
"ids": [batch_id],
190+
"operator": "is",
191+
"type": "batch"
192+
})
181193
return search_query

labelbox/schema/project.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ def export_v2(self,
442442
"last_activity_at": None,
443443
"label_created_at": None,
444444
"data_row_ids": None,
445+
"batch_id": None,
445446
})
446447

447448
mutation_name = "exportDataRowsInProject"

tests/integration/test_batch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,4 @@ def test_delete_labels_with_templates(batch_project: Project,
204204
exported_data_rows = list(batch.export_data_rows())
205205
res = batch.delete_labels(labels_as_template=True)
206206
exported_data_rows = list(batch.export_data_rows())
207-
assert len(exported_data_rows) == 5
207+
assert len(exported_data_rows) == 5

tests/integration/test_project.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import time
22
import os
3+
from typing import Tuple
34
import uuid
45

56
import pytest
67
import requests
78

89
from labelbox import Project, LabelingFrontend, Dataset
910
from labelbox.exceptions import InvalidQueryError
11+
from labelbox.schema.data_row import DataRow
12+
from labelbox.schema.label import Label
1013
from labelbox.schema.media_type import MediaType
1114
from labelbox.schema.queue_mode import QueueMode
1215

@@ -42,6 +45,43 @@ def test_project(client, rand_gen):
4245
assert project not in projects
4346

4447

48+
def test_batch_project_export_v2(
49+
configured_batch_project_with_label: Tuple[Project, Dataset, DataRow,
50+
Label],
51+
export_v2_test_helpers, dataset: Dataset, image_url: str):
52+
project, dataset, *_ = configured_batch_project_with_label
53+
54+
batch = list(project.batches())[0]
55+
filters = {
56+
"last_activity_at": ["2000-01-01 00:00:00", "2050-01-01 00:00:00"],
57+
"label_created_at": ["2000-01-01 00:00:00", "2050-01-01 00:00:00"],
58+
"batch_id": batch.uid,
59+
}
60+
params = {
61+
"include_performance_details": True,
62+
"include_labels": True,
63+
"media_type_override": MediaType.Image
64+
}
65+
task_name = "test_batch_export_v2"
66+
task = dataset.create_data_rows([
67+
{
68+
"row_data": image_url,
69+
"external_id": "my-image"
70+
},
71+
] * 2)
72+
task.wait_till_done()
73+
data_rows = [dr.uid for dr in list(dataset.export_data_rows())]
74+
batch_one = f'batch one {uuid.uuid4()}'
75+
76+
# This test creates two batches, only one batch should be exporter
77+
# Creatin second batch that will not be used in the export due to the filter: batch_id
78+
project.create_batch(batch_one, data_rows)
79+
80+
task_results = export_v2_test_helpers.run_project_export_v2_task(
81+
project, task_name=task_name, filters=filters, params=params)
82+
assert (batch.size == len(task_results))
83+
84+
4585
def test_project_export_v2(client, export_v2_test_helpers,
4686
configured_project_with_label,
4787
wait_for_data_row_processing):

0 commit comments

Comments
 (0)