Skip to content

Commit 230341e

Browse files
[QQC-2590] Create method in SDK to modify LPO priorities in bulk (#1253)
1 parent 63c54f5 commit 230341e

File tree

3 files changed

+99
-20
lines changed

3 files changed

+99
-20
lines changed

labelbox/schema/project.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,60 @@ def set_labeling_parameter_overrides(self, data) -> bool:
11661166
res = self.client.execute(query_str, {id_param: self.uid})
11671167
return res["project"]["setLabelingParameterOverrides"]["success"]
11681168

1169+
def update_data_row_labeling_priority(
1170+
self,
1171+
data_rows: List[str],
1172+
priority: int,
1173+
) -> bool:
1174+
"""
1175+
Updates labeling parameter overrides to this project in bulk. This method allows up to 1 million data rows to be
1176+
updated at once.
1177+
1178+
See information on priority here:
1179+
https://docs.labelbox.com/en/configure-editor/queue-system#reservation-system
1180+
1181+
Args:
1182+
data_rows (iterable): An iterable of data row ids.
1183+
priority (int): Priority for the new override. See above for more information.
1184+
1185+
Returns:
1186+
bool, indicates if the operation was a success.
1187+
"""
1188+
1189+
method = "createQueuePriorityUpdateTask"
1190+
priority_param = "priority"
1191+
project_param = "projectId"
1192+
data_rows_param = "dataRowIds"
1193+
query_str = """mutation %sPyApi(
1194+
$%s: Int!
1195+
$%s: ID!
1196+
$%s: [ID!]
1197+
) {
1198+
project(where: { id: $%s }) {
1199+
%s(
1200+
data: { priority: $%s, dataRowIds: $%s }
1201+
) {
1202+
taskId
1203+
}
1204+
}
1205+
}
1206+
""" % (method, priority_param, project_param, data_rows_param,
1207+
project_param, method, priority_param, data_rows_param)
1208+
res = self.client.execute(
1209+
query_str, {
1210+
priority_param: priority,
1211+
project_param: self.uid,
1212+
data_rows_param: data_rows
1213+
})["project"][method]
1214+
1215+
task_id = res['taskId']
1216+
1217+
task = self._wait_for_task(task_id)
1218+
if task.status != "COMPLETE":
1219+
raise LabelboxError(f"Priority was not updated successfully: " +
1220+
json.dumps(task.errors))
1221+
return True
1222+
11691223
def upsert_review_queue(self, quota_factor) -> None:
11701224
""" Sets the the proportion of total assets in a project to review.
11711225

tests/integration/conftest.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import pytest
1212
import requests
1313

14-
from labelbox import Dataset
14+
from labelbox import Dataset, DataRow
1515
from labelbox import LabelingFrontend
1616
from labelbox import OntologyBuilder, Tool, Option, Classification, MediaType
1717
from labelbox.orm import query
@@ -167,6 +167,29 @@ def consensus_project(client, rand_gen):
167167
project.delete()
168168

169169

170+
@pytest.fixture
171+
def consensus_project_with_batch(consensus_project, initial_dataset, rand_gen,
172+
image_url):
173+
project = consensus_project
174+
dataset = initial_dataset
175+
176+
task = dataset.create_data_rows([{DataRow.row_data: image_url}] * 3)
177+
task.wait_till_done()
178+
assert task.status == "COMPLETE"
179+
180+
data_rows = list(dataset.data_rows())
181+
assert len(data_rows) == 3
182+
183+
batch = project.create_batch(
184+
rand_gen(str),
185+
data_rows, # sample of data row objects
186+
5 # priority between 1(Highest) - 5(lowest)
187+
)
188+
189+
yield [project, batch, data_rows]
190+
batch.delete()
191+
192+
170193
@pytest.fixture
171194
def dataset(client, rand_gen):
172195
dataset = client.create_dataset(name=rand_gen(str))

tests/integration/test_labeling_parameter_overrides.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,8 @@
22
from labelbox import DataRow
33

44

5-
def test_labeling_parameter_overrides(consensus_project, initial_dataset,
6-
rand_gen, image_url):
7-
project = consensus_project
8-
dataset = initial_dataset
9-
10-
task = dataset.create_data_rows([{DataRow.row_data: image_url}] * 3)
11-
task.wait_till_done()
12-
assert task.status == "COMPLETE"
13-
14-
data_rows = list(dataset.data_rows())
15-
assert len(data_rows) == 3
16-
17-
project.create_batch(
18-
rand_gen(str),
19-
data_rows, # sample of data row objects
20-
5 # priority between 1(Highest) - 5(lowest)
21-
)
5+
def test_labeling_parameter_overrides(consensus_project_with_batch):
6+
[project, _, data_rows] = consensus_project_with_batch
227

238
init_labeling_parameter_overrides = list(
249
project.labeling_parameter_overrides())
@@ -45,10 +30,27 @@ def test_labeling_parameter_overrides(consensus_project, initial_dataset,
4530
data = [(data_rows[2], "a_string", 3)]
4631
project.set_labeling_parameter_overrides(data)
4732
assert str(exc_info.value) == \
48-
f"Priority must be an int. Found <class 'str'> for data_row {data_rows[2]}. Index: 0"
33+
f"Priority must be an int. Found <class 'str'> for data_row {data_rows[2]}. Index: 0"
4934

5035
with pytest.raises(TypeError) as exc_info:
5136
data = [(data_rows[2].uid, 1)]
5237
project.set_labeling_parameter_overrides(data)
5338
assert str(exc_info.value) == \
54-
"data_row should be be of type DataRow. Found <class 'str'>. Index: 0"
39+
"data_row should be be of type DataRow. Found <class 'str'>. Index: 0"
40+
41+
42+
def test_set_labeling_priority(consensus_project_with_batch):
43+
[project, _, data_rows] = consensus_project_with_batch
44+
45+
init_labeling_parameter_overrides = list(
46+
project.labeling_parameter_overrides())
47+
assert len(init_labeling_parameter_overrides) == 3
48+
assert {o.priority for o in init_labeling_parameter_overrides} == {5, 5, 5}
49+
50+
data = [data_row.uid for data_row in data_rows]
51+
success = project.update_data_row_labeling_priority(data, 1)
52+
assert success
53+
54+
updated_overrides = list(project.labeling_parameter_overrides())
55+
assert len(updated_overrides) == 3
56+
assert {o.priority for o in updated_overrides} == {1, 1, 1}

0 commit comments

Comments
 (0)